Issues

Issue #14 resolved

Make module_directory argument accept string template

Anonymous created an issue

Make module_directory argument accept string template, so you can construct a template lookup like this:

from mako.lookup import TemplateLookup lookup = TemplateLookup(directories=['dir1', 'dir2'], module_directory='${directory}')

to generate module files in the same directory as the corresponding template file.

Comments (1)

  1. Mike Bayer repo owner

    Ok heres how I did it. the goals were:

    • no arguments to Template or TemplateLookup that werent completely generic, sensical, and as flexible as possible
    • no speed hits, meaning no path calculations that arent normally used

    So to achieve the effect you want, youd do this:

    def getmodulename(filename, uri): return filename + ".py"

    lookup = TemplateLookup(directories=[a,b,c], modulename_callable=getmodulename) t = lookup.get_template('/foo/bar/index.html') ...

    the `modulename_callable` argument lets you send a callable which takes `(filename, uri)` as arguments, and you return the full filename of the module filename youd like generated. that grants maximum flexibility. for a Template by itself, you can send the "module_filename" argument which is just a string (it makes no sense for the Template to take a callable when the exact filename of the template is known).

  2. Log in to comment