| @@ -1,3 +1,8 @@ | |||||
| Version 0.8.5a2 | |||||
| ============================================================ | |||||
| * Modified combined plugin to support relative paths and recursion. (Issue #108) | |||||
| Version 0.8.5a1 | Version 0.8.5a1 | ||||
| ============================================================ | ============================================================ | ||||
| @@ -1,4 +1,4 @@ | |||||
| Version 0.8.5a1 | |||||
| Version 0.8.5a2 | |||||
| A brand new **hyde** | A brand new **hyde** | ||||
| ==================== | ==================== | ||||
| @@ -7,12 +7,15 @@ from fnmatch import fnmatch | |||||
| from hyde.model import Expando | from hyde.model import Expando | ||||
| from hyde.plugin import Plugin | from hyde.plugin import Plugin | ||||
| import operator | |||||
| class CombinePlugin(Plugin): | class CombinePlugin(Plugin): | ||||
| """ | """ | ||||
| To use this combine, the following configuration should be added | To use this combine, the following configuration should be added | ||||
| to meta data:: | to meta data:: | ||||
| combine: | combine: | ||||
| root: content/media #Optional. Path must be relative to content folder - default current folder | |||||
| recurse: true #Optional. Default false. | |||||
| files: | files: | ||||
| - ns1.*.js | - ns1.*.js | ||||
| - ns2.*.js | - ns2.*.js | ||||
| @@ -45,17 +48,28 @@ class CombinePlugin(Plugin): | |||||
| files = [ files ] | files = [ files ] | ||||
| # Grab resources to combine | # Grab resources to combine | ||||
| resources = [] | |||||
| for r in resource.node.resources: | |||||
| for f in files: | |||||
| if fnmatch(r.name, f): | |||||
| resources.append(r) | |||||
| break | |||||
| # select site root | |||||
| try: | |||||
| root = self.site.content.node_from_relative_path(resource.meta.combine.root) | |||||
| except AttributeError: | |||||
| root = resource.node | |||||
| # select walker | |||||
| try: | |||||
| recurse = resource.meta.combine.recurse | |||||
| except AttributeError: | |||||
| recurse = False | |||||
| walker = root.walk_resources() if recurse else root.resources | |||||
| resources = [r for r in walker if any(fnmatch(r.name, f) for f in files)] | |||||
| if not resources: | if not resources: | ||||
| self.logger.debug("No resources to combine for [%s]" % resource) | self.logger.debug("No resources to combine for [%s]" % resource) | ||||
| return [] | return [] | ||||
| return sorted(resources, key=lambda r: r.name) | |||||
| return sorted(resources, key=operator.attrgetter('name')) | |||||
| def begin_site(self): | def begin_site(self): | ||||
| """ | """ | ||||
| @@ -105,4 +119,4 @@ class CombinePlugin(Plugin): | |||||
| if where == "top": | if where == "top": | ||||
| return "".join([r.source.read_all() for r in resources] + [text]) | return "".join([r.source.read_all() for r in resources] + [text]) | ||||
| else: | else: | ||||
| return "".join([text] + [r.source.read_all() for r in resources]) | |||||
| return "".join([text] + [r.source.read_all() for r in resources]) | |||||
| @@ -457,4 +457,4 @@ class Site(object): | |||||
| Given the relative path, determines if it is content or media. | Given the relative path, determines if it is content or media. | ||||
| """ | """ | ||||
| folder = self.content.source.child_folder(path) | folder = self.content.source.child_folder(path) | ||||
| return folder.is_descendant_of(self.config.media_root_path) | |||||
| return folder.is_descendant_of(self.config.media_root_path) | |||||
| @@ -12,19 +12,7 @@ from hyde.site import Site | |||||
| COMBINE_SOURCE = File(__file__).parent.child_folder('combine') | COMBINE_SOURCE = File(__file__).parent.child_folder('combine') | ||||
| TEST_SITE = File(__file__).parent.parent.child_folder('_test') | TEST_SITE = File(__file__).parent.parent.child_folder('_test') | ||||
| class TestCombine(object): | |||||
| def setUp(self): | |||||
| TEST_SITE.make() | |||||
| TEST_SITE.parent.child_folder( | |||||
| 'sites/test_jinja').copy_contents_to(TEST_SITE) | |||||
| TEST_SITE.child_folder('content/media/js').make() | |||||
| COMBINE_SOURCE.copy_contents_to(TEST_SITE.child('content/media/js')) | |||||
| def tearDown(self): | |||||
| TEST_SITE.delete() | |||||
| class CombineTester(object): | |||||
| def _test_combine(self, content): | def _test_combine(self, content): | ||||
| s = Site(TEST_SITE) | s = Site(TEST_SITE) | ||||
| s.config.plugins = [ | s.config.plugins = [ | ||||
| @@ -41,6 +29,18 @@ class TestCombine(object): | |||||
| text = target.read_all() | text = target.read_all() | ||||
| return text, s | return text, s | ||||
| class TestCombine(CombineTester): | |||||
| def setUp(self): | |||||
| TEST_SITE.make() | |||||
| TEST_SITE.parent.child_folder( | |||||
| 'sites/test_jinja').copy_contents_to(TEST_SITE) | |||||
| TEST_SITE.child_folder('content/media/js').make() | |||||
| COMBINE_SOURCE.copy_contents_to(TEST_SITE.child('content/media/js')) | |||||
| def tearDown(self): | |||||
| TEST_SITE.delete() | |||||
| def test_combine_top(self): | def test_combine_top(self): | ||||
| text, _ = self._test_combine(""" | text, _ = self._test_combine(""" | ||||
| --- | --- | ||||
| @@ -88,3 +88,40 @@ First line""") | |||||
| for i in range(1,4): | for i in range(1,4): | ||||
| assert not File(Folder(s.config.deploy_root_path). | assert not File(Folder(s.config.deploy_root_path). | ||||
| child('media/js/script.%d.js' % i)).exists | child('media/js/script.%d.js' % i)).exists | ||||
| class TestCombinePaths(CombineTester): | |||||
| def setUp(self): | |||||
| TEST_SITE.make() | |||||
| TEST_SITE.parent.child_folder( | |||||
| 'sites/test_jinja').copy_contents_to(TEST_SITE) | |||||
| TEST_SITE.child_folder('content/media/js').make() | |||||
| JS = TEST_SITE.child_folder('content/scripts').make() | |||||
| S1 = JS.child_folder('s1').make() | |||||
| S2 = JS.child_folder('s2').make() | |||||
| S3 = JS.child_folder('s3').make() | |||||
| File(COMBINE_SOURCE.child('script.1.js')).copy_to(S1) | |||||
| File(COMBINE_SOURCE.child('script.2.js')).copy_to(S2) | |||||
| File(COMBINE_SOURCE.child('script.3.js')).copy_to(S3) | |||||
| def tearDown(self): | |||||
| TEST_SITE.delete() | |||||
| def test_combine_top(self): | |||||
| text, _ = self._test_combine(""" | |||||
| --- | |||||
| combine: | |||||
| root: scripts | |||||
| recurse: true | |||||
| files: script.*.js | |||||
| where: top | |||||
| --- | |||||
| Last line""") | |||||
| print text | |||||
| assert text == """var a = 1 + 2; | |||||
| var b = a + 3; | |||||
| var c = a + 5; | |||||
| Last line""" | |||||
| return | |||||
| @@ -3,4 +3,4 @@ | |||||
| Handles hyde version | Handles hyde version | ||||
| TODO: Use fabric like versioning scheme | TODO: Use fabric like versioning scheme | ||||
| """ | """ | ||||
| __version__ = '0.8.5a1' | |||||
| __version__ = '0.8.5a2' | |||||