diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a423906..4dfe25f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ============================================================ diff --git a/README.rst b/README.rst index 91d4dda..fbb4fda 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Version 0.8.7a6 +Version 0.8.7a7 A brand new **hyde** ==================== diff --git a/hyde/engine.py b/hyde/engine.py index 4df557b..7f545e5 100644 --- a/hyde/engine.py +++ b/hyde/engine.py @@ -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.') diff --git a/hyde/model.py b/hyde/model.py index 3cda7b4..d8b15d0 100644 --- a/hyde/model.py +++ b/hyde/model.py @@ -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 diff --git a/hyde/tests/test_generate.py b/hyde/tests/test_generate.py index d2e43c9..8249e06 100644 --- a/hyde/tests/test_generate.py +++ b/hyde/tests/test_generate.py @@ -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 }} diff --git a/hyde/version.py b/hyde/version.py index 936b816..25a1f50 100644 --- a/hyde/version.py +++ b/hyde/version.py @@ -2,4 +2,4 @@ """ Handles hyde version. """ -__version__ = '0.8.7a6' +__version__ = '0.8.7a7'