diff --git a/hyde/ext/plugins/auto_extend.py b/hyde/ext/plugins/auto_extend.py deleted file mode 100644 index 878baa8..0000000 --- a/hyde/ext/plugins/auto_extend.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Autoextend plugin -""" - -from hyde.plugin import Plugin -import re - -class AutoExtendPlugin(Plugin): - """ - The plugin class for extending templates using metadata. - """ - - def __init__(self, site): - super(AutoExtendPlugin, self).__init__(site) - - def begin_text_resource(self, resource, text): - """ - If the meta data for the resource contains a layout attribute, - and there is no extends statement, this plugin automatically adds - an extends statement to the top of the file. - """ - - if not resource.uses_template: - return text - - layout = None - block = None - try: - layout = resource.meta.extends - except AttributeError: - pass - - try: - block = resource.meta.default_block - except AttributeError: - pass - - if layout: - self.logger.debug("Autoextending %s with %s" % ( - resource.relative_path, layout)) - extends_pattern = self.template.patterns['extends'] - - if not re.search(extends_pattern, text): - extended_text = self.template.get_extends_statement(layout) - extended_text += '\n' - if block: - extended_text += ('%s\n%s\n%s' % - (self.t_block_open_tag(block), - text, - self.t_block_close_tag(block))) - else: - extended_text += text - return extended_text - return text \ No newline at end of file diff --git a/hyde/ext/plugins/meta.py b/hyde/ext/plugins/meta.py index c9c40bd..b09f782 100644 --- a/hyde/ext/plugins/meta.py +++ b/hyde/ext/plugins/meta.py @@ -142,3 +142,53 @@ class MetaPlugin(Plugin): has changed. Return text without meta data. """ return self.__read_resource__(resource, text) + + +class AutoExtendPlugin(Plugin): + """ + The plugin class for extending templates using metadata. + """ + + def __init__(self, site): + super(AutoExtendPlugin, self).__init__(site) + + def begin_text_resource(self, resource, text): + """ + If the meta data for the resource contains a layout attribute, + and there is no extends statement, this plugin automatically adds + an extends statement to the top of the file. + """ + + if not resource.uses_template: + return text + + layout = None + block = None + try: + layout = resource.meta.extends + except AttributeError: + pass + + try: + block = resource.meta.default_block + except AttributeError: + pass + + if layout: + self.logger.debug("Autoextending %s with %s" % ( + resource.relative_path, layout)) + extends_pattern = self.template.patterns['extends'] + + if not re.search(extends_pattern, text): + extended_text = self.template.get_extends_statement(layout) + extended_text += '\n' + if block: + extended_text += ('%s\n%s\n%s' % + (self.t_block_open_tag(block), + text, + self.t_block_close_tag(block))) + else: + extended_text += text + return extended_text + return text + diff --git a/hyde/layouts/basic/site.yaml b/hyde/layouts/basic/site.yaml index de90308..bdaa77e 100644 --- a/hyde/layouts/basic/site.yaml +++ b/hyde/layouts/basic/site.yaml @@ -4,7 +4,7 @@ media_url: /media # URL where the media files are served from. base_url: / # The base url for autogenerated links. plugins: - hyde.ext.plugins.meta.MetaPlugin - - hyde.ext.plugins.auto_extend.AutoExtendPlugin + - hyde.ext.plugins.meta.AutoExtendPlugin - hyde.ext.plugins.sorter.SorterPlugin - hyde.ext.plugins.tagger.TaggerPlugin - hyde.ext.plugins.syntext.SyntextPlugin @@ -58,4 +58,4 @@ tagger: template: tagged_posts.j2 archive_extension: html meta: - listable: false \ No newline at end of file + listable: false diff --git a/hyde/layouts/starter/site.yaml b/hyde/layouts/starter/site.yaml index 2557f6a..bb4845b 100644 --- a/hyde/layouts/starter/site.yaml +++ b/hyde/layouts/starter/site.yaml @@ -10,7 +10,7 @@ base_url: / template: hyde.ext.templates.jinja.Jinja2Template plugins: - hyde.ext.plugins.meta.MetaPlugin - - hyde.ext.plugins.auto_extend.AutoExtendPlugin + - hyde.ext.plugins.meta.AutoExtendPlugin # Plugins needed for the advances section. - hyde.ext.plugins.sorter.SorterPlugin - hyde.ext.plugins.grouper.GrouperPlugin diff --git a/hyde/tests/ext/test_auto_extend.py b/hyde/tests/ext/test_auto_extend.py index 1d63400..3e9be2b 100644 --- a/hyde/tests/ext/test_auto_extend.py +++ b/hyde/tests/ext/test_auto_extend.py @@ -42,7 +42,7 @@ class TestAutoExtend(object): def test_can_auto_extend(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin', - 'hyde.ext.plugins.auto_extend.AutoExtendPlugin', + 'hyde.ext.plugins.meta.AutoExtendPlugin', 'hyde.ext.plugins.text.BlockdownPlugin'] txt ="This template tests to make sure blocks can be replaced with markdownish syntax." templ = """ @@ -59,7 +59,7 @@ extends: base.html def test_can_auto_extend_with_default_blocks(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin', - 'hyde.ext.plugins.auto_extend.AutoExtendPlugin', + 'hyde.ext.plugins.meta.AutoExtendPlugin', 'hyde.ext.plugins.text.BlockdownPlugin'] txt ="This template tests to make sure blocks can be replaced with markdownish syntax." templ = """ diff --git a/hyde/tests/sites/test_sorter/site.yaml b/hyde/tests/sites/test_sorter/site.yaml index c037f33..c15e6a9 100644 --- a/hyde/tests/sites/test_sorter/site.yaml +++ b/hyde/tests/sites/test_sorter/site.yaml @@ -4,7 +4,7 @@ media_url: /media # URL where the media files are served from. base_url: / # The base url for autogenerated links. plugins: - hyde.ext.plugins.meta.MetaPlugin - - hyde.ext.plugins.auto_extend.AutoExtendPlugin + - hyde.ext.plugins.meta.AutoExtendPlugin - hyde.ext.plugins.sorter.SorterPlugin - hyde.ext.plugins.text.TextlinksPlugin meta: diff --git a/hyde/tests/sites/test_tagger/site.yaml b/hyde/tests/sites/test_tagger/site.yaml index 9b7ee78..c555348 100644 --- a/hyde/tests/sites/test_tagger/site.yaml +++ b/hyde/tests/sites/test_tagger/site.yaml @@ -4,7 +4,7 @@ media_url: /media # URL where the media files are served from. base_url: / # The base url for autogenerated links. plugins: - hyde.ext.plugins.meta.MetaPlugin - - hyde.ext.plugins.auto_extend.AutoExtendPlugin + - hyde.ext.plugins.meta.AutoExtendPlugin - hyde.ext.plugins.sorter.SorterPlugin - hyde.ext.plugins.tagger.TaggerPlugin - hyde.ext.plugins.text.TextlinksPlugin diff --git a/hyde/tests/ssp/site.yaml b/hyde/tests/ssp/site.yaml index 1416503..daf3d55 100644 --- a/hyde/tests/ssp/site.yaml +++ b/hyde/tests/ssp/site.yaml @@ -4,7 +4,7 @@ media_url: /media # URL where the media files are served from. base_url: / # The base url for autogenerated links. plugins: - hyde.ext.plugins.meta.MetaPlugin - - hyde.ext.plugins.auto_extend.AutoExtendPlugin + - hyde.ext.plugins.meta.AutoExtendPlugin - hyde.ext.plugins.sorter.SorterPlugin - hyde.ext.plugins.tagger.TaggerPlugin - hyde.ext.plugins.text.SyntextPlugin