From 40247c275eff08654db55357ecf41cd4bb773104 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sun, 7 Jul 2013 16:37:49 +0000 Subject: [PATCH] Refactor the template loading/showing code. There are now get_template and show_template methods that take the template name as an argument, rather than four lots of duplicated functions. get_template is a bit unwieldy, but it's better than before. --- NEWS | 2 + rawdoglib/rawdog.py | 93 +++++++++++++++++---------------------------- 2 files changed, 37 insertions(+), 58 deletions(-) diff --git a/NEWS b/NEWS index 625747f..4d7fc53 100644 --- a/NEWS +++ b/NEWS @@ -139,6 +139,8 @@ Move rawdog's feed quality heuristic into feedscanner. Provide templates for the feed list and each item in the feed list (based on patch from Arnout Engelen). +Refactor the template-loading/showing code to reduce duplication. + Rename the "template" option to "pagetemplate", for consistency. ("template" is still accepted for backwards compatibility.) diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 912cd71..53d4495 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -1374,22 +1374,25 @@ class Rawdog(Persistable): self.modified() config.log("Finished update") - def get_pagetemplate(self, config): - """Get the main template.""" - if config["pagetemplate"] != "default": - return load_file(config["pagetemplate"]) + def get_template(self, name, config): + """Return the contents of a template.""" - template = """ """ - if config["userefresh"]: - template += """__refresh__ + if config["userefresh"]: + template += """__refresh__ """ - template += """ + template += """ rawdog @@ -1400,13 +1403,13 @@ class Rawdog(Persistable): __items__ """ - if config["showfeeds"]: - template += """

Feeds

+ if config["showfeeds"]: + template += """

Feeds

__feeds__
""" - template += """