def test_render_file(self): filepath = scriptdir + '/correct_drydoc.txt' dry_text = drydoc.read_file(filepath, encoding='utf-8') rendered = example_render_func(dry_text) self.assertEqual(rendered, correct_rendered, 'correct_drydoc.txt was rendered incorrectly')
def template_include(path, render=True, info=None): """Returns document in path. path is relative to the document where include is called. By default, document is rendered as DRY doc. """ docdir = info['docdir'] filepath = os.path.abspath(os.path.join(docdir, path)) contents = drydoc.read_file(filepath) if not render: return contents doc = drydoc.DryDoc(contents) # Copy info dictionary to prevent next templates to change # data in it. Each document gets their own info dictionary. newinfo = info.copy() # Update document's location to next template newdir = os.path.split(filepath)[0] newinfo['docdir'] = newdir # Create new template functions and pass newinfo which contains the # new docdir to them newfuncs = {} for name, func in info['template_funcs'].items(): funcname = getattr(func, '__name__', None) # Assign newinfo to all template functions if funcname is not None and func.__name__.startswith(func_prefix): newfunc = assign_kwargs(func, info=newinfo) newfunc.__name__ = func.__name__ newname = func.__name__[len(func_prefix):] newfuncs[newname] = newfunc else: newfuncs[name] = func newinfo['template_funcs'] = newfuncs env = newinfo['template_env'] env.update(newfuncs) return doc.render(env=env)
def template_filevars(path, info=None): docdir = info['docdir'] filepath = os.path.abspath(os.path.join(docdir, path)) contents = drydoc.read_file(filepath, encoding=info['encoding']) doc = drydoc.DryDoc(contents) return doc.get_variables()