New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make module_directory argument accept string template #14

Closed
sqlalchemy-bot opened this Issue Jan 20, 2007 · 2 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Jan 20, 2007

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

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 21, 2007

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).

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 21, 2007

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