Skip to content
Permalink
Browse files
Unifying different compiler extension pluing initializations and prov…
…iding simple accessing functions for compiler extensions for a given page compiler.
  • Loading branch information
felixfontein committed Jul 4, 2015
1 parent e8ce9bb commit 2b191366788ceed711377a40c024cc2cc340323c
Showing with 16 additions and 21 deletions.
  1. +9 −4 nikola/nikola.py
  2. +1 −6 nikola/plugins/compile/markdown/__init__.py
  3. +1 −7 nikola/plugins/compile/rest/__init__.py
  4. +5 −4 tests/base.py
@@ -61,8 +61,6 @@
LateTask,
PageCompiler,
CompilerExtension,
RestExtension,
MarkdownExtension,
Task,
TaskMultiplier,
TemplateSystem,
@@ -670,8 +668,6 @@ def __init__(self, **config):
"PageCompiler": PageCompiler,
"TaskMultiplier": TaskMultiplier,
"CompilerExtension": CompilerExtension,
"RestExtension": RestExtension,
"MarkdownExtension": MarkdownExtension,
"SignalHandler": SignalHandler,
"ConfigPlugin": ConfigPlugin,
"PostScanner": PostScanner,
@@ -730,6 +726,7 @@ def __init__(self, **config):
self.config['COMPILERS'][k] = sorted(list(v))

# Activate all required compiler plugins
self.compiler_extensions = self._activate_plugins_of_category("CompilerExtension")
for plugin_info in self.plugin_manager.getPluginsOfCategory("PageCompiler"):
if plugin_info.name in self.config["COMPILERS"].keys():
self.plugin_manager.activatePluginByName(plugin_info.name)
@@ -840,6 +837,14 @@ def _activate_plugins_of_category(self, category):
plugins.append(plugin_info)
return plugins

def activate_compiler_extensions(self, compiler_name):
"""Activate all the compiler extension plugins for a given compiler and return them."""
plugins = []
for plugin_info in self.compiler_extensions:
if plugin_info.plugin_object.compiler_name == compiler_name:
plugins.append(plugin_info)
return plugins

def _get_themes(self):
if self._THEMES is None:
try:
@@ -54,13 +54,8 @@ class CompileMarkdown(PageCompiler):

def set_site(self, site):
self.config_dependencies = []
for plugin_info in site.plugin_manager.getPluginsOfCategory("MarkdownExtension"):
if plugin_info.name in site.config['DISABLED_PLUGINS']:
site.plugin_manager.removePluginFromCategory(plugin_info, "MarkdownExtension")
continue
for plugin_info in site.activate_compiler_extensions('markdown'):
self.config_dependencies.append(plugin_info.name)
site.plugin_manager.activatePluginByName(plugin_info.name)
plugin_info.plugin_object.set_site(site)
self.extensions.append(plugin_info.plugin_object)
plugin_info.plugin_object.short_help = plugin_info.description

@@ -128,14 +128,8 @@ def create_post(self, path, **kw):

def set_site(self, site):
self.config_dependencies = []
for plugin_info in site.plugin_manager.getPluginsOfCategory("RestExtension"):
if plugin_info.name in site.config['DISABLED_PLUGINS']:
site.plugin_manager.removePluginFromCategory(plugin_info, "RestExtension")
continue

site.plugin_manager.activatePluginByName(plugin_info.name)
for plugin_info in site.activate_compiler_extensions('rest'):
self.config_dependencies.append(plugin_info.name)
plugin_info.plugin_object.set_site(site)
plugin_info.plugin_object.short_help = plugin_info.description

self.logger = get_logger('compile_rest', site.loghandlers)
@@ -30,8 +30,7 @@
TemplateSystem,
PageCompiler,
TaskMultiplier,
RestExtension,
MarkdownExtension
CompilerExtension
)


@@ -213,8 +212,7 @@ def __init__(self):
"TemplateSystem": TemplateSystem,
"PageCompiler": PageCompiler,
"TaskMultiplier": TaskMultiplier,
"RestExtension": RestExtension,
"MarkdownExtension": MarkdownExtension,
"CompilerExtension": CompilerExtension
})
self.loghandlers = [nikola.utils.STDERR_HANDLER]
self.plugin_manager.setPluginInfoExtension('plugin')
@@ -239,5 +237,8 @@ def __init__(self):
self.template_system = self
self.name = 'mako'

def activate_compiler_extensions(self, compiler_name):
return []

def render_template(self, name, _, context):
return('<img src="IMG.jpg">')

0 comments on commit 2b19136

Please sign in to comment.