| @@ -15,25 +15,30 @@ class BlockdownPlugin(Plugin): | |||||
| def __init__(self, site): | def __init__(self, site): | ||||
| super(BlockdownPlugin, self).__init__(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): | def template_loaded(self, template): | ||||
| self.template = template | self.template = template | ||||
| def begin_text_resource(self, resource, text): | def begin_text_resource(self, resource, text): | ||||
| """ | """ | ||||
| Replace =======////blockname\\\\=========== | |||||
| Replace open pattern (default:===[====]blockname[===========]) | |||||
| with | with | ||||
| {% block blockname %} or equivalent and | {% block blockname %} or equivalent and | ||||
| Replace =======\\\\blockname////=========== | |||||
| Replace close pattern (default===[====]/[blockname][===========]) | |||||
| with | with | ||||
| {% block blockname %} or equivalent | {% 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): | def blockdown_to_block(match, start_block=True): | ||||
| if not match.lastindex: | if not match.lastindex: | ||||
| return '' | return '' | ||||
| @@ -40,7 +40,8 @@ class MetaPlugin(Plugin): | |||||
| Metadata plugin for hyde. Loads meta data in the following order: | Metadata plugin for hyde. Loads meta data in the following order: | ||||
| 1. meta.yaml: files in any folder | 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: | Example: | ||||
| --- | --- | ||||
| abc: def | abc: def | ||||
| @@ -80,7 +81,7 @@ class MetaPlugin(Plugin): | |||||
| logger.info("Trying to load metadata from resource [%s]" % resource) | logger.info("Trying to load metadata from resource [%s]" % resource) | ||||
| yaml_finder = re.compile( | yaml_finder = re.compile( | ||||
| r"^\s*---\s*\n((?:.|\n)+?)\n\s*---\s*\n", | |||||
| r"^\s*(?:---|===)\s*\n((?:.|\n)+?)\n\s*(?:---|===)\s*\n", | |||||
| re.MULTILINE) | re.MULTILINE) | ||||
| match = re.match(yaml_finder, text) | match = re.match(yaml_finder, text) | ||||
| if not match: | if not match: | ||||
| @@ -63,8 +63,18 @@ class HydeRequestHandler(SimpleHTTPRequestHandler): | |||||
| path = result.path.lstrip('/') | path = result.path.lstrip('/') | ||||
| res = site.content.resource_from_relative_path(path) | res = site.content.resource_from_relative_path(path) | ||||
| if not res: | 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: | else: | ||||
| self.server.generate_resource(res) | self.server.generate_resource(res) | ||||
| new_path = site.config.deploy_root_path.child( | new_path = site.config.deploy_root_path.child( | ||||
| @@ -89,6 +99,7 @@ class HydeWebServer(HTTPServer): | |||||
| def __init__(self, site, address, port): | def __init__(self, site, address, port): | ||||
| self.site = site | self.site = site | ||||
| self.site.load() | self.site.load() | ||||
| self.exception_count = 0 | |||||
| self.generator = Generator(self.site) | self.generator = Generator(self.site) | ||||
| HTTPServer.__init__(self, (address, port), | HTTPServer.__init__(self, (address, port), | ||||
| @@ -106,9 +117,15 @@ class HydeWebServer(HTTPServer): | |||||
| logger.info('Regenerating the entire site') | logger.info('Regenerating the entire site') | ||||
| self.generator.generate_all() | self.generator.generate_all() | ||||
| except Exception, exception: | except Exception, exception: | ||||
| self.exception_count += 1 | |||||
| logger.error('Error occured when regenerating the site [%s]' | logger.error('Error occured when regenerating the site [%s]' | ||||
| % exception.message) | % exception.message) | ||||
| self.__reinit__() | |||||
| if self.exception_count > 1: | |||||
| self.shutdown() | |||||
| exit() | |||||
| else: | |||||
| self.__reinit__() | |||||
| def generate_resource(self, resource): | def generate_resource(self, resource): | ||||
| """ | """ | ||||
| @@ -33,9 +33,9 @@ class TestAutoExtend(object): | |||||
| --- | --- | ||||
| extends: base.html | extends: base.html | ||||
| --- | --- | ||||
| ===========================////title\\\\============================ | |||||
| =====title======== | |||||
| %s | %s | ||||
| ===========================\\\\title////============================""" | |||||
| ====/title========""" | |||||
| content = (templ.strip() % txt).strip() | content = (templ.strip() % txt).strip() | ||||
| bd = File(TEST_SITE.child('content/auto_extend.html')) | bd = File(TEST_SITE.child('content/auto_extend.html')) | ||||
| @@ -29,9 +29,9 @@ class TestBlockdown(object): | |||||
| txt ="This template tests to make sure blocks can be replaced with markdownish syntax." | txt ="This template tests to make sure blocks can be replaced with markdownish syntax." | ||||
| templ = """ | templ = """ | ||||
| {%% extends "base.html" %%} | {%% extends "base.html" %%} | ||||
| ===========================////title\\\\============================ | |||||
| =====title======== | |||||
| %s | %s | ||||
| ===========================\\\\title////============================""" | |||||
| ====/title========""" | |||||
| content = (templ.strip() % txt).strip() | content = (templ.strip() % txt).strip() | ||||
| bd = File(TEST_SITE.child('content/blockdown.html')) | bd = File(TEST_SITE.child('content/blockdown.html')) | ||||
| @@ -73,9 +73,9 @@ twitter: %(twitter)s | |||||
| 'author': 'Lakshmi Vyas', | 'author': 'Lakshmi Vyas', | ||||
| 'twitter': 'lakshmivyas'} | 'twitter': 'lakshmivyas'} | ||||
| text = """ | text = """ | ||||
| --- | |||||
| === | |||||
| title: Even nicer title | title: Even nicer title | ||||
| --- | |||||
| === | |||||
| {%% extends "base.html" %%} | {%% extends "base.html" %%} | ||||
| {%% block main %%} | {%% block main %%} | ||||