Permalink
Browse files

Allow filters to "tee"

  • Loading branch information...
1 parent 0f65d3e commit c7bc9702d819ae583e6413ac823c685c68b5965a @rubys committed Apr 26, 2007
Showing with 64 additions and 6 deletions.
  1. +12 −2 docs/filters.html
  2. +16 −4 planet/splice.py
  3. +25 −0 tests/data/apply/config-html.ini
  4. +11 −0 tests/test_apply.py
View
@@ -77,8 +77,18 @@
perl or ruby or class/jar (java), aren't supported at the moment, but these
would be easy to add.</li>
-<li>Templates written using htmltmpl currently only have access to a fixed set
-of fields, whereas XSLT templates have access to everything.</li>
+<li>If the filter name contains a redirection character (<code>&gt;</code>),
+then the output stream is
+<a href="http://en.wikipedia.org/wiki/Tee_(Unix)">tee</a>d; 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
+<a href="../filters/xhtml2html.py">xhtml2html</a> to produce both an XHTML and
+an HTML output stream from one source.</li>
+
+<li>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.</li>
</ul>
</body>
</html>
View
@@ -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)
@@ -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
View
@@ -55,6 +55,16 @@ def test_apply_genshi_fancy(self):
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 @@ def test_apply_filter(self):
if method.startswith('test_'): break
else:
delattr(ApplyTest,'test_apply_genshi_fancy')
+ delattr(ApplyTest,'test_apply_filter_html')

0 comments on commit c7bc970

Please sign in to comment.