Skip to content
Permalink
Browse files

Offer global_data everywhere (#2488)

The `global_data` name will be usable everywhere. `data` will still
work outside of shortcodes.
  • Loading branch information
Kwpolska committed Oct 30, 2016
1 parent 48fa3bd commit d7067cc6899683e9d1eb10c27404b8fdc4b9a1c7
Showing with 12 additions and 7 deletions.
  1. +2 −1 CHANGES.txt
  2. +6 −3 docs/manual.txt
  3. +4 −3 nikola/nikola.py
@@ -4,7 +4,8 @@ New in master
Bugfixes
--------

* Make "data" from global context available to templated shortcodes (Issue #2488)
* Make ``data`` from global context available to templated shortcodes
as ``global_data`` (Issue #2488)
* Don't crash if plugins is a file (Issue #2539)

Features
@@ -1086,9 +1086,10 @@ In that case, the template engine used will be your theme's and the arguments yo
as well as the global context from your ``conf.py``, are available to the template you
are creating.

You can use anything defined in your confguration's ``GLOBAL_CONTEXT`` as variables in your
shortcode template, with a caveat: Because of an unfortunate implementation detail, data is called
"global_data" when used in a shortcode.
You can use anything defined in your confguration's ``GLOBAL_CONTEXT`` as
variables in your shortcode template, with a caveat: Because of an unfortunate
implementation detail (a name conflict), ``data`` is called ``global_data``
when used in a shortcode.

The Global Context and Data files
---------------------------------
@@ -1119,6 +1120,8 @@ JSON/YAML/TOML files and Nikola generates a large page with data from all data
files. (This is especially useful with some automatic rebuild feature, like
those documented in `Deployment`_)

Data files are also available as ``global_data``, to avoid name conflicts in
shortcodes. (``global_data`` works everywhere.)

Redirections
------------
@@ -1165,6 +1165,8 @@ def _set_global_context_from_data(self):
data = utils.load_data(fname)
key = os.path.splitext(fname.split(os.sep, 1)[1])[0]
self._GLOBAL_CONTEXT['data'][key] = data
# Offer global_data as an alias for data (Issue #2488)
self._GLOBAL_CONTEXT['global_data'] = self._GLOBAL_CONTEXT['data']

def _activate_plugins_of_category(self, category):
"""Activate all the plugins of a given category and return them."""
@@ -1492,13 +1494,12 @@ def _make_renderfunc(self, t_data, fname=None):
Global context keys are made available as part of the context,
respecting locale.
As a special quirk, the "data" key from global_context is made
available as "global_data" because of name clobbering.
As a special quirk, the "data" key from global_context is
available only as "global_data" because of name clobbering.
"""
def render_shortcode(*args, **kw):
context = self.GLOBAL_CONTEXT.copy()
context['global_data'] = context['data']
context.update(kw)
context['_args'] = args
context['lang'] = utils.LocaleBorg().current_lang

0 comments on commit d7067cc

Please sign in to comment.
You can’t perform that action at this time.