| | 1 | {{{ |
| | 2 | #!rst |
| | 3 | |
| | 4 | **why would you want this recipe ?** You need to integrate markup sources into a `scons <http://www.scons.org/>`_ based build system and you would like implicit dependencies for ``xi:include`` directives. |
| | 5 | |
| | 6 | file SConscript:: |
| | 7 | |
| | 8 | import sys |
| | 9 | from markup.filters import IncludeFilter |
| | 10 | from markup.template import Template,TemplateLoader |
| | 11 | |
| | 12 | def markup_xinclude_scan(node, env, path, arg): |
| | 13 | t=Template(node.get_contents()) |
| | 14 | loader=TemplateLoader('.'.split()) |
| | 15 | t.filters.insert(0, IncludeFilter(loader)) |
| | 16 | t.generate().render() |
| | 17 | return loader._cache.keys() |
| | 18 | |
| | 19 | markup_scanner = Scanner( |
| | 20 | name='markup', |
| | 21 | function=markup_xinclude_scan, |
| | 22 | argument=None, |
| | 23 | skeys = '.xhtml .html .xml'.split()) |
| | 24 | scanners = Environment().Dictionary('SCANNERS') |
| | 25 | env = Environment(SCANNERS = scanners + [markup_scanner]) |
| | 26 | |
| | 27 | env.Command('page-out', 'page.html', './render $SOURCES $TARGET') |
| | 28 | |
| | 29 | So, assuming page.html references another file, say ``base.html``, using the Xinclude recipe, any edit to base.html will cause scons to consider ``page-out`` to be out of date. After an edit of either page.html or base.html ``scons -f SConscript`` will be sufficient to bring ``page-out`` up to date. |
| | 30 | |
| | 31 | render is a trivial wrapper script that renders the final output using markup for a single source file. Mine looks like this:: |
| | 32 | |
| | 33 | #!/usr/bin/python |
| | 34 | import sys |
| | 35 | try: import wingdbstub |
| | 36 | except ImportError: pass |
| | 37 | from markup.filters import IncludeFilter |
| | 38 | from markup.template import Template,TemplateLoader |
| | 39 | t=Template(file(sys.argv[1]).read()) |
| | 40 | t.filters.insert(0, IncludeFilter(TemplateLoader('.'.split()))) |
| | 41 | outf = sys.stdout |
| | 42 | if len(sys.argv) > 2: |
| | 43 | outf=file(sys.argv[2], 'w') |
| | 44 | print >> outf, t.generate().render() |
| | 45 | |
| | 46 | There may be slicker ways of doing this. If you know them then please update this recipe. |
| | 47 | |
| | 48 | |
| | 49 | }}} |