Skip to content
Permalink
Browse files

Merge branch 'master' into baguette

  • Loading branch information
ralsina committed May 24, 2017
2 parents 2f528cf + fb06046 commit de409010652a3139e90293933abfeb3a77713d5c
Showing with 47 additions and 12 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 CHANGES.txt
  3. +12 −4 docs/extending.txt
  4. +7 −2 docs/manual.txt
  5. +2 −2 nikola/nikola.py
  6. +1 −1 nikola/plugins/task/galleries.py
  7. +1 −1 nikola/plugins/task/listings.py
  8. +15 −1 nikola/utils.py
  9. +1 −1 requirements-tests.txt
  10. +4 −0 snapcraft.yaml
@@ -194,4 +194,6 @@ Session.vim
.netrwhist
*~

# Demo for Bagguette
bower_components/baguettebox.js/demo
# End of https://www.gitignore.io/api/pydev,python,pycharm,vim
@@ -17,6 +17,8 @@ Features
Bugfixes
--------

* Save dependencies for template hooks properly (using .__doc__ or
.template_registry_identifier for callables)
* Enable larger panorama thumbnails (Issue #2780)
* Disable ``archive_rss`` link handler, which was useless because no
such RSS was ever generated (Issue #2783)
@@ -537,21 +537,22 @@ HTML:

# In set_site
def generate_html_bit(name, ftype='js'):
"""Generate HTML for an asset."""
return '<script src="/assets/{t}/{n}.{t}">'.format(n=name, t=ftype)

site.template_hooks['extra_head'].append(generate_html_bit, False, 'fancyplugin', type='js')
site.template_hooks['extra_head'].append(generate_html_bit, False, 'fancyplugin', ftype='js')


The second argument to ``append()`` is used to determine whether the function
needs access to the current template context and the site. If it is set to
``True``, the function will also receive ``site`` and ``context`` keyword
arguments. Example use:


.. code-block:: python

# In set_site
def greeting(addr, endswith='', site=None, context=None):
"""Greet someone."""
if context['lang'] == 'en':
greet = u'Hello'
elif context['lang'] == 'es':
@@ -564,6 +565,13 @@ arguments. Example use:

site.template_hooks['page_header'].append(greeting, True, u'Nikola Tesla', endswith=u'!')

Dependencies for template hooks:

* if the input is a string, the string value, alongside arguments to ``append``, is used for calculating dependencies
* if the input is a callable, it attempts ``input.template_registry_identifier``, then ``input.__doc__``, and if neither is available, it uses a static string.

Make sure to provide at least a docstring, or a identifier, to ensure rebuilds work properly.

Shortcodes
==========

@@ -579,7 +587,7 @@ So, if you are creating a plugin that generates markup, it may be a good idea
to register it as a shortcode in addition of to restructured text directive or
markdown extension, thus making it available to all markup formats.

To implement your own shortcodes from a plugin, you can create a plugin inheriting ``ShortcodePlugin`` and
To implement your own shortcodes from a plugin, you can create a plugin inheriting ``ShortcodePlugin`` and
from its ``set_site`` method, call

``Nikola.register_shortcode(name, func)`` with the following arguments:
@@ -610,7 +618,7 @@ variable keyword arguments):
between them, otherwise ``None``.

``lang``:
The current language.
The current language.

If the shortcode tag has arguments of the form ``foo=bar`` they will be
passed as named arguments. Everything else will be passed as positional
@@ -2028,8 +2028,10 @@ To use mathematics in a post, you **must** add the ``mathjax`` tag, no matter
which renderer you are using. (Exception: posts that are Jupyter Notebooks are
automatically marked as math)

By default, Nikola will accept ``\(...\)`` for inline math; ``\[...\]`` and
``$$...$$`` for display math. If you want to use the old ``$...$`` syntax as well
.. Note to editors: the paragraph below uses U+200B, zero-width space. Don’t break it.

By default, Nikola will accept ``\​(...\​)`` for inline math; ``\​[...\​]`` and
``$​$...$​$`` for display math. If you want to use the old ``$...$`` syntax as well
(which may conflict with running text!), you need to use special config for
your renderer:

@@ -2060,6 +2062,9 @@ your renderer:
]
"""

*(Note: the previous paragraph uses invisible characters to prevent rendering
TeX for display, so don’t copy the examples with three dots to your posts)*

Inline usage
~~~~~~~~~~~~

@@ -950,7 +950,7 @@ def __init__(self, **config):
# TODO: remove in v8, or earlier
if ('THEME_REVEAL_CONFIG_SUBTHEME' in config or 'THEME_REVEAL_CONFIG_TRANSITION' in config or
(self.config['THEME'] in ('reveal', 'reveal-jinja') and
('subtheme' not in config.GLOBAL_CONTEXT or 'transition' not in config.GLOBAL_CONTEXT))):
('subtheme' not in config['GLOBAL_CONTEXT'] or 'transition' not in config['GLOBAL_CONTEXT']))):
utils.LOGGER.warn('The THEME_REVEAL_CONFIG_* settings are deprecated. Use `subtheme` and `transition` in GLOBAL_CONTEXT instead.')
self._GLOBAL_CONTEXT['subtheme'] = config.get('THEME_REVEAL_CONFIG_SUBTHEME', 'sky')
self._GLOBAL_CONTEXT['transition'] = config.get('THEME_REVEAL_CONFIG_TRANSITION', 'cube')
@@ -2243,7 +2243,7 @@ def generic_renderer(self, lang, output_name, template_name, filters, file_deps=
deps_dict.update(post_deps_dict)

for k, v in self.GLOBAL_CONTEXT['template_hooks'].items():
deps_dict['||template_hooks|{0}||'.format(k)] = v._items
deps_dict['||template_hooks|{0}||'.format(k)] = v.calculate_deps()

for k in self._GLOBAL_CONTEXT_TRANSLATABLE:
deps_dict[k] = deps_dict['global'][k](lang)
@@ -173,7 +173,7 @@ def gen_tasks(self):
self.image_ext_list.extend(self.site.config.get('EXTRA_IMAGE_EXTENSIONS', []))

for k, v in self.site.GLOBAL_CONTEXT['template_hooks'].items():
self.kw['||template_hooks|{0}||'.format(k)] = v._items
self.kw['||template_hooks|{0}||'.format(k)] = v.calculate_deps()

self.site.scan_posts()
yield self.group_task()
@@ -187,7 +187,7 @@ def render_listing(in_name, out_name, input_folder, output_folder, folders=[], f
uptodate = {'c': self.site.GLOBAL_CONTEXT}

for k, v in self.site.GLOBAL_CONTEXT['template_hooks'].items():
uptodate['||template_hooks|{0}||'.format(k)] = v._items
uptodate['||template_hooks|{0}||'.format(k)] = v.calculate_deps()

for k in self.site._GLOBAL_CONTEXT_TRANSLATABLE:
uptodate[k] = self.site.GLOBAL_CONTEXT[k](self.kw['default_lang'])
@@ -512,9 +512,23 @@ def append(self, inp, wants_site_and_context=False, *args, **kwargs):
c = callable(inp)
self._items.append((c, inp, wants_site_and_context, args, kwargs))

def calculate_deps(self):
"""Calculate dependencies for a registry."""
deps = []
for is_callable, inp, wants_site_and_context, args, kwargs in self._items:
if not is_callable:
name = inp
elif hasattr(inp, 'template_registry_identifier'):
name = inp.template_registry_identifier
elif hasattr(inp, '__doc__'):
name = inp.__doc__
else:
name = '_undefined_callable_'
deps.append((is_callable, name, wants_site_and_context, args, kwargs))

def __hash__(self):
"""Return hash of a registry."""
return hash(config_changed({self.name: self._items})._calc_digest())
return hash(config_changed({self.name: self.calculate_deps()})._calc_digest())

def __str__(self):
"""Stringify a registry."""
@@ -1,7 +1,7 @@
-r requirements-extras.txt
mock==2.0.0
coverage==4.4.1
pytest==3.0.7
pytest==3.1.0
pytest-cov==2.5.1
freezegun==0.3.9
codacy-coverage==1.3.6
@@ -51,3 +51,7 @@ parts:
- notebook>=4.0.0
- ipykernel>=4.0.0
build-packages: [libjpeg-dev]
install: |
find $SNAPCRAFT_PART_INSTALL -name '*.a' -exec rm {} \;
find $SNAPCRAFT_PART_INSTALL -name 'terminado' -type d -exec rm {} \;
find $SNAPCRAFT_PART_INSTALL -name 'tornado' -type d -exec rm {} \;

0 comments on commit de40901

Please sign in to comment.