- Also, fixed `raise_exceptions` commandline parameter handling.main
@@ -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 | Version 0.8.7a6 | ||||
============================================================ | ============================================================ | ||||
@@ -1,4 +1,4 @@ | |||||
Version 0.8.7a6 | |||||
Version 0.8.7a7 | |||||
A brand new **hyde** | A brand new **hyde** | ||||
==================== | ==================== | ||||
@@ -34,7 +34,7 @@ class Engine(Application): | |||||
@command(description='hyde - a python static website generator', | @command(description='hyde - a python static website generator', | ||||
epilog='Use %(prog)s {command} -h to get help on individual commands') | epilog='Use %(prog)s {command} -h to get help on individual commands') | ||||
@true('-v', '--verbose', help="Show detailed information in console") | @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.") | help="Don't handle exceptions.") | ||||
@version('--version', version='%(prog)s ' + __version__) | @version('--version', version='%(prog)s ' + __version__) | ||||
@store('-s', '--sitepath', default='.', help="Location of the hyde site") | @store('-s', '--sitepath', default='.', help="Location of the hyde site") | ||||
@@ -45,7 +45,8 @@ class Engine(Application): | |||||
like version and metadata | like version and metadata | ||||
""" | """ | ||||
sitepath = Folder(args.sitepath).fully_expanded_path | 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) | return Folder(sitepath) | ||||
@subcommand('create', help='Create a new hyde site.') | @subcommand('create', help='Create a new hyde site.') | ||||
@@ -12,6 +12,22 @@ from fswrap import File, Folder | |||||
logger = getLoggerWithNullHandler('hyde.engine') | 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): | class Expando(object): | ||||
""" | """ | ||||
A generic expando class that creates attributes from | A generic expando class that creates attributes from | ||||
@@ -45,21 +61,8 @@ class Expando(object): | |||||
Sets the expando attribute after | Sets the expando attribute after | ||||
transforming the value. | 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): | def __repr__(self): | ||||
return unicode(self.to_dict()) | return unicode(self.to_dict()) | ||||
@@ -73,10 +76,12 @@ class Expando(object): | |||||
for k, v in d.items(): | for k, v in d.items(): | ||||
if isinstance(v, Expando): | if isinstance(v, Expando): | ||||
result[k] = v.to_dict() | result[k] = v.to_dict() | ||||
elif isinstance(v, (tuple, list, set, frozenset)): | |||||
elif isinstance(v, SEQS): | |||||
seq = type(v) | 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: | else: | ||||
result[k] = v | result[k] = v | ||||
return result | return result | ||||
@@ -115,7 +120,8 @@ class Context(object): | |||||
for provider_name, resource_name in providers.items(): | for provider_name, resource_name in providers.items(): | ||||
res = File(Folder(sitepath).child(resource_name)) | res = File(Folder(sitepath).child(resource_name)) | ||||
if res.exists: | 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 | return context | ||||
@@ -129,17 +129,16 @@ class TestGenerator(object): | |||||
} | } | ||||
})) | })) | ||||
nav = """ | nav = """ | ||||
main: | |||||
- home | |||||
- articles | |||||
- projects | |||||
- home | |||||
- articles | |||||
- projects | |||||
""" | """ | ||||
text = """ | text = """ | ||||
{% extends "base.html" %} | {% extends "base.html" %} | ||||
{% block main %} | {% block main %} | ||||
{{nav}} | {{nav}} | ||||
{% for item in nav.main %} | |||||
{% for item in nav %} | |||||
{{item}} | {{item}} | ||||
{% endfor %} | {% endfor %} | ||||
abc = {{ abc }} | abc = {{ abc }} | ||||
@@ -2,4 +2,4 @@ | |||||
""" | """ | ||||
Handles hyde version. | Handles hyde version. | ||||
""" | """ | ||||
__version__ = '0.8.7a6' | |||||
__version__ = '0.8.7a7' |