Skip to content

Commit d128a8b

Browse files
committedJun 3, 2008
- added a runner script "mako-render" which renders
standard input as a template to stdout [ticket:81] [ticket:56]
1 parent 4a63492 commit d128a8b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
 

‎CHANGES

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
_push_buffer(), _pop_buffer(),
4848
caller_stack._push_frame(), caller_stack._pop_frame().
4949

50+
- added a runner script "mako-render" which renders
51+
standard input as a template to stdout [ticket:81]
52+
[ticket:56]
53+
5054
- Bugfixes:
5155
- can now use most names from __builtins__ as variable
5256
names without explicit declaration (i.e. 'id',

‎scripts/mako-render

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
3+
def render(data):
4+
from mako.template import Template
5+
from mako.lookup import TemplateLookup
6+
7+
lookup = TemplateLookup(["."])
8+
return Template(data, lookup=lookup).render()
9+
10+
def main(argv=None):
11+
from os.path import isfile
12+
from sys import stdin
13+
14+
if argv is None:
15+
import sys
16+
argv = sys.argv
17+
18+
from optparse import OptionParser
19+
20+
parser = OptionParser("usage: %prog [FILENAME]")
21+
22+
opts, args = parser.parse_args(argv[1:])
23+
if len(args) not in (0, 1):
24+
parser.error("wrong number of arguments") # Will exit
25+
26+
if (len(args) == 0) or (args[0] == "-"):
27+
fo = stdin
28+
else:
29+
filename = args[0]
30+
if not isfile(filename):
31+
raise SystemExit("error: can't find %s" % filename)
32+
fo = open(filename)
33+
34+
data = fo.read()
35+
print render(data)
36+
37+
if __name__ == "__main__":
38+
main()

‎setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
license='MIT',
3535
package_dir={'':'lib'},
3636
packages=find_packages('lib', exclude=['ez_setup', 'examples', 'tests']),
37+
scripts=['scripts/mako-render'],
3738
zip_safe=False,
3839
install_requires=[
3940
'Beaker',

0 commit comments

Comments
 (0)