diff options
author | Richard Darst <rkd@zgib.net> | 2009-09-22 18:30:39 (GMT) |
---|---|---|
committer | Richard Darst <rkd@zgib.net> | 2009-09-22 18:30:39 (GMT) |
commit | 96f41658e31a7db326daf197be9c3ec89f191140 (patch) | |
tree | 177ce35c0783596cf31adcfe895f9816a9a07ed2 /items.py | |
parent | 7c36b6b89e1adec1f1c38fd312c88e5c220abc7c (diff) |
Add templaning necessary for the soon-to-be genshi templating
- This adds .get_template method on the _BaseWriter which gives a big
data structure object that can be used with genshi templates to
write custom HTML.
- Template writer added - place to add the new writer code.
- For information on how this works, search for these two names in
the code and read the comments in them.
darcs-hash:20090922183039-82ea9-c403d1e748e13ee79afc8dbdf7f8ee286000797a.gz
Diffstat (limited to 'items.py')
-rw-r--r-- | items.py | 40 |
1 files changed, 27 insertions, 13 deletions
@@ -66,17 +66,31 @@ class _BaseItem(object): endtext = '' startmw = '' endmw = '' - def get_replacements(self, escapewith): + def get_replacements(self, M, escapewith): replacements = { } for name in dir(self): if name[0] == "_": continue replacements[name] = getattr(self, name) replacements['nick'] = escapewith(replacements['nick']) + replacements['link'] = self.logURL(M) if 'line' in replacements: replacements['line'] = escapewith(replacements['line']) if 'topic' in replacements: replacements['topic'] = escapewith(replacements['topic']) + if 'url' in replacements: + replacements['url_quoteescaped'] = \ + escapewith(self.url.replace('"', "%22")) + return replacements + def template(self, M, escapewith): + template = { } + for k,v in self.get_replacements(M, escapewith).iteritems(): + if k not in ('itemtype', 'line', 'topic', + 'url', 'url_quoteescaped', + 'nick', 'time', 'link', 'anchor'): + continue + template[k] = v + return template def makeRSTref(self, M): if self.nick[-1] == '_': rstref = rstref_orig = "%s%s"%(self.nick, self.time) @@ -121,7 +135,7 @@ class Topic(_BaseItem): self.nick = nick ; self.topic = line ; self.linenum = linenum self.time = time.strftime("%H:%M:%S", time_) def _htmlrepl(self, M): - repl = self.get_replacements(escapewith=writers.html) + repl = self.get_replacements(M, escapewith=writers.html) repl['link'] = self.logURL(M) return repl def html(self, M): @@ -130,16 +144,16 @@ class Topic(_BaseItem): return self.html2_template%self._htmlrepl(M) def rst(self, M): self.rstref = self.makeRSTref(M) - repl = self.get_replacements(escapewith=writers.rst) + repl = self.get_replacements(M, escapewith=writers.rst) if repl['topic']=='': repl['topic']=' ' repl['link'] = self.logURL(M) return self.rst_template%repl def text(self, M): - repl = self.get_replacements(escapewith=writers.text) + repl = self.get_replacements(M, escapewith=writers.text) repl['link'] = self.logURL(M) return self.text_template%repl def mw(self, M): - repl = self.get_replacements(escapewith=writers.mw) + repl = self.get_replacements(M, escapewith=writers.mw) return self.mw_template%repl class GenericItem(_BaseItem): @@ -163,7 +177,7 @@ class GenericItem(_BaseItem): self.nick = nick ; self.line = line ; self.linenum = linenum self.time = time.strftime("%H:%M:%S", time_) def _htmlrepl(self, M): - repl = self.get_replacements(escapewith=writers.html) + repl = self.get_replacements(M, escapewith=writers.html) repl['link'] = self.logURL(M) return repl def html(self, M): @@ -172,15 +186,15 @@ class GenericItem(_BaseItem): return self.html2_template%self._htmlrepl(M) def rst(self, M): self.rstref = self.makeRSTref(M) - repl = self.get_replacements(escapewith=writers.rst) + repl = self.get_replacements(M, escapewith=writers.rst) repl['link'] = self.logURL(M) return self.rst_template%repl def text(self, M): - repl = self.get_replacements(escapewith=writers.text) + repl = self.get_replacements(M, escapewith=writers.text) repl['link'] = self.logURL(M) return self.text_template%repl def mw(self, M): - repl = self.get_replacements(escapewith=writers.mw) + repl = self.get_replacements(M, escapewith=writers.mw) return self.mw_template%repl @@ -237,7 +251,7 @@ class Link(_BaseItem): self.url = self.url self.line = self.line.strip() def _htmlrepl(self, M): - repl = self.get_replacements(escapewith=writers.html) + repl = self.get_replacements(M, escapewith=writers.html) # special: replace doublequote only for the URL. repl['url'] = writers.html(self.url.replace('"', "%22")) repl['url_readable'] = writers.html(self.url) @@ -249,14 +263,14 @@ class Link(_BaseItem): return self.html2_template%self._htmlrepl(M) def rst(self, M): self.rstref = self.makeRSTref(M) - repl = self.get_replacements(escapewith=writers.rst) + repl = self.get_replacements(M, escapewith=writers.rst) repl['link'] = self.logURL(M) #repl['url'] = writers.rst(self.url) return self.rst_template%repl def text(self, M): - repl = self.get_replacements(escapewith=writers.text) + repl = self.get_replacements(M, escapewith=writers.text) repl['link'] = self.logURL(M) return self.text_template%repl def mw(self, M): - repl = self.get_replacements(escapewith=writers.mw) + repl = self.get_replacements(M, escapewith=writers.mw) return self.mw_template%repl |