@@ -1,6 +1,6 @@ | |||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
""" | """ | ||||
Autoextend css plugin | |||||
Autoextend plugin | |||||
""" | """ | ||||
from hyde.plugin import Plugin | from hyde.plugin import Plugin | ||||
@@ -8,7 +8,7 @@ import re | |||||
class AutoExtendPlugin(Plugin): | class AutoExtendPlugin(Plugin): | ||||
""" | """ | ||||
The plugin class for less css | |||||
The plugin class for extending templates using metadata. | |||||
""" | """ | ||||
def __init__(self, site): | def __init__(self, site): | ||||
@@ -8,7 +8,7 @@ from hyde.fs import Folder | |||||
class FlattenerPlugin(Plugin): | class FlattenerPlugin(Plugin): | ||||
""" | """ | ||||
The plugin class for syntax text replacement. | |||||
The plugin class for flattening nested folders. | |||||
""" | """ | ||||
def __init__(self, site): | def __init__(self, site): | ||||
super(FlattenerPlugin, self).__init__(site) | super(FlattenerPlugin, self).__init__(site) | ||||
@@ -384,6 +384,7 @@ class Jinja2Template(Template): | |||||
self.env.globals['media_url'] = media_url | self.env.globals['media_url'] = media_url | ||||
self.env.globals['content_url'] = content_url | self.env.globals['content_url'] = content_url | ||||
self.env.globals['engine'] = engine | self.env.globals['engine'] = engine | ||||
self.env.globals['deps'] = {} | |||||
self.env.filters['markdown'] = markdown | self.env.filters['markdown'] = markdown | ||||
self.env.filters['syntax'] = syntax | self.env.filters['syntax'] = syntax | ||||
@@ -411,10 +412,10 @@ class Jinja2Template(Template): | |||||
from jinja2.meta import find_referenced_templates | from jinja2.meta import find_referenced_templates | ||||
ast = self.env.parse(text) | ast = self.env.parse(text) | ||||
tpls = find_referenced_templates(ast) | tpls = find_referenced_templates(ast) | ||||
deps = [] | |||||
deps = list(self.env.globals['deps'].get('path', [])) | |||||
for dep in tpls: | for dep in tpls: | ||||
deps.append(dep) | |||||
if dep: | if dep: | ||||
deps.append(dep) | |||||
deps.extend(self.get_dependencies(dep)) | deps.extend(self.get_dependencies(dep)) | ||||
return list(set(deps)) | return list(set(deps)) | ||||
@@ -25,8 +25,8 @@ class Generator(object): | |||||
self.generated_once = False | self.generated_once = False | ||||
self.__context__ = dict(site=site) | self.__context__ = dict(site=site) | ||||
if hasattr(site.config, 'context'): | if hasattr(site.config, 'context'): | ||||
self.__context__.update( | |||||
Context.load(site.sitepath, site.config.context)) | |||||
site.context = Context.load(site.sitepath, site.config.context) | |||||
self.__context__.update(site.context) | |||||
self.template = None | self.template = None | ||||
Plugin.load_all(site) | Plugin.load_all(site) | ||||
@@ -108,6 +108,12 @@ class Generator(object): | |||||
logger.info("Generation Complete") | logger.info("Generation Complete") | ||||
self.events.generation_complete() | self.events.generation_complete() | ||||
def get_dependencies(self, resource): | |||||
""" | |||||
Gets the dependencies for a given resource. | |||||
""" | |||||
return self.template.get_dependencies(resource.relative_path) | |||||
def has_resource_changed(self, resource): | def has_resource_changed(self, resource): | ||||
""" | """ | ||||
Checks if the given resource has changed since the | Checks if the given resource has changed since the | ||||
@@ -126,7 +132,7 @@ class Generator(object): | |||||
if resource.source_file.is_binary or not resource.uses_template: | if resource.source_file.is_binary or not resource.uses_template: | ||||
logger.debug("No Changes found in %s" % resource) | logger.debug("No Changes found in %s" % resource) | ||||
return False | return False | ||||
deps = self.template.get_dependencies(resource.relative_path) | |||||
deps = self.get_dependencies(resource) | |||||
if not deps or None in deps: | if not deps or None in deps: | ||||
logger.debug("No changes found in %s" % resource) | logger.debug("No changes found in %s" % resource) | ||||
return False | return False | ||||
@@ -134,6 +140,8 @@ class Generator(object): | |||||
layout = Folder(self.site.sitepath).child_folder('layout') | layout = Folder(self.site.sitepath).child_folder('layout') | ||||
logger.debug("Checking for changes in dependents:%s" % deps) | logger.debug("Checking for changes in dependents:%s" % deps) | ||||
for dep in deps: | for dep in deps: | ||||
if not dep: | |||||
return True | |||||
source = File(content.child(dep)) | source = File(content.child(dep)) | ||||
if not source.exists: | if not source.exists: | ||||
source = File(layout.child(dep)) | source = File(layout.child(dep)) | ||||
@@ -348,6 +348,7 @@ class Site(object): | |||||
self.config = config if config else Config(self.sitepath) | self.config = config if config else Config(self.sitepath) | ||||
self.content = RootNode(self.config.content_root_path, self) | self.content = RootNode(self.config.content_root_path, self) | ||||
self.plugins = [] | self.plugins = [] | ||||
self.context = {} | |||||
def load(self): | def load(self): | ||||
""" | """ | ||||
@@ -171,6 +171,39 @@ class TestJinjaTemplate(object): | |||||
assert 'layout.html' in deps | assert 'layout.html' in deps | ||||
assert 'index.html' in deps | assert 'index.html' in deps | ||||
def test_depends_with_reference_tag(self): | |||||
site = Site(TEST_SITE) | |||||
JINJA2.copy_contents_to(site.content.source) | |||||
inc = File(TEST_SITE.child('content/inc.md')) | |||||
inc.write("{% refer to 'index.html' as index%}") | |||||
site.load() | |||||
gen = Generator(site) | |||||
gen.load_template_if_needed() | |||||
t = gen.template | |||||
deps = list(t.get_dependencies('inc.md')) | |||||
assert len(deps) == 3 | |||||
assert 'helpers.html' in deps | |||||
assert 'layout.html' in deps | |||||
assert 'index.html' in deps | |||||
def test_cant_find_depends_with_reference_tag_var(self): | |||||
site = Site(TEST_SITE) | |||||
JINJA2.copy_contents_to(site.content.source) | |||||
inc = File(TEST_SITE.child('content/inc.md')) | |||||
inc.write("{% set ind = 'index.html' %}{% refer to ind as index %}") | |||||
site.load() | |||||
gen = Generator(site) | |||||
gen.load_template_if_needed() | |||||
t = gen.template | |||||
deps = list(t.get_dependencies('inc.md')) | |||||
assert len(deps) == 1 | |||||
assert not deps[0] | |||||
def test_can_include_templates_with_processing(self): | def test_can_include_templates_with_processing(self): | ||||
text = """ | text = """ | ||||
=== | === | ||||
@@ -276,6 +309,34 @@ Hyde & Jinja. | |||||
text2 = """ | text2 = """ | ||||
{% refer to "inc.md" as inc %} | {% refer to "inc.md" as inc %} | ||||
{{ inc.html('.fulltext') }} | {{ inc.html('.fulltext') }} | ||||
""" | |||||
html = assert_markdown_typogrify_processed_well(text, text2) | |||||
assert "mark" not in html | |||||
assert "reference" not in html | |||||
def test_refer_with_var(self): | |||||
text = """ | |||||
=== | |||||
is_processable: False | |||||
=== | |||||
<div class="fulltext"> | |||||
{% filter markdown|typogrify %} | |||||
{% mark heading %} | |||||
This is a heading | |||||
================= | |||||
{% endmark %} | |||||
{% reference content %} | |||||
Hyde & Jinja. | |||||
{% endreference %} | |||||
{% endfilter %} | |||||
</div> | |||||
""" | |||||
text2 = """ | |||||
{% set incu = 'inc.md' %} | |||||
{% refer to incu as inc %} | |||||
{{ inc.html('.fulltext') }} | |||||
""" | """ | ||||
html = assert_markdown_typogrify_processed_well(text, text2) | html = assert_markdown_typogrify_processed_well(text, text2) | ||||
assert "mark" not in html | assert "mark" not in html |