From 3e1674cb923eb14e3b8ddf92cf61faa2f9d8b1a9 Mon Sep 17 00:00:00 2001 From: Lakshmi Vyasarajan Date: Wed, 29 May 2013 09:08:19 +0530 Subject: [PATCH] Add support for draft blog posts. (Issue #213) ` --- CHANGELOG.rst | 5 +++ hyde/ext/plugins/blog.py | 36 ++++++++++++++++++ hyde/ext/templates/jinja.py | 3 +- hyde/tests/ext/test_drafts.py | 71 +++++++++++++++++++++++++++++++++++ hyde/version.py | 2 +- 5 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 hyde/ext/plugins/blog.py create mode 100644 hyde/tests/ext/test_drafts.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a5efd7c..4f149ec 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +Version 0.8.7a2 +============================================================ + +* Add support for draft blog posts. (Issue #213) + Version 0.8.7a1 ============================================================ * Bugfix: Use `clearfix` class in `listing.j2`. (Issue #156) diff --git a/hyde/ext/plugins/blog.py b/hyde/ext/plugins/blog.py new file mode 100644 index 0000000..a0fcc91 --- /dev/null +++ b/hyde/ext/plugins/blog.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +""" + +Plugins that are useful to blogs hosted with hyde. + +""" + +from hyde.plugin import Plugin + + +class DraftsPlugin(Plugin): + + + def begin_site(self): + + in_production = self.site.config.mode.startswith('prod') + if not in_production: + self.logger.info( + 'Generating draft posts as the site is not in production mode.') + return + + for resource in self.site.content.walk_resources(): + if not resource.is_processable: + continue + + try: + is_draft = resource.meta.is_draft + except AttributeError: + is_draft = False + + if is_draft: + resource.is_processable = False + + self.logger.info( + '%s is%s draft' % (resource, + '' if is_draft else ' not')) \ No newline at end of file diff --git a/hyde/ext/templates/jinja.py b/hyde/ext/templates/jinja.py index 30b187f..8ab5f6f 100644 --- a/hyde/ext/templates/jinja.py +++ b/hyde/ext/templates/jinja.py @@ -165,7 +165,6 @@ def restructuredtext(env, value): for extension in extensions: imp.load_module(extension, *imp.find_module(extension)) - if highlight_source: import hyde.lib.pygments.rst_directive @@ -672,7 +671,7 @@ class Jinja2Template(Template): settings['extensions'].extend(extensions) else: settings['extensions'].append(extensions) - + filters = conf.get('filters', {}) if isinstance(filters, dict): for name, value in filters.items(): diff --git a/hyde/tests/ext/test_drafts.py b/hyde/tests/ext/test_drafts.py new file mode 100644 index 0000000..c42459d --- /dev/null +++ b/hyde/tests/ext/test_drafts.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +""" +Use nose +`$ pip install nose` +`$ nosetests` +""" + +from hyde.generator import Generator +from hyde.site import Site +from hyde.model import Config + +from fswrap import File + +TEST_SITE = File(__file__).parent.parent.child_folder('_test') + +DRAFT_POST = """ + +--- +is_draft: true +--- + +A draft post. + +""" + +class TestDrafts(object): + + def setUp(self): + TEST_SITE.make() + TEST_SITE.parent.child_folder( + 'sites/test_jinja').copy_contents_to(TEST_SITE) + draft = TEST_SITE.child_file('content/blog/2013/may/draft-post.html') + draft.parent.make() + draft.write(DRAFT_POST) + + def tearDown(self): + TEST_SITE.delete() + + def test_drafts_are_skipped_in_production(self): + s = Site(TEST_SITE) + cfg = """ + mode: production + plugins: + - hyde.ext.plugins.meta.MetaPlugin + - hyde.ext.plugins.blog.DraftsPlugin + """ + import yaml + s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) + s.load() + gen = Generator(s) + gen.generate_all() + assert not s.config.deploy_root_path.child_file( + 'blog/2013/may/draft-post.html').exists + + def test_drafts_are_published_in_development(self): + s = Site(TEST_SITE) + cfg = """ + mode: development + plugins: + - hyde.ext.plugins.meta.MetaPlugin + - hyde.ext.plugins.blog.DraftsPlugin + """ + import yaml + s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) + s.load() + gen = Generator(s) + gen.generate_all() + assert s.config.deploy_root_path.child_file( + 'blog/2013/may/draft-post.html').exists + + diff --git a/hyde/version.py b/hyde/version.py index 1a6b12b..39346c6 100644 --- a/hyde/version.py +++ b/hyde/version.py @@ -2,4 +2,4 @@ """ Handles hyde version. """ -__version__ = '0.8.7a1' +__version__ = '0.8.7a2'