diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c0f8546..6a44988 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +Version 0.8.5a4 +============================================================ + +* Added an optional sorting parameter. (Issue #111) + Version 0.8.5a3 ============================================================ diff --git a/README.rst b/README.rst index b1374fb..9f2e46b 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Version 0.8.5a3 +Version 0.8.5a4 A brand new **hyde** ==================== diff --git a/hyde/ext/plugins/combine.py b/hyde/ext/plugins/combine.py index a610779..a0ad217 100644 --- a/hyde/ext/plugins/combine.py +++ b/hyde/ext/plugins/combine.py @@ -14,6 +14,7 @@ class CombinePlugin(Plugin): To use this combine, the following configuration should be added to meta data:: combine: + sort: false #Optional. Defaults to true. root: content/media #Optional. Path must be relative to content folder - default current folder recurse: true #Optional. Default false. files: @@ -63,13 +64,24 @@ class CombinePlugin(Plugin): 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)] + # Must we sort? + try: + sort = resource.meta.combine.sort + except AttributeError: + sort = True + + if sort: + resources = sorted([r for r in walker if any(fnmatch(r.name, f) for f in files)], + key=operator.attrgetter('name')) + else: + resources = dict([(f, r) for f in files for r in walker if fnmatch(r.name, f)]) + resources = [resources[f] for f in files if f in resources] if not resources: self.logger.debug("No resources to combine for [%s]" % resource) return [] - return sorted(resources, key=operator.attrgetter('name')) + return resources def begin_site(self): """ diff --git a/hyde/tests/ext/test_combine.py b/hyde/tests/ext/test_combine.py index 629a0cc..e8003d4 100644 --- a/hyde/tests/ext/test_combine.py +++ b/hyde/tests/ext/test_combine.py @@ -70,6 +70,29 @@ First line var a = 1 + 2; var b = a + 3; var c = a + 5; +""" + + assert text.strip() == expected.strip() + return + + def test_combine_bottom_unsorted(self): + text, _ = self._test_combine(""" +--- +combine: + sort: false + files: + - script.3.js + - script.1.js + - script.2.js + where: bottom +--- + +First line +""") + expected = """First line +var c = a + 5; +var a = 1 + 2; +var b = a + 3; """ assert text.strip() == expected.strip() diff --git a/hyde/version.py b/hyde/version.py index fc3a2c0..babfbbd 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.5a3' +__version__ = '0.8.5a4'