From ffb671c61a24a9086343b54bad080e145ff33fc5 Mon Sep 17 00:00:00 2001 From: Dererk Date: Tue, 15 Nov 2016 14:18:46 -0300 Subject: New upstream version 7.8.1 --- docs/extending.txt | 174 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 156 insertions(+), 18 deletions(-) (limited to 'docs/extending.txt') diff --git a/docs/extending.txt b/docs/extending.txt index 9e5dfbc..4fa935d 100644 --- a/docs/extending.txt +++ b/docs/extending.txt @@ -9,7 +9,7 @@ Extending Nikola ================ -:Version: 7.7.3 +:Version: 7.8.1 :Author: Roberto Alsina .. class:: alert alert-info pull-right @@ -63,13 +63,13 @@ When you run ``nikola --help`` you will see something like this: nikola import_feed import a RSS/Atom dump nikola import_wordpress import a WordPress dump nikola init create a Nikola site in the specified folder - nikola install_theme install theme into current site nikola list list tasks from dodo file nikola mincss apply mincss to the generated site nikola new_post create a new blog post or site page nikola run run tasks nikola serve start the test webserver nikola strace use strace to list file_deps and targets + nikola theme manage themes nikola version print the Nikola version number nikola help show help / reference @@ -172,8 +172,8 @@ TemplateSystem Plugins ---------------------- Nikola supports Mako and Jinja2. If you prefer some other templating -system, then you will have to write a TemplateSystem plugin. Here's how they work. -First, you have to create a .plugin file. Here's the one for the Mako plugin: +system, then you will have to write a ``TemplateSystem`` plugin. Here's how they work. +First, you have to create a ``.plugin`` file. Here's the one for the Mako plugin: .. code-block:: ini @@ -253,10 +253,10 @@ Task Plugins ------------ If you want to do something that depends on the data in your site, you -probably want to do a Task plugin, which will make it be part of the -``nikola build`` command. There are the currently available tasks, all +probably want to do a ``Task`` plugin, which will make it be part of the +``nikola build`` command. These are the currently available tasks, all provided by plugins: -T + .. sidebar:: Other Tasks There are also ``LateTask`` plugins, which are executed later, @@ -380,7 +380,7 @@ They must provide: If the compiler produces something other than HTML files, it should also implement ``extension`` which returns the preferred extension for the output file. -These plugins can also be used to extract metadata from file. To do so, the +These plugins can also be used to extract metadata from a file. To do so, the plugin may implement ``read_metadata`` that will return a dict containing the metadata contained in the file. @@ -389,7 +389,8 @@ RestExtension Plugins Implement directives for reStructuredText, see `media.py `__ for a simple example. -If your output depends on a config value, you need to make your post record a dependency on a pseudo-path, like this: +If your output depends on a config value, you need to make your post record a +dependency on a pseudo-path, like this: .. code-block:: text @@ -397,17 +398,18 @@ If your output depends on a config value, you need to make your post record a de Then, whenever the ``OPTIONNAME`` option is changed in conf.py, the file will be rebuilt. -If your directive depends or may depend on the whole timeline (like the post-list directive, where adding new posts -to the site could make it stale), you should record a dependency on the -pseudo-path ``####MAGIC####TIMELINE``. +If your directive depends or may depend on the whole timeline (like the +``post-list`` directive, where adding new posts to the site could make it +stale), you should record a dependency on the pseudo-path +``####MAGIC####TIMELINE``. MarkdownExtension Plugins ------------------------- Implement Markdown extensions, see `mdx_nikola.py `__ for a simple example. -Note that python markdown extensions are often also available as separate packages. This is only meant to ship extensions -along with Nikola. +Note that Python markdown extensions are often also available as separate +packages. This is only meant to ship extensions along with Nikola. SignalHandler Plugins --------------------- @@ -445,6 +447,16 @@ Currently Nikola emits the following signals: 'undeployed': # all files not deployed since they are either future posts/drafts } +``compiled`` + When a post/page is compiled from its source to html, before anything else is done with it. The signal + data is in the form:: + + { + 'source': # the path to the source file + 'dest': # the path to the cache file for the post/page + 'post': # the Post object for the post/page + } + One example is the `deploy_hooks plugin. `__ ConfigPlugin Plugins @@ -458,7 +470,7 @@ from ``super()``. Example plugin: `navstories {{ bar }} + +Will result in this output + +.. code:: html + +
baz
+ + +State and Cache +=============== + +Sometimes your plugins will need to cache things to speed up further actions. Here are the conventions for that: + +* If it's a file, put it somewhere in ``self.site.config['CACHE_FOLDER']`` (defaults to ``cache/``. +* If it's a value, use ``self.site.cache.set(key, value)`` to set it and ``self.site.cache.get(key)`` to get it. + The key should be a string, the value should be json-encodable (so, be careful with datetime objects) + +The values and files you store there can **and will** be deleted sometimes by the user. They should always be +things you can reconstruct without lossage. They are throwaways. + +On the other hand, sometimes you want to save something that is **not** a throwaway. These are things that may +change the output, so the user should not delete them. We call that **state**. To save state: + +* If it's a file, put it somewhere in the working directory. Try not to do that please. +* If it's a value, use ``self.site.state.set(key, value)`` to set it and ``self.state.cache.get(key)`` to get it. + The key should be a string, the value should be json-encodable (so, be careful with datetime objects) + +The ``cache`` and ``state`` objects are rather simplistic, and that's intentional. They have no default values: if +the key is not there, you will get ``None`` and like it. They are meant to be both threadsafe, but hey, who can +guarantee that sort of thing? + +There are no sections, and no access protection, so let's not use it to store passwords and such. Use responsibly. + -- cgit v1.2.3