Add several hooks into write().
authorAdam Sampson <ats@offog.org>
Tue, 21 Dec 2004 23:53:06 +0000 (23:53 +0000)
committerAdam Sampson <ats@offog.org>
Tue, 21 Dec 2004 23:53:06 +0000 (23:53 +0000)
PLUGINS
rawdoglib/rawdog.py

diff --git a/PLUGINS b/PLUGINS
index 7e9a0223924276fb69d53f3f3dbfa01a6769606d..2c067d158607d0cff9b653b367eadd4d1d71cf4d 100644 (file)
--- 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.
+
index de5f8cd38272dbedca5e164248e1b12e45659865..5cabeaee46ce1450d7262877f3219d8881a380c7 100644 (file)
@@ -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")