diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0d3cc02..2828d35 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +Version 0.8.5a11 +============================================================ + +* Bug Fix: Folder Flattener updates node's `relative_deploy_path` & `url` attributes as well. (Issue #126) +* BREAKING: As part of the above fix, `resource.url` is prefixed with a `/`. (Issue #126) + Version 0.8.5a10 ============================================================ diff --git a/README.rst b/README.rst index 16091c3..8af495d 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Version 0.8.5a10 +Version 0.8.5a11 A brand new **hyde** ==================== diff --git a/hyde/ext/plugins/folders.py b/hyde/ext/plugins/folders.py index 40bd6f0..6a25add 100644 --- a/hyde/ext/plugins/folders.py +++ b/hyde/ext/plugins/folders.py @@ -39,5 +39,6 @@ class FlattenerPlugin(Plugin): 'Flattening resource path [%s] to [%s]' % (resource, target_path)) resource.relative_deploy_path = target_path - + for child in node.walk(): + child.relative_deploy_path = target.path diff --git a/hyde/site.py b/hyde/site.py index 69feb8e..be17521 100644 --- a/hyde/site.py +++ b/hyde/site.py @@ -33,6 +33,7 @@ class Processable(object): self.source = FS.file_or_folder(source) self.is_processable = True self.uses_template = True + self._relative_deploy_path = None @property def name(self): @@ -50,6 +51,40 @@ class Processable(object): Gets the source path of this node. """ return self.source.path + + def get_relative_deploy_path(self): + """ + Gets the path where the file will be created + after its been processed. + """ + return self._relative_deploy_path \ + if self._relative_deploy_path is not None \ + else self.relative_path + + def set_relative_deploy_path(self, path): + """ + Sets the path where the file ought to be created + after its been processed. + """ + self._relative_deploy_path = path + self.site.content.deploy_path_changed(self) + + relative_deploy_path = property(get_relative_deploy_path, set_relative_deploy_path) + + @property + def url(self): + """ + Returns the relative url for the processable + """ + return '/' + self.relative_deploy_path + + @property + def full_url(self): + """ + Returns the full url for the processable. + """ + return self.site.full_url(self.relative_deploy_path) + class Resource(Processable): """ @@ -66,7 +101,6 @@ class Resource(Processable): " to instantiate a resource") self.node = node self.site = node.site - self._relative_deploy_path = None self.simple_copy = False @property @@ -75,39 +109,12 @@ class Resource(Processable): Gets the path relative to the root folder (Content) """ return self.source_file.get_relative_path(self.node.root.source_folder) - + @property def slug(self): #TODO: Add a more sophisticated slugify method return self.source.name_without_extension - def get_relative_deploy_path(self): - """ - Gets the path where the file will be created - after its been processed. - """ - return self._relative_deploy_path \ - if self._relative_deploy_path \ - else self.relative_path - - def set_relative_deploy_path(self, path): - """ - Sets the path where the file ought to be created - after its been processed. - """ - self._relative_deploy_path = path - self.site.content.resource_deploy_path_changed(self) - - relative_deploy_path = property(get_relative_deploy_path, set_relative_deploy_path) - url = relative_deploy_path - - @property - def full_url(self): - """ - Returns the full url for the resource. - """ - return self.site.full_url(self.relative_path) - class Node(Processable): """ Represents any folder that is processed by hyde @@ -200,14 +207,6 @@ class Node(Processable): """ return self.source_folder.get_relative_path(self.root.source_folder) - @property - def url(self): - return '/' + self.relative_path - - @property - def full_url(self): - return self.site.full_url(self.relative_path) - class RootNode(Node): """ Represents one of the roots of site: Content, Media or Layout @@ -257,12 +256,12 @@ class RootNode(Node): return self.resource_from_path( self.source_folder.child(relative_path)) - def resource_deploy_path_changed(self, resource): + def deploy_path_changed(self, item): """ Handles the case where the relative deploy path of a resource has changed. """ - self.resource_deploy_map[unicode(resource.relative_deploy_path)] = resource + self.resource_deploy_map[unicode(item.relative_deploy_path)] = item @path_normalized def resource_from_relative_deploy_path(self, relative_deploy_path): diff --git a/hyde/tests/ext/test_flattener.py b/hyde/tests/ext/test_flattener.py index de4a329..e2af835 100644 --- a/hyde/tests/ext/test_flattener.py +++ b/hyde/tests/ext/test_flattener.py @@ -23,7 +23,7 @@ class TestFlattner(object): def tearDown(self): TEST_SITE.delete() - def test_can_flattener(self): + def test_can_flatten(self): s = Site(TEST_SITE) cfg = """ plugins: @@ -43,3 +43,25 @@ class TestFlattner(object): assert not s.config.deploy_root_path.child_folder('blog').exists assert File(s.config.deploy_root_path.child('merry-christmas.html')).exists + def test_flattener_fixes_nodes(self): + s = Site(TEST_SITE) + cfg = """ + plugins: + - hyde.ext.plugins.folders.FlattenerPlugin + flattener: + items: + - + source: blog + target: '' + """ + import yaml + s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) + s.load() + gen = Generator(s) + gen.generate_all() + blog_node = s.content.node_from_relative_path('blog') + + assert blog_node + assert blog_node.url == '/' + + diff --git a/hyde/tests/ext/test_paginator.py b/hyde/tests/ext/test_paginator.py index 0e053ab..d66caff 100644 --- a/hyde/tests/ext/test_paginator.py +++ b/hyde/tests/ext/test_paginator.py @@ -47,18 +47,18 @@ class TestPaginator(object): expected_page1_content = dedent('''\ Another Sad Post - page2/pages_of_one.txt''') + /page2/pages_of_one.txt''') expected_page2_content = dedent('''\ A Happy Post - pages_of_one.txt - page3/pages_of_one.txt''') + /pages_of_one.txt + /page3/pages_of_one.txt''') expected_page3_content = dedent('''\ An Angry Post - page2/pages_of_one.txt - page4/pages_of_one.txt''') + /page2/pages_of_one.txt + /page4/pages_of_one.txt''') expected_page4_content = dedent('''\ A Sad Post - page3/pages_of_one.txt + /page3/pages_of_one.txt ''') page1 = self.deploy.child('pages_of_one.txt') diff --git a/hyde/tests/test_site.py b/hyde/tests/test_site.py index 9c32a30..ed0b35e 100644 --- a/hyde/tests/test_site.py +++ b/hyde/tests/test_site.py @@ -149,7 +149,7 @@ def test_relative_deploy_path(): s.load() for page in s.content.walk_resources(): assert page.relative_deploy_path == Folder(page.relative_path) - assert page.url == page.relative_deploy_path + assert page.url == '/' + page.relative_deploy_path def test_relative_deploy_path_override(): s = Site(TEST_SITE_ROOT) diff --git a/hyde/version.py b/hyde/version.py index 8860d1b..11ff266 100644 --- a/hyde/version.py +++ b/hyde/version.py @@ -3,4 +3,4 @@ Handles hyde version TODO: Use fabric like versioning scheme """ -__version__ = '0.8.5a10' +__version__ = '0.8.5a11'