aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/compile/rest
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/compile/rest')
-rw-r--r--nikola/plugins/compile/rest/__init__.py26
-rw-r--r--nikola/plugins/compile/rest/chart.py13
-rw-r--r--nikola/plugins/compile/rest/doc.py2
-rw-r--r--nikola/plugins/compile/rest/listing.py1
-rw-r--r--nikola/plugins/compile/rest/post_list.py5
-rw-r--r--nikola/plugins/compile/rest/slides.py9
-rw-r--r--nikola/plugins/compile/rest/vimeo.py6
-rw-r--r--nikola/plugins/compile/rest/youtube.py2
8 files changed, 38 insertions, 26 deletions
diff --git a/nikola/plugins/compile/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py
index 9a4e19b..a93199c 100644
--- a/nikola/plugins/compile/rest/__init__.py
+++ b/nikola/plugins/compile/rest/__init__.py
@@ -40,13 +40,8 @@ try:
except ImportError:
has_docutils = False
-try:
- from collections import OrderedDict
-except ImportError:
- OrderedDict = dict # NOQA
-
from nikola.plugin_categories import PageCompiler
-from nikola.utils import get_logger, makedirs, req_missing
+from nikola.utils import get_logger, makedirs, req_missing, write_metadata
class CompileRest(PageCompiler):
@@ -102,22 +97,25 @@ class CompileRest(PageCompiler):
else:
return False
- def create_post(self, path, onefile=False, is_page=False, **kw):
- metadata = OrderedDict()
+ def create_post(self, path, **kw):
+ content = kw.pop('content', None)
+ onefile = kw.pop('onefile', False)
+ # is_page is not used by create_post as of now.
+ kw.pop('is_page', False)
+ metadata = {}
metadata.update(self.default_metadata)
metadata.update(kw)
makedirs(os.path.dirname(path))
+ if not content.endswith('\n'):
+ content += '\n'
with codecs.open(path, "wb+", "utf8") as fd:
if onefile:
- for k, v in metadata.items():
- fd.write('.. {0}: {1}\n'.format(k, v))
- fd.write("\nWrite your {0} here.".format('page' if is_page else 'post'))
+ fd.write(write_metadata(metadata))
+ fd.write('\n' + content)
def set_site(self, site):
for plugin_info in site.plugin_manager.getPluginsOfCategory("RestExtension"):
- if (plugin_info.name in site.config['DISABLED_PLUGINS']
- or (plugin_info.name in site.EXTRA_PLUGINS and
- plugin_info.name not in site.config['ENABLED_EXTRAS'])):
+ if plugin_info.name in site.config['DISABLED_PLUGINS']:
site.plugin_manager.removePluginFromCategory(plugin_info, "RestExtension")
continue
diff --git a/nikola/plugins/compile/rest/chart.py b/nikola/plugins/compile/rest/chart.py
index 03878a3..55ddf5c 100644
--- a/nikola/plugins/compile/rest/chart.py
+++ b/nikola/plugins/compile/rest/chart.py
@@ -37,13 +37,16 @@ except ImportError:
from nikola.plugin_categories import RestExtension
from nikola.utils import req_missing
+_site = None
+
class Plugin(RestExtension):
name = "rest_chart"
def set_site(self, site):
- self.site = site
+ global _site
+ _site = self.site = site
directives.register_directive('chart', Chart)
return super(Plugin, self).set_site(site)
@@ -146,5 +149,9 @@ class Chart(Directive):
for line in self.content:
label, series = literal_eval('({0})'.format(line))
chart.add(label, series)
-
- return [nodes.raw('', chart.render().decode('utf8'), format='html')]
+ data = chart.render().decode('utf8')
+ if _site and _site.invariant:
+ import re
+ data = re.sub('id="chart-[a-f0-9\-]+"', 'id="chart-foobar"', data)
+ data = re.sub('#chart-[a-f0-9\-]+', '#chart-foobar', data)
+ return [nodes.raw('', data, format='html')]
diff --git a/nikola/plugins/compile/rest/doc.py b/nikola/plugins/compile/rest/doc.py
index a150a81..6143606 100644
--- a/nikola/plugins/compile/rest/doc.py
+++ b/nikola/plugins/compile/rest/doc.py
@@ -48,7 +48,6 @@ def doc_role(name, rawtext, text, lineno, inliner,
# split link's text and post's slug in role content
has_explicit_title, title, slug = split_explicit_title(text)
-
# check if the slug given is part of our blog posts/pages
twin_slugs = False
post = None
@@ -73,7 +72,6 @@ def doc_role(name, rawtext, text, lineno, inliner,
if not has_explicit_title:
# use post's title as link's text
title = post.title()
-
permalink = post.permalink()
if twin_slugs:
msg = inliner.reporter.warning(
diff --git a/nikola/plugins/compile/rest/listing.py b/nikola/plugins/compile/rest/listing.py
index d70e02d..18a1807 100644
--- a/nikola/plugins/compile/rest/listing.py
+++ b/nikola/plugins/compile/rest/listing.py
@@ -46,6 +46,7 @@ except ImportError: # docutils < 0.9 (Debian Sid For The Loss)
class CodeBlock(Directive):
required_arguments = 1
has_content = True
+ option_spec = {}
CODE = '<pre>{0}</pre>'
def run(self):
diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py
index 6804b58..456e571 100644
--- a/nikola/plugins/compile/rest/post_list.py
+++ b/nikola/plugins/compile/rest/post_list.py
@@ -124,7 +124,10 @@ class PostList(Directive):
show_all = self.options.get('all', False)
lang = self.options.get('lang', utils.LocaleBorg().current_lang)
template = self.options.get('template', 'post_list_directive.tmpl')
- post_list_id = self.options.get('id', 'post_list_' + uuid.uuid4().hex)
+ if self.site.invariant: # for testing purposes
+ post_list_id = self.options.get('id', 'post_list_' + 'fixedvaluethatisnotauuid')
+ else:
+ post_list_id = self.options.get('id', 'post_list_' + uuid.uuid4().hex)
posts = []
step = -1 if reverse is None else None
diff --git a/nikola/plugins/compile/rest/slides.py b/nikola/plugins/compile/rest/slides.py
index 203ae51..ea8e413 100644
--- a/nikola/plugins/compile/rest/slides.py
+++ b/nikola/plugins/compile/rest/slides.py
@@ -53,12 +53,17 @@ class Slides(Directive):
if len(self.content) == 0:
return
+ if self.site.invariant: # for testing purposes
+ carousel_id = 'slides_' + 'fixedvaluethatisnotauuid'
+ else:
+ carousel_id = 'slides_' + uuid.uuid4().hex
+
output = self.site.template_system.render_template(
'slides.tmpl',
None,
{
- 'content': self.content,
- 'carousel_id': 'slides_' + uuid.uuid4().hex,
+ 'slides_content': self.content,
+ 'carousel_id': carousel_id,
}
)
return [nodes.raw('', output, format='html')]
diff --git a/nikola/plugins/compile/rest/vimeo.py b/nikola/plugins/compile/rest/vimeo.py
index 82c4dc1..4b34dfe 100644
--- a/nikola/plugins/compile/rest/vimeo.py
+++ b/nikola/plugins/compile/rest/vimeo.py
@@ -49,9 +49,9 @@ class Plugin(RestExtension):
return super(Plugin, self).set_site(site)
-CODE = """<iframe src="http://player.vimeo.com/video/{vimeo_id}"
+CODE = """<iframe src="//player.vimeo.com/video/{vimeo_id}"
width="{width}" height="{height}"
-frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen>
+frameborder="0" webkitAllowFullScreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowFullScreen="allowFullScreen">
</iframe>
"""
@@ -108,7 +108,7 @@ class Vimeo(Directive):
if json: # we can attempt to retrieve video attributes from vimeo
try:
- url = ('http://vimeo.com/api/v2/video/{0}'
+ url = ('//vimeo.com/api/v2/video/{0}'
'.json'.format(self.arguments[0]))
data = requests.get(url).text
video_attributes = json.loads(data)[0]
diff --git a/nikola/plugins/compile/rest/youtube.py b/nikola/plugins/compile/rest/youtube.py
index 19e12d1..b32e77a 100644
--- a/nikola/plugins/compile/rest/youtube.py
+++ b/nikola/plugins/compile/rest/youtube.py
@@ -44,7 +44,7 @@ class Plugin(RestExtension):
CODE = """\
<iframe width="{width}"
height="{height}"
-src="http://www.youtube.com/embed/{yid}?rel=0&amp;hd=1&amp;wmode=transparent"
+src="//www.youtube.com/embed/{yid}?rel=0&amp;hd=1&amp;wmode=transparent"
></iframe>"""