def __call__(self, entryfn='body', context={}): from eazytext.compiler import Compiler self.compiler = Compiler(etxtext=self.etxtext, etxloc=self.etxloc, etxconfig=self.etxconfig, etparser=self.etparser) context['_etxcontext'] = context module = self.compiler.execetx(context=context) entry = getattr(module, entryfn) html = entry() if callable(entry) else '' return html
class Translate(object): def __init__(self, etxloc=None, etxtext=None, etxconfig={}): """`etxconfig` parameter will find its way into every object defined by wiki processor. TODO : somehow find a way to pass the arguments to `body` function """ self.etxconfig = dict(defaultconfig.items()) self.etxconfig.update(etxconfig) self.etxconfig.setdefault('devmod', DEVMOD) # Initialize plugins self.etxconfig = initplugins(self.etxconfig, force=self.etxconfig['devmod']) self.etxloc, self.etxtext = etxloc, etxtext self.etparser = ETParser(etxconfig=self.etxconfig) def __call__(self, entryfn='body', context={}): from eazytext.compiler import Compiler self.compiler = Compiler(etxtext=self.etxtext, etxloc=self.etxloc, etxconfig=self.etxconfig, etparser=self.etparser) context['_etxcontext'] = context module = self.compiler.execetx(context=context) entry = getattr(module, entryfn) html = entry() if callable(entry) else '' return html
def etx_cmdline(etxloc, **kwargs): from eazytext.compiler import Compiler htmlfile = kwargs.get('ofile', '') etxconfig = dict(defaultconfig.items()) # directories, module_directory, devmod etxconfig.update(kwargs) etxconfig['module_directory'] = u'.' etxconfig['include_skin'] = True etxconfig['ashtml'] = True # Parse command line arguments and configuration context = eval(etxconfig.pop('context', '{}')) debuglevel = etxconfig.pop('debuglevel', 0) show = etxconfig.pop('show', False) dump = etxconfig.pop('dump', False) encoding = etxconfig['input_encoding'] # Initialize plugins) etxconfig.setdefault('devmod', DEVMOD) etxconfig = initplugins(etxconfig, force=etxconfig['devmod']) # Setup parser etparser = ETParser(etxconfig=etxconfig, debug=debuglevel) compiler = Compiler(etxloc=etxloc, etxconfig=etxconfig, etparser=etparser) pyfile = compiler.etxfile + '.py' if not htmlfile: htmlfile = basename(compiler.etxfile).rsplit('.', 1)[0] + '.html' htmlfile = join(dirname(compiler.etxfile), htmlfile) if debuglevel: print "AST tree ..." tu = compiler.toast() elif show: print "AST tree ..." tu = compiler.toast() tu.show() elif dump: from eazytext.ast import Context tu = compiler.toast() rctext = tu.dump(Context()) text = codecs.open(compiler.etxfile, encoding=encoding).read() if rctext[:-1] != text: print "Mismatch ..." sys.exit(1) else: print "Success ..." else: print "Generating py / html file ... " pytext = compiler.topy(etxhash=compiler.etxlookup.etxhash) # Intermediate file should always be encoded in 'utf-8' codecs.open(pyfile, mode='w', encoding=DEFAULT_ENCODING).write(pytext) t = Translate(etxloc=etxloc, etxconfig=etxconfig) html = t(context=deepcopy(context)) codecs.open(htmlfile, mode='w', encoding=encoding).write(html) # This is for measuring performance st = dt.now() [ Translate(etxloc=etxloc, etxconfig=etxconfig)(context=deepcopy(context)) for i in range(2) ]