Edgewall Software

Changes between Version 1 and Version 2 of GenshiRecipes/SconsXIncludeScanner


Ignore:
Timestamp:
Sep 12, 2006 12:31:00 PM (9 years ago)
Author:
cmlenz
Comment:

s/Markup/Genshi, some cleanup

Legend:

Unmodified
Added
Removed
Modified
  • GenshiRecipes/SconsXIncludeScanner

    v1 v2  
     1= [GenshiRecipes Genshi Recipes]: XInclude scanner for SCons =
     2
     3== Motivation ==
     4
     5You need to integrate Genshi sources into an [http://www.scons.org/ SCons] based build system and you would like implicit dependencies for `xi:include` directives.
     6
     7== Code ==
     8
    19{{{
    2 #!rst
     10#!python
     11import sys
     12from genshi.filters import IncludeFilter
     13from genshi.template import Template,TemplateLoader
    314
    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.
     15def genshi_xinclude_scan(node, env, path, arg):
     16    t = Template(node.get_contents())
     17    loader = TemplateLoader('.'.split())
     18    t.filters.insert(0, IncludeFilter(loader))
     19    t.generate().render()
     20    return loader._cache.keys()
    521
    6 file SConscript::
     22markup_scanner = Scanner(
     23    name='genshi',
     24    function=genshi_xinclude_scan,
     25    argument=None,
     26    skeys = '.xhtml .html .xml'.split())
     27scanners = Environment().Dictionary('SCANNERS')
     28env = Environment(SCANNERS = scanners + [genshi_scanner])
    729
    8     import sys
    9     from markup.filters import IncludeFilter
    10     from markup.template import Template,TemplateLoader
     30env.Command('page-out', 'page.html', './render $SOURCES $TARGET')
     31}}}
    1132
    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()
     33So, 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.
    1834
    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])
     35`render` is a trivial wrapper script that renders the final output using Genshi for a single source file. Mine looks like this::
    2636
    27     env.Command('page-out', 'page.html', './render $SOURCES $TARGET')
     37{{{
     38#!python
     39#!/usr/bin/python
     40import sys
     41try:
     42    import wingdbstub
     43except ImportError:
     44    pass
     45from genshi.filters import IncludeFilter
     46from genshi.template import Template, TemplateLoader
    2847
    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()
     48t = Template(file(sys.argv[1]).read())
     49t.filters.insert(0, IncludeFilter(TemplateLoader('.'.split())))
     50outf = sys.stdout
     51if len(sys.argv) > 2:
     52    outf = file(sys.argv[2], 'w')
     53print >> outf, t.generate()
     54}}}
    4555
    4656There may be slicker ways of doing this. If you know them then please update this recipe.
    4757
    48 
    49 }}}
     58----
     59See also: GenshiRecipes, GenshiRecipes/RecursiveIncludeScanner