From a497bde93731f5cc5dd3c54675ee63b16e53e338 Mon Sep 17 00:00:00 2001 From: Lakshmi Vyasarajan Date: Thu, 6 Jan 2011 14:21:46 +0530 Subject: [PATCH] Fixed syntax for meta and blockdown tags --- hyde/ext/plugins/blockdown.py | 21 +++++++++++++-------- hyde/ext/plugins/meta.py | 5 +++-- hyde/server.py | 23 ++++++++++++++++++++--- hyde/tests/ext/test_auto_extend.py | 4 ++-- hyde/tests/ext/test_blockdown.py | 4 ++-- hyde/tests/ext/test_meta.py | 4 ++-- 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/hyde/ext/plugins/blockdown.py b/hyde/ext/plugins/blockdown.py index 80c1889..66b9c42 100644 --- a/hyde/ext/plugins/blockdown.py +++ b/hyde/ext/plugins/blockdown.py @@ -15,25 +15,30 @@ class BlockdownPlugin(Plugin): def __init__(self, site): super(BlockdownPlugin, self).__init__(site) + try: + self.open_pattern = site.config.blockdown.open_pattern + except AttributeError: + self.open_pattern = '^\s*===+\s*([A-Za-z0-9_\-.]+)\s*=*\s*$' + + try: + self.close_pattern = site.config.blockdown.close_pattern + except AttributeError: + self.close_pattern = '^\s*===+\s*/+\s*=*/*([A-Za-z0-9_\-.]*)[\s=/]*$' def template_loaded(self, template): self.template = template def begin_text_resource(self, resource, text): """ - Replace =======////blockname\\\\=========== + Replace open pattern (default:===[====]blockname[===========]) with {% block blockname %} or equivalent and - Replace =======\\\\blockname////=========== + Replace close pattern (default===[====]/[blockname][===========]) with {% block blockname %} or equivalent """ - blocktag_open = re.compile( - '^\s*=+/+\s*([A-Za-z0-9_\-.]+)\s*\\\\+=+$', - re.MULTILINE) - blocktag_close = re.compile( - '^\s*=+\\\\+\s*([A-Za-z0-9_\-.]+)\s*/+=+$', - re.MULTILINE) + blocktag_open = re.compile(self.open_pattern, re.MULTILINE) + blocktag_close = re.compile(self.close_pattern, re.MULTILINE) def blockdown_to_block(match, start_block=True): if not match.lastindex: return '' diff --git a/hyde/ext/plugins/meta.py b/hyde/ext/plugins/meta.py index 2433b1c..760df43 100644 --- a/hyde/ext/plugins/meta.py +++ b/hyde/ext/plugins/meta.py @@ -40,7 +40,8 @@ class MetaPlugin(Plugin): Metadata plugin for hyde. Loads meta data in the following order: 1. meta.yaml: files in any folder - 2. frontmatter: any text file with content enclosed within three dashes. + 2. frontmatter: any text file with content enclosed within three dashes + or three equals signs. Example: --- abc: def @@ -80,7 +81,7 @@ class MetaPlugin(Plugin): logger.info("Trying to load metadata from resource [%s]" % resource) yaml_finder = re.compile( - r"^\s*---\s*\n((?:.|\n)+?)\n\s*---\s*\n", + r"^\s*(?:---|===)\s*\n((?:.|\n)+?)\n\s*(?:---|===)\s*\n", re.MULTILINE) match = re.match(yaml_finder, text) if not match: diff --git a/hyde/server.py b/hyde/server.py index 96a98f6..d46d94e 100644 --- a/hyde/server.py +++ b/hyde/server.py @@ -63,8 +63,18 @@ class HydeRequestHandler(SimpleHTTPRequestHandler): path = result.path.lstrip('/') res = site.content.resource_from_relative_path(path) if not res: - logger.info("Cannot load file:[%s]" % path) - raise Exception("Cannot load file: [%s]" % path) + # Cannot find the source file using the given path. + # Check if the target file exists in the deploy folder. + deployed = File(site.config.deploy_root_path.child(path)) + if deployed.exists: + # this file is probably being generated by a plugin. + # lets not try too hard, just regenerate + self.server.regenerate() + return deployed.path + else: + logger.info("Cannot load file:[%s]" % path) + raise Exception("Cannot load file: [%s]" % path) + else: self.server.generate_resource(res) new_path = site.config.deploy_root_path.child( @@ -89,6 +99,7 @@ class HydeWebServer(HTTPServer): def __init__(self, site, address, port): self.site = site self.site.load() + self.exception_count = 0 self.generator = Generator(self.site) HTTPServer.__init__(self, (address, port), @@ -106,9 +117,15 @@ class HydeWebServer(HTTPServer): logger.info('Regenerating the entire site') self.generator.generate_all() except Exception, exception: + self.exception_count += 1 logger.error('Error occured when regenerating the site [%s]' % exception.message) - self.__reinit__() + if self.exception_count > 1: + self.shutdown() + exit() + else: + self.__reinit__() + def generate_resource(self, resource): """ diff --git a/hyde/tests/ext/test_auto_extend.py b/hyde/tests/ext/test_auto_extend.py index eb352ab..e845606 100644 --- a/hyde/tests/ext/test_auto_extend.py +++ b/hyde/tests/ext/test_auto_extend.py @@ -33,9 +33,9 @@ class TestAutoExtend(object): --- extends: base.html --- -===========================////title\\\\============================ +=====title======== %s -===========================\\\\title////============================""" +====/title========""" content = (templ.strip() % txt).strip() bd = File(TEST_SITE.child('content/auto_extend.html')) diff --git a/hyde/tests/ext/test_blockdown.py b/hyde/tests/ext/test_blockdown.py index fa700e9..c3ecba8 100644 --- a/hyde/tests/ext/test_blockdown.py +++ b/hyde/tests/ext/test_blockdown.py @@ -29,9 +29,9 @@ class TestBlockdown(object): txt ="This template tests to make sure blocks can be replaced with markdownish syntax." templ = """ {%% extends "base.html" %%} -===========================////title\\\\============================ +=====title======== %s -===========================\\\\title////============================""" +====/title========""" content = (templ.strip() % txt).strip() bd = File(TEST_SITE.child('content/blockdown.html')) diff --git a/hyde/tests/ext/test_meta.py b/hyde/tests/ext/test_meta.py index 791ac27..171bbb3 100644 --- a/hyde/tests/ext/test_meta.py +++ b/hyde/tests/ext/test_meta.py @@ -73,9 +73,9 @@ twitter: %(twitter)s 'author': 'Lakshmi Vyas', 'twitter': 'lakshmivyas'} text = """ ---- +=== title: Even nicer title ---- +=== {%% extends "base.html" %%} {%% block main %%}