Browse Source

Add support for draft blog posts. (Issue #213)

`
main
Lakshmi Vyasarajan 11 years ago
parent
commit
3e1674cb92
5 changed files with 114 additions and 3 deletions
  1. +5
    -0
      CHANGELOG.rst
  2. +36
    -0
      hyde/ext/plugins/blog.py
  3. +1
    -2
      hyde/ext/templates/jinja.py
  4. +71
    -0
      hyde/tests/ext/test_drafts.py
  5. +1
    -1
      hyde/version.py

+ 5
- 0
CHANGELOG.rst View File

@@ -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)


+ 36
- 0
hyde/ext/plugins/blog.py View File

@@ -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'))

+ 1
- 2
hyde/ext/templates/jinja.py View File

@@ -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():


+ 71
- 0
hyde/tests/ext/test_drafts.py View File

@@ -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



+ 1
- 1
hyde/version.py View File

@@ -2,4 +2,4 @@
"""
Handles hyde version.
"""
__version__ = '0.8.7a1'
__version__ = '0.8.7a2'

Loading…
Cancel
Save