Re: making flavours easier
Russell Nelson <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
will guaraldi writes:
> You could use my pyinclude plugin. That allows you to include files into
> a template.
>
> http://pyblosxom.sourceforge.net/blog/registry/include/pyinclude
Well done! May I offer this enhancement? Works a champ with a
blogroll that looks like this:
http://blog.russnelson.com Russell Nelson
http://angry-economist.russnelson.com The Angry Economist
and an inclusion that looks like this:
$util::include("blogroll.data",'<li><a href="%s">%s</a>\n')
--- plugins/pyinclude.py Wed Mar 9 15:01:24 2005
+++ plugins/pyimport.py Mon Mar 14 10:39:35 2005
@@ -90,7 +75,7 @@
def verify_installation(request):
return 1
-def include(req, filename):
+def include(req, filename, template=None):
"""
This takes in one argument--a filename. It opens the file, reads
in the contents, and returns them as the value of this variable.
@@ -108,7 +93,12 @@
try:
f = open(filename, "r")
- lines = "".join(f.readlines())
+ if template:
+ lines = ""
+ for line in f:
+ lines += template % tuple(line.rstrip().split('\t'))
+ else:
+ lines = "".join(f.readlines())
f.close()
return eval_python_blocks(req, lines)
except:
--
--My blog is at blog.russnelson.com | The laws of physics cannot
Crynwr sells support for free software | PGPok | be legislated. Neither can
521 Pleasant Valley Rd. | +1 315-323-1241 cell | the laws of countries.
Potsdam, NY 13676-3213 | +1 212-202-2318 VOIP |
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click