Skip to content
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
Closed

Make module_directory argument accept string template #14

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

Comments

@sqlalchemy-bot
Copy link

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

@sqlalchemy-bot
Copy link
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
Projects
None yet
Development

No branches or pull requests

1 participant