| @@ -1,3 +1,8 @@ | |||||
| Version 0.8.7a2 | |||||
| ============================================================ | |||||
| * Add support for draft blog posts. (Issue #213) | |||||
| Version 0.8.7a1 | Version 0.8.7a1 | ||||
| ============================================================ | ============================================================ | ||||
| * Bugfix: Use `clearfix` class in `listing.j2`. (Issue #156) | * Bugfix: Use `clearfix` class in `listing.j2`. (Issue #156) | ||||
| @@ -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')) | |||||
| @@ -165,7 +165,6 @@ def restructuredtext(env, value): | |||||
| for extension in extensions: | for extension in extensions: | ||||
| imp.load_module(extension, *imp.find_module(extension)) | imp.load_module(extension, *imp.find_module(extension)) | ||||
| if highlight_source: | if highlight_source: | ||||
| import hyde.lib.pygments.rst_directive | import hyde.lib.pygments.rst_directive | ||||
| @@ -672,7 +671,7 @@ class Jinja2Template(Template): | |||||
| settings['extensions'].extend(extensions) | settings['extensions'].extend(extensions) | ||||
| else: | else: | ||||
| settings['extensions'].append(extensions) | settings['extensions'].append(extensions) | ||||
| filters = conf.get('filters', {}) | filters = conf.get('filters', {}) | ||||
| if isinstance(filters, dict): | if isinstance(filters, dict): | ||||
| for name, value in filters.items(): | for name, value in filters.items(): | ||||
| @@ -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 | |||||
| @@ -2,4 +2,4 @@ | |||||
| """ | """ | ||||
| Handles hyde version. | Handles hyde version. | ||||
| """ | """ | ||||
| __version__ = '0.8.7a1' | |||||
| __version__ = '0.8.7a2' | |||||