def post_setup(self, path=None, name=None): # Post setup hook if path: self.path = path else: self.path = os.path.dirname(inspect.getfile(self.__class__)) if name: self.name = name else: self.name = "%s %s " % (self.default_workspace_category, "Plugin") self.name = name # Plugin personal template engine self.templateEngine = Engine( loader=FileLoader([self.path, os.path.join(utils.scriptdir, 'html')]), extensions=[CoreExtension(), CodeExtension()] ) help_path = os.path.join(self.path, 'readme.html') if os.path.exists(help_path): self.help_tab_html_filename = 'readme.html' else: self.help_tab_html_filename = None
def setUp(self): from wheezy.template.engine import Engine from wheezy.template.ext.code import CodeExtension from wheezy.template.ext.core import CoreExtension from wheezy.template.loader import DictLoader self.templates = {} self.engine = Engine(loader=DictLoader(templates=self.templates), extensions=[CoreExtension(), CodeExtension()])
def parse_toplevel_config(self, config): super().parse_toplevel_config(config) if GIFormatter.engine is None: module_path = os.path.dirname(__file__) searchpath = [os.path.join(module_path, "html_templates")] + Formatter.engine.loader.searchpath GIFormatter.engine = Engine( loader=FileLoader(searchpath, encoding='UTF-8'), extensions=[CoreExtension(), CodeExtension()]) GIFormatter.engine.global_vars.update({'e': html.escape})
def content(self, source, filename): engine = Engine( loader=Loader(source), extensions=[ CoreExtension(token_start='\\$'), CodeExtension(token_start='\\$'), ]) engine.global_vars.update({'warn': warn}) return engine.get_template(filename).render({})
def generate_source(argsstring, options, version, enums, functions_by_category, passthru, extensions, types, raw_enums): template_pattern = re.compile("(.*).template") # Sort by categories and sort the functions inside the categories functions_by_category = sorted(functions_by_category, key=lambda x: x[0]) functions_by_category = list( map(lambda c: (c[0], sorted(c[1], key=lambda x: x.name)), functions_by_category)) template_namespace = { 'passthru': passthru, 'functions': functions_by_category, 'enums': enums, 'options': options, 'version': version, 'extensions': extensions, 'types': types, 'raw_enums': raw_enums, 'args': argsstring } if not os.path.isdir(options.template_dir): print('%s is not a directory' % options.template_dir) exit(1) if os.path.exists(options.outdir) and not os.path.isdir(options.outdir): print('%s is not a directory' % options.outdir) exit(1) if not os.path.exists(options.outdir): os.mkdir(options.outdir) engine = Engine(loader=FileLoader([options.template_dir]), extensions=[CoreExtension(), CodeExtension()]) generatedFiles = 0 allFiles = 0 for template_path in glob('%s/*.template' % os.path.abspath(options.template_dir)): infile = os.path.basename(template_path) outfile = '%s/%s' % (options.outdir, template_pattern.match(infile).group(1)) template = engine.get_template(infile) allFiles += 1 with open(outfile, 'w') as out: out.write(template.render(template_namespace)) print("Successfully generated %s" % outfile) generatedFiles += 1 print("Generated %d of %d files" % (generatedFiles, allFiles))
def main(argv: typing.Optional[typing.List[str]] = None) -> int: args = parse_args(argv or sys.argv[1:]) if not args: return 2 ts = args.token_start extensions = [CoreExtension(ts), CodeExtension(ts)] extensions.extend(args.extensions) engine = Engine(FileLoader(args.searchpath), extensions) engine.global_vars.update({"h": escape}) t = engine.get_template(args.template) sys.stdout.write(t.render(load_context(args.context))) return 0
def parse_toplevel_config(self, config): super().parse_toplevel_config(config) if GstFormatter.engine is None: gi_extension_path = gi.__path__[0] searchpath = [ os.path.join(gi_extension_path, "html_templates"), self.__tmpdir.name ] + Formatter.engine.loader.searchpath GstFormatter.engine = Engine( loader=FileLoader(searchpath, encoding='UTF-8'), extensions=[CoreExtension(), CodeExtension()]) GstFormatter.engine.global_vars.update({'e': html.escape})
def __init__(self, path): self.path = path template_dct = { 'docker': templates.docker, } engine = Engine(loader=DictLoader(template_dct), extensions=[CoreExtension(), CodeExtension()]) self.templates = { name: engine.get_template(name) for name in template_dct }
def main(args=None): if not json: # pragma: nocover print('error: json module is not available') return 1 args = parse_args(args or sys.argv[1:]) if not args: return 2 ts = args.token_start extensions = [CoreExtension(ts), CodeExtension(ts)] extensions.extend(args.extensions) engine = Engine(FileLoader(args.searchpath), extensions) engine.global_vars.update({'h': escape}) t = engine.get_template(args.template) sys.stdout.write(t.render(load_context(args.context))) return 0
def parse_toplevel_config(self, config): """Parse @config to setup @self state.""" if not Formatter.initialized: html_theme = config.get('html_theme', 'default') if html_theme != 'default': uri = urllib.parse.urlparse(html_theme) if not uri.scheme: html_theme = config.get_path('html_theme') debug("Using theme located at %s" % html_theme) elif uri.scheme.startswith('http'): html_theme = self.__download_theme(uri) if html_theme == 'default': default_theme = os.path.join(HERE, os.pardir, 'hotdoc_bootstrap_theme', 'dist') html_theme = os.path.abspath(default_theme) debug("Using default theme") theme_meta_path = os.path.join(html_theme, 'theme.json') if os.path.exists(theme_meta_path): with open(theme_meta_path, 'r') as _: Formatter.theme_meta = json.loads(_.read()) searchpath = [] self.__load_theme_templates(searchpath, HERE) Formatter.theme_path = html_theme if html_theme: self.__load_theme_templates(searchpath, html_theme) Formatter.extra_theme_path = config.get_path('html_extra_theme') if Formatter.extra_theme_path: self.__load_theme_templates(searchpath, Formatter.extra_theme_path) Formatter.engine = Engine( loader=FileLoader(searchpath, encoding='UTF-8'), extensions=[CoreExtension(), CodeExtension()]) Formatter.engine.global_vars.update({'e': html.escape}) Formatter.initialized = True
def __init__(self, searchpath): Formatter.__init__(self) self._symbol_formatters = { FunctionSymbol: self._format_function, FunctionMacroSymbol: self._format_function_macro, CallbackSymbol: self._format_callback, ConstantSymbol: self._format_constant, ExportedVariableSymbol: self._format_constant, AliasSymbol: self._format_alias, StructSymbol: self._format_struct, EnumSymbol: self._format_enum, ParameterSymbol: self._format_parameter_symbol, ReturnItemSymbol: self._format_return_item_symbol, FieldSymbol: self._format_field_symbol, SignalSymbol: self._format_signal_symbol, VFunctionSymbol: self._format_vfunction_symbol, PropertySymbol: self._format_property_symbol, ClassSymbol: self._format_class_symbol, InterfaceSymbol: self._format_interface_symbol, } self._ordering = [InterfaceSymbol, ClassSymbol, FunctionSymbol, FunctionMacroSymbol, SignalSymbol, PropertySymbol, StructSymbol, VFunctionSymbol, EnumSymbol, ConstantSymbol, ExportedVariableSymbol, AliasSymbol, CallbackSymbol] if HtmlFormatter.theme_path: self.__load_theme_templates(searchpath, HtmlFormatter.theme_path) if HtmlFormatter.extra_theme_path: self.__load_theme_templates(searchpath, HtmlFormatter.extra_theme_path) searchpath.append(os.path.join(HERE, "html_templates")) self.engine = Engine( loader=FileLoader(searchpath, encoding='UTF-8'), extensions=[CoreExtension(), CodeExtension()] ) self.all_scripts = set() self.all_stylesheets = set() self._docstring_formatter = GtkDocStringFormatter()
def parse_config(self, config): """Banana banana """ self.add_anchors = bool(config.get("html_add_anchors")) self.number_headings = bool(config.get("html_number_headings")) if self.theme_path: self.__load_theme_templates(self.searchpath, self.theme_path) if self.extra_theme_path: self.__load_theme_templates(self.searchpath, self.extra_theme_path) self.searchpath.append(os.path.join(HERE, "templates")) self.engine = Engine(loader=FileLoader(self.searchpath, encoding='UTF-8'), extensions=[CoreExtension(), CodeExtension()]) self.engine.global_vars.update({'e': html.escape}) self._docstring_formatter.parse_config(config)
server.stop() template = """\ @require(name) Hello, @name""" engine_dict = Engine(loader=DictLoader({'x': template}), extensions=[CoreExtension()]) template_w = engine_dict.get_template('x') searchpath = ['./static/templates-wheezy'] #searchpath = ['./views'] engine = Engine(loader=FileLoader(searchpath), extensions=[CoreExtension(), CodeExtension()]) templateChild = engine.get_template('child.html') template_famille = engine.get_template('famille.html') @route("/") def working(): return "Site en maintenance" @route('/img/<filename>') def send_static(filename): return static_file(filename, root='static/img')
def setUp(self) -> None: self.engine = Engine( loader=DictLoader({}), extensions=[CodeExtension()] )
def setUp(self) -> None: self.templates: typing.Dict[str, str] = {} self.engine = Engine( loader=DictLoader(templates=self.templates), extensions=[CoreExtension(), CodeExtension()], )
class AutoRequireExtension: def __init__(self, *names): self.names = names @property def postprocessors(self): yield self.add_require def add_require(self, tokens): tokens.insert(0, (0, 'require', f"require({','.join(self.names)})")) engine = Engine( loader=FileLoader(['.']), extensions=[ CoreExtension(token_start='\\$'), CodeExtension(token_start='\\$'), AutoRequireExtension('config', 'urls', 'db', 'endpoint', 'values'), ]) with catch_warnings(record=True): engine = autoreload(engine) engine.global_vars.update( {'_r': engine.render, 'warn': warn, 'json': json}) class Page(list): def __init__(self, count, page_size, page):