assets-include
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -0,1 +1,6 @@ | ||
0.6.0 / 2012-08-09 | ||
================== | ||
* Added support for asset hosts (-a ... or assetHosts via API). | ||
0.5.0 / 2012-08-07 | ||
@@ -2,0 +7,0 @@ ================== |
@@ -12,3 +12,4 @@ var AssetsExpander = require('assets-expander'), | ||
this.rootPath = process.cwd(); | ||
this.hostsIterator = this._hostsIterator(this.options.assetHosts); | ||
if (this.options.root.indexOf(this.rootPath) != 0) | ||
@@ -81,6 +82,8 @@ this.options.root = path.normalize(path.join(this.rootPath, this.options.root)); | ||
_assetPathWithStamp: function(assetPath, bundleInfo) { | ||
var hostPrefix = this.hostsIterator ? '//' + this.hostsIterator.next() : ''; | ||
var relativePath = assetPath.replace(this.options.root, ''); | ||
if (this.options.bundled && this.cacheInfo) { | ||
var cacheStamp = this.cacheInfo[bundleInfo.type + '/' + bundleInfo.group]; | ||
return relativePath.replace(/\.(css|js)/, '-' + cacheStamp + ".$1"); | ||
return hostPrefix + relativePath.replace(/\.(css|js)/, '-' + cacheStamp + ".$1"); | ||
} else { | ||
@@ -91,3 +94,3 @@ var mtime = assetPath.indexOf(this.rootPath) == 0 ? | ||
return relativePath + "?" + mtime; | ||
return hostPrefix + relativePath + "?" + mtime; | ||
} | ||
@@ -110,2 +113,31 @@ }, | ||
_hostsIterator: function(hostsDefinition) { | ||
if (!hostsDefinition) return null; | ||
return { | ||
next: function() { | ||
if (!this.cycleList) { | ||
var cycleList = []; | ||
if (hostsDefinition.indexOf('[') > -1) { | ||
var start = hostsDefinition.indexOf('['); | ||
var end = hostsDefinition.indexOf(']'); | ||
var pattern = hostsDefinition.substring(start + 1, end); | ||
pattern.split(',').forEach(function(version) { | ||
cycleList.push(hostsDefinition.replace(/\[([^\]])+\]/, version)); | ||
}); | ||
} else { | ||
cycleList = [hostsDefinition]; | ||
} | ||
this.cycleList = cycleList; | ||
this.index = 0; | ||
} | ||
if (this.index == this.cycleList.length) this.index = 0; | ||
return this.cycleList[this.index++]; | ||
} | ||
}; | ||
}, | ||
_bundleInfo: function(locator) { | ||
@@ -112,0 +144,0 @@ var firstSlashIndex = locator.indexOf('/'), |
@@ -5,3 +5,3 @@ { | ||
"description": "Include assets into your views with ease (assets-packager compatible).", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "" |
@@ -46,2 +46,8 @@ var vows = require('vows'), | ||
}), | ||
'bundled scripts with asset hosts': binaryContext('-b -a assets[0,1].goalsmashers.com -r ./data/public -c ./data/config.yml javascripts/all.js', { | ||
'must give bundled script inclusion': function(error, stdout) { | ||
assert.equal(stdout.match(/<script/g).length, 1); | ||
assert.equal(stdout.match(/\/\/assets0.goalsmashers.com\/javascripts\/bundled\/all\.js\?\d+/g).length, 1); | ||
} | ||
}), | ||
'bundled scripts with cache boosters': binaryContext('-b -s -r ./data/public -c ./data/config.yml javascripts/all.js', { | ||
@@ -68,2 +74,7 @@ 'must give bundled script inclusion': function(error, stdout) { | ||
}), | ||
'bundled plain lists with asset hosts': binaryContext('-l -b -a assets[3,2,1].goalsmashers.com -r ./data/public -c ./data/config.yml javascripts/all.js', { | ||
'must give bundled script inclusion': function(error, stdout) { | ||
assert(/^\/\/assets3.goalsmashers.com\/javascripts\/bundled\/all\.js\?\d+$/.test(stdout)) | ||
} | ||
}), | ||
'inline with cache boosters': binaryContext('-i -b -s -r ./data/public -c ./data/config.yml javascripts/all.js', { | ||
@@ -70,0 +81,0 @@ 'must give bundled script inclusion': function(error, stdout) { |
@@ -63,2 +63,12 @@ var vows = require('vows'), | ||
}), | ||
'in plain (dev) mode with asset hosts': includeContext({ | ||
'should give a list of link tags': function(include) { | ||
var asFragment = include.group('stylesheets/all.less'); | ||
assert(/\/\/assets0.goalsmashers.com\/stylesheets\/one.less\?\d+/.test(asFragment), 'missing one.less'); | ||
assert(/\/\/assets1.goalsmashers.com\/stylesheets\/two.less\?\d+/.test(asFragment), 'missing two.less'); | ||
assert(/\/\/assets0.goalsmashers.com\/stylesheets\/three.less\?\d+/.test(asFragment), 'missing three.less'); | ||
assert.equal(asFragment.match(/<link/g).length, 3); | ||
assert.equal(asFragment.match(/rel="stylesheet\/less"/g).length, 3); | ||
} | ||
}, { assetHosts: 'assets[0,1].goalsmashers.com' }), | ||
'in bundled (prod) mode as CSS': includeContext({ | ||
@@ -77,3 +87,10 @@ 'should give a bundled link tag': function(include) { | ||
} | ||
}, { bundled: true, cacheBoosters: true }) | ||
}, { bundled: true, cacheBoosters: true }), | ||
'in bundled mode as CSS with assets hosts': includeContext({ | ||
'should give a bundled link tag with version id': function(include) { | ||
var asFragment = include.group('stylesheets/all.css'); | ||
assert(/"\/\/assets0.goalsmashers.com\/stylesheets\/bundled\/all\.css\?\d+"/.test(asFragment), 'missing all.css'); | ||
assert.equal(asFragment.match(/<link/g).length, 1); | ||
} | ||
}, { bundled: true, assetHosts: "assets[0,1].goalsmashers.com" }) | ||
}, | ||
@@ -93,3 +110,3 @@ 'scripts group': { | ||
var asFragment = include.group('javascripts/all.js'); | ||
assert(/\/javascripts\/bundled\/all.js\?\d+/.test(asFragment), 'missing all.js'); | ||
assert(/\/javascripts\/bundled\/all\.js\?\d+/.test(asFragment), 'missing all.js'); | ||
assert.equal(asFragment.match(/<script/g).length, 1); | ||
@@ -101,6 +118,13 @@ } | ||
var asFragment = include.group('javascripts/all.js'); | ||
assert(/"\/javascripts\/bundled\/all-test1234567.js"/.test(asFragment), 'missing all.js'); | ||
assert(/"\/javascripts\/bundled\/all\-test1234567\.js"/.test(asFragment), 'missing all.js'); | ||
assert.equal(asFragment.match(/<script/g).length, 1); | ||
} | ||
}, { bundled: true, cacheBoosters: true }) | ||
}, { bundled: true, cacheBoosters: true }), | ||
'in bundled (prod) mode with assets hosts': includeContext({ | ||
'should give a bundled script tag': function(include) { | ||
var asFragment = include.group('javascripts/all.js'); | ||
assert(/"\/\/assets0.goalsmashers.com\/javascripts\/bundled\/all\.js\?\d+"/.test(asFragment), 'missing all.js'); | ||
assert.equal(asFragment.match(/<script/g).length, 1); | ||
} | ||
}, { bundled: true, assetHosts: 'assets0.goalsmashers.com' }) | ||
}, | ||
@@ -149,3 +173,10 @@ 'custom': { | ||
} | ||
}, { bundled: true, cacheBoosters: true }) | ||
}, { bundled: true, cacheBoosters: true }), | ||
'in bundled (prod) mode as CSS with assets hosts': includeContext({ | ||
'should give one stylesheet': function(include) { | ||
var list = include.list('stylesheets/all.css'); | ||
assert.equal(list.length, 1); | ||
assert(/\/\/na.test.com\/stylesheets\/bundled\/all\.css\?\d+/.test(list[0]), 'missing all.less') | ||
} | ||
}, { bundled: true, assetHosts: 'n[a,b].test.com' }) | ||
}, | ||
@@ -174,3 +205,10 @@ 'list of scripts': { | ||
} | ||
}, { bundled: true, cacheBoosters: true }) | ||
}, { bundled: true, cacheBoosters: true }), | ||
'in bundled (prod) mode with assets hosts': includeContext({ | ||
'should give one stylesheet': function(include) { | ||
var list = include.list('javascripts/all.js'); | ||
assert.equal(list.length, 1); | ||
assert(/\/\/goalsmashers.com\/javascripts\/bundled\/all\.js\?\d+/.test(list[0]), 'missing all.js') | ||
} | ||
}, { bundled: true, assetHosts: 'goalsmashers.com' }) | ||
} | ||
@@ -205,3 +243,3 @@ }); | ||
}, { bundled: true }), | ||
'in bundled (prod) mode as CSS': includeContext({ | ||
'in bundled (prod) mode as CSS with cache boosters': includeContext({ | ||
'should give list of link tags': function(include) { | ||
@@ -211,3 +249,9 @@ var asFragment = include.inline('stylesheets/all.css'); | ||
} | ||
}, { bundled: true, cacheBoosters: true }) | ||
}, { bundled: true, cacheBoosters: true }), | ||
'in bundled (prod) mode as CSS with asset hosts': includeContext({ | ||
'should give list of link tags': function(include) { | ||
var asFragment = include.inline('stylesheets/all.css'); | ||
assert.equal("<style type=\"text/css\">.one{}.two{}.three{}</style>", asFragment); | ||
} | ||
}, { bundled: true, assetHosts: '[0,1].goalsmashers.com' }) | ||
}, | ||
@@ -230,3 +274,3 @@ 'inline scripts': { | ||
}, { bundled: true }), | ||
'in bundled (prod) mode': includeContext({ | ||
'in bundled (prod) mode with cache boosters': includeContext({ | ||
'should give a bundled script tag': function(include) { | ||
@@ -236,4 +280,10 @@ var asFragment = include.inline('javascripts/all.js'); | ||
} | ||
}, { bundled: true, cacheBoosters: true }) | ||
}, { bundled: true, cacheBoosters: true }), | ||
'in bundled (prod) mode with asset hosts': includeContext({ | ||
'should give a bundled script tag': function(include) { | ||
var asFragment = include.inline('javascripts/all.js'); | ||
assert.equal("<script>123</script>", asFragment); | ||
} | ||
}, { bundled: true, assetHosts: 'goalsmashers.com' }) | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26899
482