From ea36770467b1f5f4507a4c09474af32d69204464 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 21 Dec 2004 23:53:06 +0000 Subject: [PATCH] Add several hooks into write(). --- PLUGINS | 56 +++++++++++++++++++++++++++++++++++++++++---- rawdoglib/rawdog.py | 10 ++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/PLUGINS b/PLUGINS index 7e9a022..2c067d1 100644 --- a/PLUGINS +++ b/PLUGINS @@ -41,13 +41,59 @@ Run just before rawdog saves the state file and exits. ### config_option(config, name, value) +* name: the option name +* value: the option value + Called when rawdog encounters a config file option that it doesn't -recognise with the given name and value. The rawdoglib.rawdog.parse_* -functions will probably be useful when dealing with config options. You -can raise ValueError to have rawdog print an appropriate error message. -You should return False from this hook if name is an option you -recognise. +recognise. The rawdoglib.rawdog.parse_* functions will probably be +useful when dealing with config options. You can raise ValueError to +have rawdog print an appropriate error message. You should return False +from this hook if name is an option you recognise. Note that using config.log in this hook will probably not do what you want, because the verbose flag may not yet have been turned on. +### output_filter(rawdog, config, articles) + +* articles: the mutable list of Article objects + +Called before rawdog sorts the list of articles to write. This hook can +be used to remove articles that shouldn't be written. + +### output_sort(rawdog, config, articles) + +* articles: the mutable list of Article objects + +Called after rawdog has sorted the list of articles to write. This hook +can be used to reorder (or completely resort) the list of articles to +write. + +### output_write(rawdog, config, articles) + +* articles: the mutable list of Article objects + +Called just before rawdog starts writing the HTML output. This hook can +be used to implement alternative output methods. + +### output_items_begin(rawdog, config, f) + +* f: a writable file object (__items__) + +Called before rawdog starts expanding the items template. This set of +hooks can be used to implement alternative date (or other section) +headings. + +### output_items_heading(rawdog, config, f, article, date) + +* f: a writable file object (__items__) +* article: the Article object about to be written +* date: the Article's date for sorting purposes + +Called before each item is written. + +### output_items_end(rawdog, config, f) + +* f: a writable file object (__items__) + +Called after all items are written. + diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index de5f8cd..5cabeae 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -859,6 +859,7 @@ __description__ else: article_dates[a] = a.added numarticles = len(articles) + def compare(a, b): """Compare two articles to decide how they should be sorted. Sort by added date, then @@ -873,13 +874,19 @@ __description__ if i != 0: return i return cmp(a.hash, b.hash) + plugins.call_hook("output_filter", self, config, articles) articles.sort(compare) + plugins.call_hook("output_sort", self, config, articles) + if config["maxarticles"] != 0: articles = articles[:config["maxarticles"]] + plugins.call_hook("output_write", self, config, articles) + f = StringIO() itemtemplate = self.get_itemtemplate(config) dw = DayWriter(f, config) + plugins.call_hook("output_items_begin", self, config, f) seen_links = {} seen_guids = {} @@ -922,6 +929,7 @@ __description__ count += 1 dw.time(article_dates[article]) + plugins.call_hook("output_items_heading", self, config, f, article, article_dates[article]) itembits = {} for name, value in feed.args.items(): @@ -978,6 +986,8 @@ __description__ f.write(fill_template(itemtemplate, itembits)) dw.close() + plugins.call_hook("output_items_end", self, config, f) + bits["items"] = f.getvalue() bits["num_items"] = str(numarticles) config.log("Selected ", count, " of ", numarticles, " articles to write; ignored ", dup_count, " duplicates") -- 2.35.1