How to use the mako.lookup.TemplateLookup function in Mako

To help you get started, we’ve selected a few Mako examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zzzeek / mako / test / test_namespace.py View on Github external
def test_custom_tag_3(self):
        collection = lookup.TemplateLookup()
        collection.put_string(
            "base.html",
            """
            <%namespace name="foo" file="ns.html" inheritable="True"/>

            ${next.body()}
    """,
        )
        collection.put_string(
            "ns.html",
            """
            <%def name="bar()">
                this is ns.html->bar
                caller body: ${caller.body()}
            
        """,
github sqlalchemy / mako / test / test_inheritance.py View on Github external
def test_namespaces(self):
        """test that templates used via <%namespace> have access to an
        inheriting 'self', and that the full 'self' is also exported."""
        collection = lookup.TemplateLookup()

        collection.put_string(
            "base",
            """
        <%def name="a()">base_a
        <%def name="b()">base_b
        This is the base.
        ${next.body()}
""",
        )

        collection.put_string(
            "layout",
            """
        <%inherit file="base"/>
        <%def name="a()">layout_a
github zzzeek / mako / test / test_inheritance.py View on Github external
def test_pageargs_err(self):
        collection = lookup.TemplateLookup()
        collection.put_string(
            "base",
            """
            this is the base.
            ${next.body()}
        """,
        )
        collection.put_string(
            "index",
            """
            <%inherit file="base"/>
            <%page args="x, y, z=7"/>
            print ${x}, ${y}, ${z}
        """,
        )
        try:
github sqlalchemy / mako / test / test_namespace.py View on Github external
def test_overload(self):
        collection = lookup.TemplateLookup()

        collection.put_string(
            "main.html",
            """
        <%namespace name="comp" file="defs.html">
            <%def name="def1(x, y)">
                overridden def1 ${x}, ${y}
            
        

        this is main.  ${comp.def1("hi", "there")}
        ${comp.def2("there")}
    """,
        )

        collection.put_string(
github TurboGears / tg2 / tg / configuration.py View on Github external
# provide us the required config...
                compiled_dir = self.paths['templates'][0]

            # If no dotted names support was required we will just setup
            # a file system based template lookup mechanism.
            compiled_dir = tg.config.get('templating.mako.compiled_templates_dir', None)

            if not compiled_dir:
                # no specific compile dir give by conf... we expect that
                # the server will have access to the first template dir
                # to write the compiled version...
                # If this is not the case we are doomed and the user should
                # provide us the required config...
                compiled_dir = self.paths['templates'][0]

            config['pylons.app_globals'].mako_lookup = TemplateLookup(
                directories=self.paths['templates'],
                module_directory=compiled_dir,
                input_encoding='utf-8', output_encoding='utf-8',
                imports=['from webhelpers.html import escape'],
                default_filters=['escape'],
                filesystem_checks=self.auto_reload_templates)

        self.render_functions.mako = render_mako
github spirali / nedoc / nedoc / render.py View on Github external
def __init__(self, gctx):
        self.gctx = gctx
        paths = [os.path.join(os.path.dirname(__file__), "templates")]
        lookup = mako.lookup.TemplateLookup(
            paths,
            default_filters=['html_escape'],
            imports=['from mako.filters import html_escape'])
        self.templates = {}
        self.templates[Module] = lookup.get_template("module.mako")
        self.templates[Function] = lookup.get_template("function.mako")
        self.templates[Class] = lookup.get_template("class.mako")
        self.templates["source"] = lookup.get_template("source.mako")
github WhiteMagic / JoystickGremlin / gremlin / code_generator.py View on Github external
def generate_from_profile(self, config_profile):
        """Generates the code for the given configuration.

        :param config_profile the profile for which to generate the code
        """
        assert (isinstance(config_profile, gremlin.profile.Profile))

        # Create output by rendering it via the template system
        tpl_lookup = TemplateLookup(directories=["."])
        tpl = Template(
            filename="templates/gremlin_code.tpl",
            lookup=tpl_lookup
        )
        module_imports = self._process_module_imports(config_profile.imports)
        self.code = tpl.render(
            gremlin=gremlin,
            module_imports=module_imports,
        )
github dhellmann / smiley / smiley / report / html.py View on Github external
def __init__(self, run_id, output_dir, database, title, per_page):
        self.run_id = run_id
        self.output_dir = output_dir
        self.db = database
        self.title = title
        self.per_page = per_page

        self.run_details = self.db.get_run(self.run_id)
        self.line_cache = db_linecache.DBLineCache(self.db, self.run_id)
        self.report_dir = os.path.dirname(__file__)
        self.template_dir = os.path.join(self.report_dir, 'templates')
        self.template_lookup = TemplateLookup(directories=[self.template_dir])
        self.syntax_line_cache = syntax.StyledLineCache(self.db, self.run_id)
github maartendamen / HouseAgent / houseagent / core / web_pages.py View on Github external
    @inlineCallbacks
    def plugin_result(self, result):
        lookup = TemplateLookup(directories=[houseagent.template_dir])
        template = lookup.get_template('plugin_edit.html')
        
        locations = yield db.query_locations()
        
        print locations
        print result
        
        self.request.write( str( template.render(plugin=result, locations=locations ) ) ) 
        self.request.finish()
github powdahound / ec2instances.info / render.py View on Github external
def render(data_file, template_file, destination_file):
    """Build the HTML content from scraped data"""
    lookup = mako.lookup.TemplateLookup(directories=['.'])
    template = mako.template.Template(filename=template_file, lookup=lookup)
    print("Loading data from %s..." % data_file)
    with open(data_file) as f:
        instances = json.load(f)
    for i in instances:
        add_render_info(i)
    pricing_json = compress_pricing(instances)
    print("Rendering to %s..." % destination_file)
    generated_at = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')
    with io.open(destination_file, 'w', encoding="utf-8") as fh:
        try:
            fh.write(template.render(instances=instances, pricing_json=pricing_json, generated_at=generated_at))
        except:
            print(mako.exceptions.text_error_template().render())