Skip to content

Commit

Permalink
Merge branch 'ppitonak-18_targetPrefix'
Browse files Browse the repository at this point in the history
* ppitonak-18_targetPrefix:
  Force prefix & targetPrefix to end with slash
  reproducer for issue #18, targetPrefix doesn't work when path contains no slash

Fixes #18
  • Loading branch information
pgilad committed Oct 22, 2014
2 parents 864baf7 + 0662a42 commit e6113a2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ module.exports = function (grunt) {
dest: 'test/compiled/layout.jade'
}]
},
withPrefixNoSlash: {
options: {
tasks: {
js: ['concat', 'uglify', 'filerev'],
css: ['concat', 'cssmin']
},
dirTasks: ['filerev'],
prefix: 'test',
targetPrefix: 'test'
},
files: [{
src: 'test/fixtures/withPrefixNoSlash.jade',
dest: 'test/compiled/withPrefixNoSlash.jade'
}]
},
alternate: {
options: {
tasks: {
Expand Down Expand Up @@ -129,6 +144,7 @@ module.exports = function (grunt) {
'jadeUsemin:basic',
'jadeUsemin:advanced',
'jadeUsemin:withPrefix',
'jadeUsemin:withPrefixNoSlash',
'jadeUsemin:alternate',
'jadeUsemin:empty',
'copy:test',
Expand Down
16 changes: 15 additions & 1 deletion tasks/jade_usemin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,38 @@ module.exports = function (grunt) {
tasks: {
js: ['concat', 'uglify'],
css: ['concat', 'cssmin']
}
},
prefix: null,
targetPrefix: null,
dirTasks: null,
replacePath: {}
});

//force dirTasks to always be an array
if (options.dirTasks && !Array.isArray(options.dirTasks)) {
options.dirTasks = [options.dirTasks];
}

//targetPrefix must be a string
if (options.targetPrefix && !_.isString(options.targetPrefix)) {
grunt.warn('Option targetPrefix must be a string');
options.targetPrefix = null;
}

//if targetPrefix exists - make sure it ends with a /
if (options.targetPrefix && options.targetPrefix.slice(-1) !== '/') {
options.targetPrefix += '/';
}

if (options.prefix && !_.isString(options.prefix)) {
grunt.warn('Option prefix must be a string');
options.prefix = null;
}

if (options.prefix && options.prefix.slice(-1) !== '/') {
options.prefix += '/';
}

var extractedTargets = jadeUsemin.iterateFiles(this.files, options);

//rules:
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/withPrefixNoSlash.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//-<!-- build:js compiled/jquery.min.js -->
script(src='/src/script1.js')
//-<!-- endbuild -->
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ exports.jadeUsemin = {
test.ok(/jquery.min.(\w+).js/.test(filename));
test.done();
},
withPrefixNoSlash: function (test) {
test.expect(2);
var layout = grunt.file.read('test/compiled/withPrefixNoSlash.jade');
test.ok(/compiled\/jquery\.min\.(\w+)\.js/.test(layout));
var filename = grunt.file.expand('test/compiled/jquery.min.*.js')[0];
filename = path.basename(filename);
test.ok(/jquery.min.(\w+).js/.test(filename));
test.done();
},
windowsPaths: function (test) {
test.expect(1);

Expand Down

0 comments on commit e6113a2

Please sign in to comment.