scripts/mako-render
a b 1 1 #!/usr/bin/env python 2 2 3 def render(data, kw):3 def render(data, filename, kw): 4 4 from mako.template import Template 5 5 from mako.lookup import TemplateLookup 6 6 7 7 lookup = TemplateLookup(["."]) 8 return Template(data, lookup=lookup).render(**kw)8 return Template(data, filename=filename, lookup=lookup).render(**kw) 9 9 10 10 def varsplit(var): 11 11 if "=" not in var: … … 40 40 41 41 kw = dict([varsplit(var) for var in opts.var]) 42 42 data = fo.read() 43 print render(data, kw)43 print render(data, filename, kw) 44 44 45 45 if __name__ == "__main__": 46 46 main()
test:
base.mako sub/base.mako -> <%inherit file="/base.mako"/> sub/index.mako -> <%inherit file="base.mako"/>