def f_sect2(tree): temp = '''$def with (id, type, title, subtitle, content, prev, next) <div id="$id" class="$type"><div class="title">$title <div class="subtitle">$subtitle</div> </div> $:content </div> <div id="footer"> <input id="prev" type="hidden" value="$prev"/> <input id="next" type="hidden" value="$next"/> </div> ''' content = "" for c in tree.children: content += disp(c) sect2s = [c for c in tree.sibling() if c.type == 'sect2'] order = sect2s.index(tree) prev = order - 1 next = order + 1 if prev > -1: prev = sect2s[prev] if type(prev) is type(tree): prev = f_filename(prev) else: prev = f_filename(tree.parent) if next < len(sect2s): next = sect2s[next] if type(next) is type(tree): next = f_filename(next) else: next = f_filename(tree) subtitle = '%s/%s' % (order + 1, len(sect2s)) temp = Template(temp) content = str( temp(f_address(tree), tree.type, f_title(tree), subtitle, content, prev, next)) dir = path.dirname(f_path(tree)) if not path.exists(dir): os.mkdirs(dir) with open(f_path(tree), 'w') as f: f.write(str(render.slide(f_title(tree), content))) logger.info('render %s' % f_path(tree))
def f_sect2(tree): temp = '''$def with (id, type, title, subtitle, content, prev, next) <div id="$id" class="$type"><div class="title">$title <div class="subtitle">$subtitle</div> </div> $:content </div> <div id="footer"> <input id="prev" type="hidden" value="$prev"/> <input id="next" type="hidden" value="$next"/> </div> ''' content ="" for c in tree.children: content += disp(c) sect2s = [c for c in tree.sibling() if c.type == 'sect2'] order = sect2s.index(tree) prev = order-1 next = order+1 if prev > -1: prev = sect2s[prev] if type(prev) is type(tree): prev = f_filename(prev) else: prev = f_filename(tree.parent) if next < len(sect2s): next = sect2s[next] if type(next) is type(tree): next = f_filename(next) else: next = f_filename(tree) subtitle = '%s/%s' % (order + 1, len(sect2s)) temp = Template(temp) content = str(temp(f_address(tree), tree.type, f_title(tree), subtitle, content, prev, next)) dir = path.dirname(f_path(tree)) if not path.exists(dir): os.mkdirs(dir) with open(f_path(tree), 'w') as f: f.write(str(render.slide(f_title(tree), content))) logger.info('render %s' % f_path(tree))
def f_path(tree): 'The file path for specified node' bf = path.basename(tree.root().file) dir = path.splitext(bf)[0] return path.join("slides", dir, f_filename(tree))