Mercurial > genshi > mirror
annotate examples/transform/run.py @ 327:c72243905470 experimental-compiler
- further dev on codegen.
- had to add a few instance variables to genshi core to help in generating string-based python code; i
Expression holds onto its AST node, DefDirective holds onto the original string-based signature.
- generator code is a little messy right now, will clean up !
author | zzzeek |
---|---|
date | Sat, 04 Nov 2006 21:01:42 +0000 |
parents | 88ec2b306296 |
children |
rev | line source |
---|---|
107
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
1 #!/usr/bin/python |
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
3 |
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
4 import os |
108 | 5 import sys |
107
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
6 |
230 | 7 from genshi.input import HTMLParser |
233
88ec2b306296
* Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents:
230
diff
changeset
|
8 from genshi.template import Context, MarkupTemplate |
107
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
9 |
108 | 10 def transform(html_filename, tmpl_filename): |
11 tmpl_fileobj = open(tmpl_filename) | |
233
88ec2b306296
* Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents:
230
diff
changeset
|
12 tmpl = MarkupTemplate(tmpl_fileobj, tmpl_filename) |
108 | 13 tmpl_fileobj.close() |
14 | |
107
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
15 html_fileobj = open(html_filename) |
108 | 16 html = HTMLParser(html_fileobj, html_filename) |
17 print tmpl.generate(Context(input=html)).render('xhtml') | |
18 html_fileobj.close() | |
107
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
19 |
8b6bd2d920c1
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
20 if __name__ == '__main__': |
108 | 21 basepath = os.path.dirname(os.path.abspath(__file__)) |
22 tmpl_filename = os.path.join(basepath, 'template.xml') | |
23 html_filename = os.path.join(basepath, 'index.html') | |
24 transform(html_filename, tmpl_filename) |