summaryrefslogtreecommitdiff
path: root/scripts/news.py
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2011-10-08 16:21:04 +0200
committerChristian Franke <nobody@nowhere.ws>2011-10-08 17:44:40 +0200
commit1dc0670c01211a1d1e8b99facea1710949ee506d (patch)
treef373c744fcc4a27a62070d757887589db5f7739e /scripts/news.py
parentf43a8028cdf482d72efe82fdf101915df049fdc3 (diff)
Add plugin api to template.py, add news plugin
Diffstat (limited to 'scripts/news.py')
-rw-r--r--scripts/news.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/news.py b/scripts/news.py
new file mode 100644
index 0000000..ca9dfb4
--- /dev/null
+++ b/scripts/news.py
@@ -0,0 +1,25 @@
+import template
+import plugin
+import string
+import os
+
+class NewsPlugin:
+ def __init__(self):
+ newspath = os.path.join(template.path, 'news')
+ newsfiles = [ os.path.join(newspath, entry) for entry in sorted(os.listdir(newspath)) ]
+
+ self._news = []
+ for newsfile in reversed(newsfiles):
+ self._news.append(open(newsfile, 'r').read())
+
+ def process_content(self, page_content):
+ return_value = {}
+ for filename, content in page_content.iteritems():
+ template = string.Template(content)
+ return_value[filename] = template.safe_substitute(
+ news = ''.join(self._news),
+ latest_news = ''.join(self._news[:3]),
+ )
+ return return_value
+
+plugin.plugin_manager.register(NewsPlugin())