Commits

Lakshmi Vyasarajan  committed 5b0d977

Issue #111: Added an optional sorting parameter

  • Participants
  • Parent commits 609fb42

Comments (0)

Files changed (5)

File CHANGELOG.rst

+Version 0.8.5a4
+============================================================
+
+*   Added an optional sorting parameter. (Issue #111)
+
 Version 0.8.5a3
 ============================================================
 
-Version 0.8.5a3
+Version 0.8.5a4
 
 A brand new **hyde**
 ====================

File hyde/ext/plugins/combine.py

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

File hyde/tests/ext/test_combine.py

         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()
+        return
+
     def test_combine_remove(self):
         _, s = self._test_combine("""
 ---

File hyde/version.py

 Handles hyde version
 TODO: Use fabric like versioning scheme
 """
-__version__ = '0.8.5a3'
+__version__ = '0.8.5a4'