Browse Source

Issue #111: Added an optional sorting parameter

main
Lakshmi Vyasarajan 13 years ago
parent
commit
08bb122b5b
5 changed files with 44 additions and 4 deletions
  1. +5
    -0
      CHANGELOG.rst
  2. +1
    -1
      README.rst
  3. +14
    -2
      hyde/ext/plugins/combine.py
  4. +23
    -0
      hyde/tests/ext/test_combine.py
  5. +1
    -1
      hyde/version.py

+ 5
- 0
CHANGELOG.rst View File

@@ -1,3 +1,8 @@
Version 0.8.5a4
============================================================

* Added an optional sorting parameter. (Issue #111)

Version 0.8.5a3
============================================================



+ 1
- 1
README.rst View File

@@ -1,4 +1,4 @@
Version 0.8.5a3
Version 0.8.5a4

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


+ 14
- 2
hyde/ext/plugins/combine.py View File

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


+ 23
- 0
hyde/tests/ext/test_combine.py View File

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


+ 1
- 1
hyde/version.py View File

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

Loading…
Cancel
Save