Browse Source

Issue #126: (BREAKING)- Folderflattener now updates node url and deploy path properties

main
Lakshmi Vyasarajan 13 years ago
parent
commit
5e49e75c23
8 changed files with 78 additions and 50 deletions
  1. +6
    -0
      CHANGELOG.rst
  2. +1
    -1
      README.rst
  3. +2
    -1
      hyde/ext/plugins/folders.py
  4. +38
    -39
      hyde/site.py
  5. +23
    -1
      hyde/tests/ext/test_flattener.py
  6. +6
    -6
      hyde/tests/ext/test_paginator.py
  7. +1
    -1
      hyde/tests/test_site.py
  8. +1
    -1
      hyde/version.py

+ 6
- 0
CHANGELOG.rst View File

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



+ 1
- 1
README.rst View File

@@ -1,4 +1,4 @@
Version 0.8.5a10
Version 0.8.5a11

A brand new **hyde**
====================


+ 2
- 1
hyde/ext/plugins/folders.py View File

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


+ 38
- 39
hyde/site.py View File

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


+ 23
- 1
hyde/tests/ext/test_flattener.py View File

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



+ 6
- 6
hyde/tests/ext/test_paginator.py View File

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


+ 1
- 1
hyde/tests/test_site.py View File

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


+ 1
- 1
hyde/version.py View File

@@ -3,4 +3,4 @@
Handles hyde version
TODO: Use fabric like versioning scheme
"""
__version__ = '0.8.5a10'
__version__ = '0.8.5a11'

Loading…
Cancel
Save