Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added ability to override stylesheets/javascripts directories.

  • Loading branch information...
commit c5851831626fb50d58b56846003483c60cb83920 1 parent cd6d969
Jakub Pawlowicz authored September 06, 2012
2  lib/assets.js
@@ -86,7 +86,7 @@ AssetsExpander.prototype = {
86 86
       options = Object.merge(Object.clone(this.options), localOptions || {}),
87 87
       self = this;
88 88
 
89  
-    options.root = path.join(options.root, type);
  89
+    options.root = path.join(options.root, localOptions.path || type);
90 90
 
91 91
     var processLevel = function(levelDefinition, levelOptions) {
92 92
       if (typeof levelDefinition == 'string') {
34  test/assets-test.js
@@ -6,20 +6,27 @@ var vows = require('vows'),
6 6
 
7 7
 var rootPath = process.cwd() + '/test/assets/';
8 8
 
9  
-function fullPathTo(assetName) {
10  
-  return path.join(rootPath, 'stylesheets', assetName + '.css');
  9
+function fullPathTo(assetName, stylesPath) {
  10
+  stylesPath = stylesPath || 'stylesheets';
  11
+  return path.join(rootPath, stylesPath, assetName + '.css');
11 12
 };
12 13
 
13 14
 function expand(list) {
14  
-  return new AssetsExpander().processList(list, { root: path.join(rootPath, 'stylesheets'), type: 'css' });
  15
+  var options = {
  16
+    root: path.join(rootPath, 'stylesheets'),
  17
+    type: 'css'
  18
+  }
  19
+  return new AssetsExpander().processList(list, options);
15 20
 };
16 21
 
17 22
 function expanderFor(name) {
18  
-  return new AssetsExpander(path.join(process.cwd(), 'test', 'assets', name), { root: rootPath });
  23
+  var yamlFilePath = path.join(process.cwd(), 'test', 'assets', name);
  24
+  return new AssetsExpander(yamlFilePath, { root: rootPath });
19 25
 };
20 26
 
21 27
 function group(groupId) {
22  
-  return expanderFor('assets.yml').processGroup('stylesheets', groupId, { type: 'css' });
  28
+  return expanderFor('assets.yml')
  29
+    .processGroup('stylesheets', groupId, { type: 'css' });
23 30
 };
24 31
 
25 32
 exports.yamlSuite = vows.describe('incorrect yaml').addBatch({
@@ -37,6 +44,9 @@ exports.yamlSuite = vows.describe('incorrect yaml').addBatch({
37 44
   }
38 45
 });
39 46
 
  47
+// Tests expanding various assets definitions,
  48
+// e.g. '*', 'one,two', 'path/**/*', 'path/[one,two]'.
  49
+// It is based on files in ./assets/stylesheets directory.
40 50
 exports.listsSuite = vows.describe('expanding assets').addBatch({
41 51
   'expand empty': {
42 52
     topic: expand(''),
@@ -150,6 +160,7 @@ exports.listsSuite = vows.describe('expanding assets').addBatch({
150 160
   }
151 161
 });
152 162
 
  163
+// Tests expanding real definitions from *.yml files
153 164
 exports.groupsSuite = vows.describe('expanding assets groups').addBatch({
154 165
   'expand unknown type': {
155 166
     'should not fail': function(expanded) {
@@ -219,6 +230,19 @@ exports.groupsSuite = vows.describe('expanding assets groups').addBatch({
219 230
       assert.equal(expanded[2], fullPathTo('folder1/other'));
220 231
       assert.equal(expanded[3], fullPathTo('folder1/subfolder1/asset6'));
221 232
     }
  233
+  },
  234
+  'expanding all from custom.yml (with custom path)': {
  235
+    topic: function() {
  236
+      return expanderFor('custom.yml')
  237
+        .processGroup('stylesheets', 'all', { type: 'css', path: './css' });
  238
+    },
  239
+    'should give one asset': function(expanded) {
  240
+      assert.equal(expanded.length, 2);
  241
+    },
  242
+    'should give one.css only': function(expanded) {
  243
+      assert.equal(expanded[0], fullPathTo('one', 'css'));
  244
+      assert.equal(expanded[1], fullPathTo('two', 'css'));
  245
+    }
222 246
   }
223 247
 });
224 248
 
2  test/assets/assets.yml
... ...
@@ -1,4 +1,4 @@
1  
-# Comment (just to test that parsing them works)
  1
+# Comment (just to test that parsing comments works)
2 2
 stylesheets:
3 3
   desktop/public1: 'asset3,asset2,*,folder1/subfolder1/*'
4 4
   desktop/public2:
0  test/assets/css/one.css
No changes.
0  test/assets/css/two.css
No changes.
2  test/assets/custom.yml
... ...
@@ -0,0 +1,2 @@
  1
+stylesheets:
  2
+  all: 'one,two'

0 notes on commit c585183

Please sign in to comment.
Something went wrong with that request. Please try again.