diff --git a/docs/filters.html b/docs/filters.html index 425d189..58eb6fe 100644 --- a/docs/filters.html +++ b/docs/filters.html @@ -77,8 +77,18 @@ python. .xslt involkes XSLT. .sed and perl or ruby or class/jar (java), aren't supported at the moment, but these would be easy to add. -
  • Templates written using htmltmpl currently only have access to a fixed set -of fields, whereas XSLT templates have access to everything.
  • +
  • If the filter name contains a redirection character (>), +then the output stream is +teed; one branch flows +through the specified filter and the output is planced into the named file; the +other unmodified branch continues onto the next filter, if any. +One use case for this function is to use +xhtml2html to produce both an XHTML and +an HTML output stream from one source.
  • + +
  • Templates written using htmltmpl or django currently only have access to a +fixed set of fields, whereas XSLT and genshi templates have access to +everything.
  • diff --git a/planet/splice.py b/planet/splice.py index 26aa97d..13512b0 100644 --- a/planet/splice.py +++ b/planet/splice.py @@ -122,10 +122,22 @@ def apply(doc): output = open(output_file).read() for filter in config.filters(template_file): if filter in planet_filters: continue - output = shell.run(filter, output, mode="filter") - if not output: - os.unlink(output_file) - break + if filter.find('>')>0: + # tee'd output + filter,dest = filter.split('>',1) + tee = shell.run(filter.strip(), output, mode="filter") + if tee: + output_dir = planet.config.output_dir() + dest_file = os.path.join(output_dir, dest.strip()) + dest_file = open(dest_file,'w') + dest_file.write(tee) + dest_file.close() + else: + # pipe'd output + output = shell.run(filter, output, mode="filter") + if not output: + os.unlink(output_file) + break else: handle = open(output_file,'w') handle.write(output) diff --git a/tests/data/apply/config-html.ini b/tests/data/apply/config-html.ini new file mode 100644 index 0000000..635b552 --- /dev/null +++ b/tests/data/apply/config-html.ini @@ -0,0 +1,25 @@ +[Planet] +output_theme = genshi_fancy +output_dir = tests/work/apply +name = test planet +cache_directory = tests/work/spider/cache + +bill_of_materials: + images/#{face} + +[index.html.genshi] +filters: + xhtml2html.py>index.html4 + +[tests/data/spider/testfeed0.atom] +name = not found + +[tests/data/spider/testfeed1b.atom] +name = one +face = jdub.png + +[tests/data/spider/testfeed2.atom] +name = two + +[tests/data/spider/testfeed3.rss] +name = three diff --git a/tests/test_apply.py b/tests/test_apply.py index 6ed8186..ec5a8e5 100644 --- a/tests/test_apply.py +++ b/tests/test_apply.py @@ -55,6 +55,16 @@ class ApplyTest(unittest.TestCase): config.load(configfile % 'genshi') self.apply_fancy() + def test_apply_filter_html(self): + config.load(configfile % 'html') + self.apply_fancy() + + output = open(os.path.join(workdir, 'index.html')).read() + self.assertTrue(output.find('/>')>=0) + + output = open(os.path.join(workdir, 'index.html4')).read() + self.assertTrue(output.find('/>')<0) + def apply_fancy(self): splice.apply(self.feeddata) @@ -106,3 +116,4 @@ for method in dir(test_filter_genshi.GenshiFilterTests): if method.startswith('test_'): break else: delattr(ApplyTest,'test_apply_genshi_fancy') + delattr(ApplyTest,'test_apply_filter_html')