Skip to content
Permalink
Browse files

Merge pull request #1863 from getnikola/unifying-compiler-extensions

Unifying compiler extensions
  • Loading branch information
Kwpolska committed Jul 5, 2015
2 parents 9ec5d99 + c9e6d8c commit 0aa310c9e29c8291935d1e518b37d67a3429bfbc
@@ -61,8 +61,8 @@
LateTask,
PageCompiler,
CompilerExtension,
RestExtension,
MarkdownExtension,
RestExtension,
Task,
TaskMultiplier,
TemplateSystem,
@@ -671,8 +671,8 @@ def __init__(self, **config):
"PageCompiler": PageCompiler,
"TaskMultiplier": TaskMultiplier,
"CompilerExtension": CompilerExtension,
"RestExtension": RestExtension,
"MarkdownExtension": MarkdownExtension,
"RestExtension": RestExtension,
"SignalHandler": SignalHandler,
"ConfigPlugin": ConfigPlugin,
"PostScanner": PostScanner,
@@ -731,6 +731,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)
@@ -831,6 +832,7 @@ def __init__(self, **config):

def _activate_plugins_of_category(self, category):
"""Activate all the plugins of a given category and return them."""
# this code duplicated in tests/base.py
plugins = []
for plugin_info in self.plugin_manager.getPluginsOfCategory(category):
if plugin_info.name in self.config.get('DISABLED_PLUGINS'):
@@ -283,6 +283,14 @@ def split_metadata(self, data):
# ['metadata', '\n\n', 'post content']
return split_result[0], split_result[-1]

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


class CompilerExtension(BasePlugin):

@@ -53,19 +53,14 @@ class CompileMarkdown(PageCompiler):
site = None

def set_site(self, site):
super(CompileMarkdown, self).set_site(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 self.get_compiler_extensions():
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

self.config_dependencies.append(str(sorted(site.config.get("MARKDOWN_EXTENSIONS"))))
return super(CompileMarkdown, self).set_site(site)

def compile_html(self, source, dest, is_two_file=True):
if markdown is None:
@@ -127,23 +127,16 @@ def create_post(self, path, **kw):
fd.write(content)

def set_site(self, site):
super(CompileRest, self).set_site(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 self.get_compiler_extensions():
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)
if not site.debug:
self.logger.level = 4

return super(CompileRest, self).set_site(site)


def get_observer(settings):
"""Return an observer for the docutils Reporter."""
@@ -30,8 +30,9 @@
TemplateSystem,
PageCompiler,
TaskMultiplier,
RestExtension,
MarkdownExtension
CompilerExtension,
MarkdownExtension,
RestExtension
)


@@ -213,8 +214,9 @@ def __init__(self):
"TemplateSystem": TemplateSystem,
"PageCompiler": PageCompiler,
"TaskMultiplier": TaskMultiplier,
"RestExtension": RestExtension,
"CompilerExtension": CompilerExtension,
"MarkdownExtension": MarkdownExtension,
"RestExtension": RestExtension
})
self.loghandlers = [nikola.utils.STDERR_HANDLER]
self.plugin_manager.setPluginInfoExtension('plugin')
@@ -228,6 +230,7 @@ def __init__(self):
]
self.plugin_manager.setPluginPlaces(places)
self.plugin_manager.collectPlugins()
self.compiler_extensions = self._activate_plugins_of_category("CompilerExtension")

self.timeline = [
FakePost(title='Fake post',
@@ -239,5 +242,18 @@ def __init__(self):
self.template_system = self
self.name = 'mako'

def _activate_plugins_of_category(self, category):
"""Activate all the plugins of a given category and return them."""
# this code duplicated in nikola/nikola.py
plugins = []
for plugin_info in self.plugin_manager.getPluginsOfCategory(category):
if plugin_info.name in self.config.get('DISABLED_PLUGINS'):
self.plugin_manager.removePluginFromCategory(plugin_info, category)
else:
self.plugin_manager.activatePluginByName(plugin_info.name)
plugin_info.plugin_object.set_site(self)
plugins.append(plugin_info)
return plugins

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

0 comments on commit 0aa310c

Please sign in to comment.
You can’t perform that action at this time.