diff options
| author | 2021-02-03 19:17:50 -0500 | |
|---|---|---|
| committer | 2021-02-03 19:17:50 -0500 | |
| commit | 475d074fd74425efbe783fad08f97f2df0c4909f (patch) | |
| tree | 2acdae53999b3c74b716efa4edb5b40311fa356a /nikola/plugins/compile/rest/chart.py | |
| parent | cd502d52787f666fff3254d7d7e7578930c813c2 (diff) | |
| parent | 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (diff) | |
Update upstream source from tag 'upstream/8.1.2'
Update to upstream version '8.1.2'
with Debian dir e5e966a9e6010ef70618dc9a61558fa4db35aceb
Diffstat (limited to 'nikola/plugins/compile/rest/chart.py')
| -rw-r--r-- | nikola/plugins/compile/rest/chart.py | 58 |
1 files changed, 11 insertions, 47 deletions
diff --git a/nikola/plugins/compile/rest/chart.py b/nikola/plugins/compile/rest/chart.py index 24f459b..17363cb 100644 --- a/nikola/plugins/compile/rest/chart.py +++ b/nikola/plugins/compile/rest/chart.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2016 Roberto Alsina and others. +# Copyright © 2012-2020 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -23,21 +23,17 @@ # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - """Chart directive for reSTructuredText.""" -from ast import literal_eval - from docutils import nodes from docutils.parsers.rst import Directive, directives +from nikola.plugin_categories import RestExtension + try: import pygal except ImportError: - pygal = None # NOQA - -from nikola.plugin_categories import RestExtension -from nikola.utils import req_missing + pygal = None _site = None @@ -52,8 +48,7 @@ class Plugin(RestExtension): global _site _site = self.site = site directives.register_directive('chart', Chart) - self.site.register_shortcode('chart', _gen_chart) - return super(Plugin, self).set_site(site) + return super().set_site(site) class Chart(Directive): @@ -77,6 +72,7 @@ class Chart(Directive): "classes": directives.unchanged, "css": directives.unchanged, "defs": directives.unchanged, + "data_file": directives.unchanged, "disable_xml_declaration": directives.unchanged, "dots_size": directives.unchanged, "dynamic_print_values": directives.unchanged, @@ -157,41 +153,9 @@ class Chart(Directive): def run(self): """Run the directive.""" self.options['site'] = None - html = _gen_chart(self.arguments[0], data='\n'.join(self.content), **self.options) + html = _site.plugin_manager.getPluginByName( + 'chart', 'ShortcodePlugin').plugin_object.handler( + self.arguments[0], + data='\n'.join(self.content), + **self.options) return [nodes.raw('', html, format='html')] - - -def _gen_chart(chart_type, **_options): - if pygal is None: - msg = req_missing(['pygal'], 'use the Chart directive', optional=True) - return '<div class="text-error">{0}</div>'.format(msg) - options = {} - data = _options.pop('data') - _options.pop('post', None) - _options.pop('site') - if 'style' in _options: - style_name = _options.pop('style') - else: - style_name = 'BlueStyle' - if '(' in style_name: # Parametric style - style = eval('pygal.style.' + style_name) - else: - style = getattr(pygal.style, style_name) - for k, v in _options.items(): - try: - options[k] = literal_eval(v) - except: - options[k] = v - chart = pygal - for o in chart_type.split('.'): - chart = getattr(chart, o) - chart = chart(style=style) - if _site and _site.invariant: - chart.no_prefix = True - chart.config(**options) - for line in data.splitlines(): - line = line.strip() - if line: - label, series = literal_eval('({0})'.format(line)) - chart.add(label, series) - return chart.render().decode('utf8') |
