From 74fa2f419b0e04aa7edd9810bab9a9dfa2b8ed73 Mon Sep 17 00:00:00 2001 From: Chris Warrick Date: Fri, 14 Oct 2016 20:03:20 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#2531=20=E2=80=94=20pass=20post=20and=20l?= =?UTF-8?q?ang=20to=20compilers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.txt | 11 +++++++++++ nikola/plugin_categories.py | 10 +++++++++- nikola/post.py | 6 ++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 934cbcc3dc..52ead38c89 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,14 @@ +New in master +============= + +Bugfixes +-------- + +Features +-------- + +* Pass ``post`` object and ``lang`` to post compilers (Issue #2531) + New in v7.8.1 ============= diff --git a/nikola/plugin_categories.py b/nikola/plugin_categories.py index 4b4f9560e2..b5cb62ba80 100644 --- a/nikola/plugin_categories.py +++ b/nikola/plugin_categories.py @@ -275,8 +275,16 @@ def register_extra_dependencies(self, post): """Add dependency to post object to check .dep file.""" post.add_dependency(lambda: self._read_extra_deps(post), 'fragment') + def compile(self, source, dest, is_two_file=False, post=None, lang=None): + """Compile the source file and save it to dest.""" + # For backwards compatibility, call `compile_html` + # If you are implementing a compiler, please implement `compile` and + # ignore `compile_html` + self.compile_html(source, dest, is_two_file) + + # TODO remove in v8 def compile_html(self, source, dest, is_two_file=False): - """Compile the source, save it on dest.""" + """Compile the source, save it on dest. (DEPRECATED)""" raise NotImplementedError() def create_post(self, path, content=None, onefile=False, is_page=False, **kw): diff --git a/nikola/post.py b/nikola/post.py index 37e4241e2b..ff8374f998 100644 --- a/nikola/post.py +++ b/nikola/post.py @@ -97,7 +97,9 @@ def __init__( """ self.config = config self.compiler = compiler - self.compile_html = self.compiler.compile_html + self.compile = self.compiler.compile + # TODO remove in v8 + self.compile_html = self.compile self.demote_headers = self.compiler.demote_headers and self.config['DEMOTE_HEADERS'] tzinfo = self.config['__tzinfo__'] if self.config['FUTURE_IS_NOW']: @@ -516,7 +518,7 @@ def wrap_encrypt(path, password): return # Set the language to the right thing LocaleBorg().set_locale(lang) - self.compile_html( + self.compile( self.translated_source_path(lang), dest, self.is_two_file)