Skip to content

Make module_directory argument accept string template #14

Closed

Description

@sqlalchemy-bot

Migrated issue, originally created by Anonymous

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.


Attachments: module_directory.patch

Activity

  1. sqlalchemy-bot commented on Jan 21, 2007

    @sqlalchemy-bot
    Author

    Michael Bayer (@zzzeek) wrote:

    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. sqlalchemy-bot commented on Jan 21, 2007

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions