diff --git a/docs/plugins.rst b/docs/plugins.rst index 654b18f7..632408f0 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -48,20 +48,23 @@ which you map the signals to your plugin logic. Let's take a simple example:: signals.initialized.connect(test) + List of signals =============== Here is the list of currently implemented signals: -========================= ============================ =========================================================================== -Signal Arguments Description -========================= ============================ =========================================================================== +========================= ======================================= ========================================= +Signal Arguments Description +========================= ======================================= ========================================= +>>>>>>> rach/master initialized pelican object finalized pelican object invoked after all the generators are executed and just before pelican exits usefull for custom post processing actions, such as: - minifying js/css assets. - notify/ping search engines with an updated sitemap. article_generate_context article_generator, metadata +<<<<<<< HEAD article_generator_init article_generator invoked in the ArticlesGenerator.__init__ get_generators generators invoked in Pelican.get_generator_classes, can return a Generator, or several @@ -73,6 +76,25 @@ pages_generator_init pages_generator invoked in the PagesG The list is currently small, don't hesitate to add signals and make a pull request if you need them! +.. note:: + + The signal ``content_object_init`` can send different type of object as + argument. If you want to register only one type of object then you will + need to specify the sender when you are connecting to the signal. + + :: + + from pelican import signals + from pelican import contents + + def test(sender, instance): + print "%s : %s content initialized !!" % (sender, instance) + + def register(): + signals.content_object_init.connect(test, sender=contents.Article) + + + List of plugins =============== diff --git a/pelican/contents.py b/pelican/contents.py index 851607a5..b5701732 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -11,7 +11,7 @@ from sys import platform, stdin from pelican.settings import _DEFAULT_CONFIG from pelican.utils import slugify, truncate_html_words - +from pelican import signals logger = logging.getLogger(__name__) @@ -106,6 +106,8 @@ class Page(object): if 'summary' in metadata: self._summary = metadata['summary'] + signals.content_object_init.send(self.__class__, instance=self) + def check_properties(self): """test that each mandatory property is set.""" for prop in self.mandatory_properties: diff --git a/pelican/signals.py b/pelican/signals.py index 408d84c9..f3e16e76 100644 --- a/pelican/signals.py +++ b/pelican/signals.py @@ -7,3 +7,4 @@ article_generator_init = signal('article_generator_init') get_generators = signal('get_generators') pages_generate_context = signal('pages_generate_context') pages_generator_init = signal('pages_generator_init') +content_object_init = signal('content_object_init') diff --git a/tests/test_contents.py b/tests/test_contents.py index bc028ea8..6b0f93ea 100644 --- a/tests/test_contents.py +++ b/tests/test_contents.py @@ -5,7 +5,7 @@ from .support import unittest from pelican.contents import Page, Article from pelican.settings import _DEFAULT_CONFIG from pelican.utils import truncate_html_words - +from pelican.signals import content_object_init from jinja2.utils import generate_lorem_ipsum # generate one paragraph, enclosed with
@@ -158,6 +158,17 @@ class TestPage(unittest.TestCase): return page_kwargs + def test_signal(self): + """If a title is given, it should be used to generate the slug.""" + + def receiver_test_function(sender,instance): + pass + + content_object_init.connect(receiver_test_function ,sender=Page) + page = Page(**self.page_kwargs) + self.assertTrue(content_object_init.has_receivers_for(Page)) + + class TestArticle(TestPage): def test_template(self): """