Skip to content

Commit

Permalink
Update compiler plugins for Nikola v8 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Sep 3, 2017
1 parent d717b0e commit 34343ff
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 73 deletions.
18 changes: 12 additions & 6 deletions v7/asciidoc/asciidoc.py
Expand Up @@ -49,30 +49,36 @@ class CompileAsciiDoc(PageCompiler):
name = "asciidoc"
demote_headers = True

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
binary = self.site.config.get('ASCIIDOC_BINARY', 'asciidoc')
try:
subprocess.check_call((binary, '-b', 'html5', '-s', '-o', dest, source))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with open(dest, 'r', encoding='utf-8') as inf:
output, shortcode_deps = self.site.apply_shortcodes(inf.read(), with_dependencies=True)
with open(dest, 'w', encoding='utf-8') as outf:
outf.write(output)
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps
except OSError as e:
print(e)
req_missing(['asciidoc'], 'build this site (compile with asciidoc)', python=False)

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
one_file = kw.pop('onefile', False) # NOQA
Expand Down
18 changes: 12 additions & 6 deletions v7/bbcode/bbcode.py
Expand Up @@ -54,14 +54,11 @@ def __init__(self):
self.parser = bbcode.Parser()
self.parser.add_simple_formatter("note", "")

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
if bbcode is None:
req_missing(['bbcode'], 'build this site (compile BBCode)')
makedirs(os.path.dirname(dest))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with codecs.open(dest, "w+", "utf8") as out_file:
with codecs.open(source, "r", "utf8") as in_file:
data = in_file.read()
Expand All @@ -73,11 +70,20 @@ def compile_html(self, source, dest, is_two_file=True):
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
onefile = kw.pop('onefile', False)
Expand Down
18 changes: 12 additions & 6 deletions v7/commonmark/commonmark.py
Expand Up @@ -57,14 +57,11 @@ def __init__(self, *args, **kwargs):
self.parser = CommonMark.Parser()
self.renderer = CommonMark.HtmlRenderer()

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
if CommonMark is None:
req_missing(['commonmark'], 'build this site (compile with CommonMark)')
makedirs(os.path.dirname(dest))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with codecs.open(dest, "w+", "utf8") as out_file:
with codecs.open(source, "r", "utf8") as in_file:
data = in_file.read()
Expand All @@ -76,11 +73,20 @@ def compile_html(self, source, dest, is_two_file=True):
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
onefile = kw.pop('onefile', False)
Expand Down
2 changes: 1 addition & 1 deletion v7/irclogs/irclogs.plugin
Expand Up @@ -3,7 +3,7 @@ Name = irclogs
Module = irclogs

[Nikola]
PluginCategory = task
PluginCategory = Compiler
MinVersion = 7.3.0

[Documentation]
Expand Down
3 changes: 1 addition & 2 deletions v7/irclogs/irclogs.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright © 2014–2015, Chris Warrick.
# Copyright © 2014–2017, Chris Warrick.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -53,7 +53,6 @@ class CompileIRCLogs(PageCompiler):

def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
"""Compile into HTML, using NikolaPygmentsHTML."""
makedirs(os.path.dirname(dest))
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
Expand Down
18 changes: 12 additions & 6 deletions v7/kramdown/kramdown.py
Expand Up @@ -49,7 +49,8 @@ class CompileKramdown(PageCompiler):
name = "kramdown"
demote_headers = True

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
command = ['kramdown', '-o', 'html', '--no-auto-ids', abspath(source)]

Expand All @@ -59,22 +60,27 @@ def compile_html(self, source, dest, is_two_file=True):

with open(abspath(dest), 'wt') as f:
subprocess.check_call(command, stdout=f)
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with open(dest, 'r', encoding='utf-8') as inf:
output, shortcode_deps = self.site.apply_shortcodes(inf.read(), with_dependencies=True)
with open(dest, 'w', encoding='utf-8') as outf:
outf.write(output)
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
onefile = kw.pop('onefile', False)
Expand Down
18 changes: 12 additions & 6 deletions v7/markmin/markmin/__init__.py
Expand Up @@ -46,12 +46,9 @@ class CompileMarkmin(PageCompiler):
name = "markmin"
demote_headers = True

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with codecs.open(source, "rb+", "utf8") as in_f:
with codecs.open(dest, "wb+", "utf8") as out_f:
data = in_f.read()
Expand All @@ -64,11 +61,20 @@ def compile_html(self, source, dest, is_two_file=True):
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
one_file = kw.pop('onefile', False) # NOQA
Expand Down
18 changes: 12 additions & 6 deletions v7/mediawiki/mediawiki.py
Expand Up @@ -57,14 +57,11 @@ class CompileMediaWiki(PageCompiler):
name = "mediawiki"
demote_headers = True

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
if mw is None:
req_missing(['smc.mw'], 'build this site (compile with MediaWiki)', python=True)
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
Expand All @@ -78,11 +75,20 @@ def compile_html(self, source, dest, is_two_file=True):
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
Expand Down
18 changes: 12 additions & 6 deletions v7/misaka/misaka.py
Expand Up @@ -61,14 +61,11 @@ def __init__(self, *args, **kwargs):
self.ext = misaka.EXT_FENCED_CODE | misaka.EXT_STRIKETHROUGH | \
misaka.EXT_AUTOLINK | misaka.EXT_NO_INTRA_EMPHASIS

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
if misaka is None:
req_missing(['misaka'], 'build this site (compile with misaka)')
makedirs(os.path.dirname(dest))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with codecs.open(dest, "w+", "utf8") as out_file:
with codecs.open(source, "r", "utf8") as in_file:
data = in_file.read()
Expand All @@ -80,11 +77,20 @@ def compile_html(self, source, dest, is_two_file=True):
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
onefile = kw.pop('onefile', False)
Expand Down
18 changes: 12 additions & 6 deletions v7/mistune/mistune.py
Expand Up @@ -56,14 +56,11 @@ def __init__(self, *args, **kwargs):
if mistune is not None:
self.parser = mistune.Markdown()

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
if mistune is None:
req_missing(['mistune'], 'build this site (compile with mistune)')
makedirs(os.path.dirname(dest))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with codecs.open(dest, "w+", "utf8") as out_file:
with codecs.open(source, "r", "utf8") as in_file:
data = in_file.read()
Expand All @@ -75,11 +72,20 @@ def compile_html(self, source, dest, is_two_file=True):
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
onefile = kw.pop('onefile', False)
Expand Down
12 changes: 11 additions & 1 deletion v7/odt/odt.py
Expand Up @@ -55,7 +55,8 @@ class CompileODT(PageCompiler):

name = "odt"

def compile_html(self, source, dest, is_two_file=True):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
if ODF2XHTML is None:
req_missing(['odfpy'], 'build this site (compile odt)')
Expand All @@ -81,6 +82,15 @@ def compile_html(self, source, dest, is_two_file=True):
with io.open(dest, 'w+', encoding='utf-8') as outf:
outf.write(etree.tostring(body, encoding='unicode'))

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None

return compile(source, dest, is_two_file, post, None)

def create_post(self, path, **kw):
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
Expand Down

0 comments on commit 34343ff

Please sign in to comment.