Browse Source

Fixed syntax for meta and blockdown tags

main
Lakshmi Vyasarajan 14 years ago
parent
commit
a497bde937
6 changed files with 42 additions and 19 deletions
  1. +13
    -8
      hyde/ext/plugins/blockdown.py
  2. +3
    -2
      hyde/ext/plugins/meta.py
  3. +20
    -3
      hyde/server.py
  4. +2
    -2
      hyde/tests/ext/test_auto_extend.py
  5. +2
    -2
      hyde/tests/ext/test_blockdown.py
  6. +2
    -2
      hyde/tests/ext/test_meta.py

+ 13
- 8
hyde/ext/plugins/blockdown.py View File

@@ -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 ''


+ 3
- 2
hyde/ext/plugins/meta.py View File

@@ -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:


+ 20
- 3
hyde/server.py View File

@@ -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):
"""


+ 2
- 2
hyde/tests/ext/test_auto_extend.py View File

@@ -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'))


+ 2
- 2
hyde/tests/ext/test_blockdown.py View File

@@ -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'))


+ 2
- 2
hyde/tests/ext/test_meta.py View File

@@ -73,9 +73,9 @@ twitter: %(twitter)s
'author': 'Lakshmi Vyas',
'twitter': 'lakshmivyas'}
text = """
---
===
title: Even nicer title
---
===
{%% extends "base.html" %%}

{%% block main %%}


Loading…
Cancel
Save