Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some compile_html leftovers
  • Loading branch information
Kwpolska committed Oct 14, 2016
1 parent 331061f commit 7dfc111
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 25 deletions.
6 changes: 4 additions & 2 deletions docs/extending.txt
Expand Up @@ -367,11 +367,13 @@ PageCompiler Plugins
--------------------

These plugins implement markup languages, they take sources for posts or pages and
create HTML or other output files. A good example is `the misaka plugin. <https://github.com/getnikola/plugins/tree/master/v7/misaka>`__
create HTML or other output files. A good example is `the misaka plugin
<https://github.com/getnikola/plugins/tree/master/v7/misaka>`__ or the built-in
compiler plugins.

They must provide:

``compile_html``
``compile``
Function that builds a file.

``create_post``
Expand Down
8 changes: 4 additions & 4 deletions nikola/nikola.py
Expand Up @@ -1260,7 +1260,7 @@ def get_compiler(self, source_name):
"""
ext = os.path.splitext(source_name)[1]
try:
compile_html = self.inverse_compilers[ext]
compiler = self.inverse_compilers[ext]
except KeyError:
# Find the correct compiler for this files extension
lang_exts_tab = list(self.config['COMPILERS'].items())
Expand All @@ -1280,12 +1280,12 @@ def get_compiler(self, source_name):

lang = langs[0]
try:
compile_html = self.compilers[lang]
compiler = self.compilers[lang]
except KeyError:
exit("Cannot find '{0}' compiler; it might require an extra plugin -- do you have it installed?".format(lang))
self.inverse_compilers[ext] = compile_html
self.inverse_compilers[ext] = compiler

return compile_html
return compiler

def render_template(self, template_name, output_name, context, url_type=None):
"""Render a template with the global context.
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/compile/html.py
Expand Up @@ -24,7 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Implementation of compile_html for HTML source files."""
"""Page compiler plugin for HTML source files."""

from __future__ import unicode_literals

Expand Down
11 changes: 8 additions & 3 deletions nikola/plugins/compile/ipynb.py
Expand Up @@ -24,7 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Implementation of compile_html based on nbconvert."""
"""Page compiler plugin for nbconvert."""

from __future__ import unicode_literals, print_function
import io
Expand Down Expand Up @@ -77,7 +77,7 @@ def set_site(self, site):
self.logger = get_logger('compile_ipynb', STDERR_HANDLER)
super(CompileIPynb, self).set_site(site)

def compile_html_string(self, source, is_two_file=True):
def compile_string(self, source, is_two_file=True):
"""Export notebooks as HTML strings."""
if flag is None:
req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
Expand All @@ -88,11 +88,16 @@ def compile_html_string(self, source, is_two_file=True):
(body, resources) = exportHtml.from_notebook_node(nb_json)
return body

# TODO remove in v8
def compile_html_string(self, source, is_two_file=True):
"""Export notebooks as HTML strings."""
return self.compile_string(source, is_two_file)

def compile(self, source, dest, is_two_file=False, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
with io.open(dest, "w+", encoding="utf8") as out_file:
output = self.compile_html_string(source, is_two_file)
output = self.compile_string(source, is_two_file)
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(post=post))
out_file.write(output)
if post is None:
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -24,7 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Implementation of compile_html based on markdown."""
"""Page compiler plugin for Markdown."""

from __future__ import unicode_literals

Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/compile/pandoc.py
Expand Up @@ -24,7 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Implementation of compile_html based on pandoc.
"""Page compiler plugin for pandoc.
You will need, of course, to install pandoc
"""
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/compile/php.py
Expand Up @@ -24,7 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Implementation of compile_html for HTML+php."""
"""Page compiler plugin for PHP."""

from __future__ import unicode_literals

Expand Down
6 changes: 3 additions & 3 deletions nikola/plugins/compile/rest/__init__.py
Expand Up @@ -93,7 +93,7 @@ def compile_string(self, data, source_path=None, is_two_file=True):
# TODO remove in v8
def compile_html_string(self, data, source_path=None, is_two_file=True):
"""Compile reST into HTML strings."""
self.compile_string(data, source_path, is_two_file)
return self.compile_string(data, source_path, is_two_file)

def compile(self, source, dest, is_two_file=False, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
Expand All @@ -102,7 +102,7 @@ def compile(self, source, dest, is_two_file=False, post=None, lang=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()
output, error_level, deps = self.compile_html_string(data, source, is_two_file)
output, error_level, deps = self.compile_string(data, source, is_two_file)
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(post=post))
out_file.write(output)
if post is None:
Expand Down Expand Up @@ -280,7 +280,7 @@ def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
# specify here.
# logger a logger from Nikola
# source source filename (docutils gets a string)
# add_ln amount of metadata lines (see comment in compile_html above)
# add_ln amount of metadata lines (see comment in CompileRest.compile above)
reader.l_settings = {'logger': logger, 'source': source_path,
'add_ln': l_add_ln}

Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/task/listings.py
Expand Up @@ -116,7 +116,7 @@ def render_listing(in_name, out_name, input_folder, output_folder, folders=[], f
if in_name and in_name.endswith('.ipynb'):
# Special handling: render ipynbs in listings (Issue #1900)
ipynb_compiler = self.site.plugin_manager.getPluginByName("ipynb", "PageCompiler").plugin_object
ipynb_raw = ipynb_compiler.compile_html_string(in_name, True)
ipynb_raw = ipynb_compiler.compile_string(in_name, True)
ipynb_html = lxml.html.fromstring(ipynb_raw)
# The raw HTML contains garbage (scripts and styles), we can’t leave it in
code = lxml.html.tostring(ipynb_html.xpath('//*[@id="notebook"]')[0], encoding='unicode')
Expand Down
10 changes: 3 additions & 7 deletions tests/test_compile_markdown.py
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
import sys


import io
import shutil
import tempfile
Expand All @@ -28,7 +24,7 @@ def compile(self, input_string):
with io.open(self.input_path, "w+", encoding="utf8") as input_file:
input_file.write(input_string)

self.compiler.compile_html(self.input_path, self.output_path)
self.compiler.compile(self.input_path, self.output_path)

output_str = None
with io.open(self.output_path, "r", encoding="utf8") as output_path:
Expand All @@ -39,12 +35,12 @@ def compile(self, input_string):
def tearDown(self):
shutil.rmtree(self.tmp_dir)

def test_compile_html_empty(self):
def test_compile_empty(self):
input_str = ''
actual_output = self.compile(input_str)
self.assertEquals(actual_output, '')

def test_compile_html_code_hilite(self):
def test_compile_code_hilite(self):
input_str = '''\
#!python
from this
Expand Down
1 change: 1 addition & 0 deletions tests/test_rss_feeds.py
Expand Up @@ -32,6 +32,7 @@
class FakeCompiler(object):
demote_headers = False
compile_html = None
compile = None
extension = lambda self: '.html'
name = "fake"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_rst_compiler.py
Expand Up @@ -76,7 +76,7 @@ def setHtmlFromRst(self, rst):
p = FakePost('', '')
p._depfile[outf] = []
self.compiler.site.post_per_input_file[inf] = p
self.html = self.compiler.compile_html(inf, outf)
self.html = self.compiler.compile(inf, outf)
with io.open(outf, 'r', encoding='utf8') as f:
self.html = f.read()
os.unlink(inf)
Expand Down

0 comments on commit 7dfc111

Please sign in to comment.