Browse Source

Context providers now accept all valid yaml data (Issue #189).

- Also, fixed `raise_exceptions` commandline parameter handling.
main
Lakshmi Vyasarajan 11 years ago
parent
commit
73c0d75013
6 changed files with 41 additions and 27 deletions
  1. +8
    -0
      CHANGELOG.rst
  2. +1
    -1
      README.rst
  3. +3
    -2
      hyde/engine.py
  4. +24
    -18
      hyde/model.py
  5. +4
    -5
      hyde/tests/test_generate.py
  6. +1
    -1
      hyde/version.py

+ 8
- 0
CHANGELOG.rst View File

@@ -1,3 +1,11 @@
Version 0.8.7a7
============================================================

* Context providers now accept all valid yaml data (Issue #189).
* Fixed `raise_exceptions` commandline parameter handling.



Version 0.8.7a6
============================================================



+ 1
- 1
README.rst View File

@@ -1,4 +1,4 @@
Version 0.8.7a6
Version 0.8.7a7

A brand new **hyde**
====================


+ 3
- 2
hyde/engine.py View File

@@ -34,7 +34,7 @@ class Engine(Application):
@command(description='hyde - a python static website generator',
epilog='Use %(prog)s {command} -h to get help on individual commands')
@true('-v', '--verbose', help="Show detailed information in console")
@true('-x', '--raise-exceptions', default=False,
@true('-x', '--raise-exceptions', default=None,
help="Don't handle exceptions.")
@version('--version', version='%(prog)s ' + __version__)
@store('-s', '--sitepath', default='.', help="Location of the hyde site")
@@ -45,7 +45,8 @@ class Engine(Application):
like version and metadata
"""
sitepath = Folder(args.sitepath).fully_expanded_path
self.raise_exceptions = args.raise_exceptions
if args.raise_exceptions in (True, False):
self.raise_exceptions = args.raise_exceptions
return Folder(sitepath)

@subcommand('create', help='Create a new hyde site.')


+ 24
- 18
hyde/model.py View File

@@ -12,6 +12,22 @@ from fswrap import File, Folder

logger = getLoggerWithNullHandler('hyde.engine')

SEQS = (tuple, list, set, frozenset)

def make_expando(primitive):
"""
Creates an expando object, a sequence of expando objects or just
returns the primitive based on the primitive's type.
"""
if isinstance(primitive, dict):
return Expando(primitive)
elif isinstance(primitive, SEQS):
seq = type(primitive)
return seq(make_expando(attr) for attr in primitive)
else:
return primitive


class Expando(object):
"""
A generic expando class that creates attributes from
@@ -45,21 +61,8 @@ class Expando(object):
Sets the expando attribute after
transforming the value.
"""
setattr(self, unicode(key).encode('utf-8'), self._transform(value))

setattr(self, unicode(key).encode('utf-8'), make_expando(value))

def _transform(self, primitive):
"""
Creates an expando object, a sequence of expando objects or just
returns the primitive based on the primitive's type.
"""
if isinstance(primitive, dict):
return Expando(primitive)
elif isinstance(primitive, (tuple, list, set, frozenset)):
seq = type(primitive)
return seq(self._transform(attr) for attr in primitive)
else:
return primitive

def __repr__(self):
return unicode(self.to_dict())
@@ -73,10 +76,12 @@ class Expando(object):
for k, v in d.items():
if isinstance(v, Expando):
result[k] = v.to_dict()
elif isinstance(v, (tuple, list, set, frozenset)):
elif isinstance(v, SEQS):
seq = type(v)
result[k] = seq(item.to_dict() if isinstance(item, Expando)
else item for item in v)
result[k] = seq(item.to_dict()
if isinstance(item, Expando)
else item for item in v
)
else:
result[k] = v
return result
@@ -115,7 +120,8 @@ class Context(object):
for provider_name, resource_name in providers.items():
res = File(Folder(sitepath).child(resource_name))
if res.exists:
context[provider_name] = Expando(yaml.load(res.read_all()))
data = make_expando(yaml.load(res.read_all()))
context[provider_name] = data

return context



+ 4
- 5
hyde/tests/test_generate.py View File

@@ -129,17 +129,16 @@ class TestGenerator(object):
}
}))
nav = """
main:
- home
- articles
- projects
- home
- articles
- projects
"""
text = """
{% extends "base.html" %}

{% block main %}
{{nav}}
{% for item in nav.main %}
{% for item in nav %}
{{item}}
{% endfor %}
abc = {{ abc }}


+ 1
- 1
hyde/version.py View File

@@ -2,4 +2,4 @@
"""
Handles hyde version.
"""
__version__ = '0.8.7a6'
__version__ = '0.8.7a7'

Loading…
Cancel
Save