summaryrefslogtreecommitdiff
path: root/docs/plugins.rst
diff options
context:
space:
mode:
authorAlexis Métaireau <alexis@notmyidea.org>2013-08-01 14:38:00 +0200
committerAlexis Métaireau <alexis@notmyidea.org>2013-08-01 14:47:56 +0200
commit4fa9184b01642d1c2738db627f57353134ca65e0 (patch)
treea3358282171a829c708e69a337310fb7c610888e /docs/plugins.rst
parent7ec4d5faa25040f6cabcf2ddbab58b19c4b77a2c (diff)
downloadpelican-4fa9184b01642d1c2738db627f57353134ca65e0.tar.gz
Start a section about plugin recipes in the docs
Diffstat (limited to 'docs/plugins.rst')
-rw-r--r--docs/plugins.rst66
1 files changed, 66 insertions, 0 deletions
diff --git a/docs/plugins.rst b/docs/plugins.rst
index 9bf08ff3..93307afb 100644
--- a/docs/plugins.rst
+++ b/docs/plugins.rst
@@ -123,3 +123,69 @@ request if you need them!
static_generate_context static_generator_context
static_generate_preread static_generator_preread
========================== ===========================
+
+Recipes
+=======
+
+We eventually realised some of the recipes to create plugins would be best
+shared in the documentation somewhere, so here they are!
+
+How to create a new reader
+--------------------------
+
+One thing you might want is to add the support for your very own input
+format. While it might make sense to add this feature in pelican core, we
+wisely chose to avoid this situation, and have the different readers defined in
+plugins.
+
+The rationale behind this choice is mainly that plugins are really easy to
+write and don't slow down pelican itself when they're not active.
+
+No more talking, here is the example::
+
+ from pelican import signals
+ from pelican.readers import EXTENSIONS, Reader
+
+ # Create a new reader class, inheriting from the pelican.reader.Reader
+ class NewReader(Reader):
+ enabled = True # Yeah, you probably want that :-)
+
+ # The list of extensions you want this reader to match with.
+ # In the case multiple readers use the same extensions, the latest will
+ # win (so the one you're defining here, most probably).
+ file_extensions = ['yeah']
+
+ # You need to have a read method, which takes a filename and returns
+ # some content and the associated metadata.
+ def read(self, filename):
+ metadata = {'title': 'Oh yeah',
+ 'category': 'Foo',
+ 'date': '2012-12-01'}
+
+ parsed = {}
+ for key, value in metadata.items():
+ parsed[key] = self.process_metadata(key, value)
+
+ return "Some content", parsed
+
+ def add_reader(arg):
+ EXTENSIONS['yeah'] = NewReader
+
+ # this is how pelican works.
+ def register():
+ signals.initialized.connect(add_reader)
+
+
+Adding a new generator
+----------------------
+
+Adding a new generator is also really easy. You might want to have a look at
+:doc:`internals` for more information on how to create your own generator.
+
+::
+
+ def get_generators(generators):
+ # define a new generator here if you need to
+ return generators
+
+ signals.get_generators.connect(get_generators)