grunt-html-build
Advanced tools
Comparing version 0.4.3 to 0.5.0
@@ -11,2 +11,3 @@ module.exports = function (grunt) { | ||
beautify: true, | ||
//allowUnknownTags: true, | ||
//parseTag: 'htmlbuild', | ||
@@ -19,2 +20,6 @@ relative: true, | ||
], | ||
bundle_remote: [ | ||
"//cdn.jsdelivr.net/jquery/2.1.0/jquery.min.js", | ||
"//cdn.jsdelivr.net/bootstrap/3.1.1/js/bootstrap.min.js" | ||
], | ||
inlineapp: '<%= fixturesPath %>/scripts/app.js', | ||
@@ -28,3 +33,4 @@ main: '<%= fixturesPath %>/scripts/main.js' | ||
'css/libs.css', | ||
'css/dev.css' | ||
'css/dev.css', | ||
'css/another.less' | ||
] | ||
@@ -31,0 +37,0 @@ }, |
{ | ||
"name": "grunt-html-build", | ||
"description": "Grunt HTML Builder - Appends scripts and styles, Removes debug parts, append html partials, Template options", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/spatools/grunt-html-build.git", | ||
@@ -18,8 +18,6 @@ "author": { | ||
"devDependencies": { | ||
"grunt": "^0.4.5", | ||
"js-beautify": "^1.4.2" | ||
"grunt": "^0.4.5" | ||
}, | ||
"dependencies": { | ||
"grunt": "0.4.x", | ||
"js-beautify": "^1.4.2" | ||
"js-beautify": "^1.5.5" | ||
}, | ||
@@ -26,0 +24,0 @@ "keywords": [ |
@@ -218,1 +218,7 @@ # grunt-html-build [![NPM version](https://badge.fury.io/js/grunt-html-build.png)](http://badge.fury.io/js/grunt-html-build) | ||
* Allow remove task to be configured by using current target. | ||
* 0.5.0 | ||
* Avoid javascript errors when parsing unknown tags. | ||
* Add an `allowUnknownTags` option to ignore unknown tags without failing the task. | ||
* Allow to specify `attributes` on script and styles tags. | ||
* Allow http,https or // links to be processed as links. | ||
* Automatically adapt generated `link` tag for less files. |
@@ -43,3 +43,3 @@ /* | ||
// Tags Regular Expressions | ||
regexTagStartTemplate = "<!--\\s*%parseTag%:(\\w+)\\s*(inline)?\\s*(optional)?\\s*(recursive)?\\s*(noprocess)?\\s*([^\\s]*)\\s*-->", // <!-- build:{type} [inline] [optional] [recursive] {name} --> {} required [] optional | ||
regexTagStartTemplate = "<!--\\s*%parseTag%:(\\w+)\\s*(inline)?\\s*(optional)?\\s*(recursive)?\\s*(noprocess)?\\s*([^\\s]*)\\s*(?:\\[(.*)\\])?\\s*-->", // <!-- build:{type} (inline) (optional) (recursive) {name} [attributes...] --> {} required () optional | ||
regexTagEndTemplate = "<!--\\s*\\/%parseTag%\\s*-->", // <!-- /build --> | ||
@@ -71,4 +71,5 @@ regexTagStart = "", | ||
recursive: !!tagStart[4], | ||
noprocess: !!tagStart[5], | ||
noprocess: !!tagStart[5], | ||
name: tagStart[6], | ||
attributes: tagStart[7], | ||
lines: [] | ||
@@ -92,2 +93,14 @@ }; | ||
} | ||
function defaultProcessPath(pathes, params, opt) { //takes an array of paths and validates them | ||
var local = grunt.file.expand(opt, pathes), | ||
remote = _.map(pathes, path.normalize).filter(function (path) { //for loading from cdn | ||
return /^((http|https):)?(\\|\/\/)/.test(path); //is http, https, or // | ||
}); | ||
if (params.relative && opt.cwd) { | ||
local = local.map(function (src) { return path.join(opt.cwd, src); }); | ||
} | ||
return _.uniq(local.concat(remote)); | ||
} | ||
function validateBlockWithName(tag, params) { | ||
@@ -118,11 +131,9 @@ var src = params[tag.type + "s"], | ||
files = grunt.file.expand(opt, files); | ||
if (!Array.isArray(files)) { | ||
files = [files]; | ||
} | ||
if (params.relative && opt.cwd) { | ||
files = files.map(function (src) { return path.join(opt.cwd, src); }); | ||
} | ||
return files; | ||
} | ||
return params.processPath(files, params, opt); | ||
} | ||
} | ||
function validateBlockAlways(tag) { | ||
@@ -141,17 +152,48 @@ return true; | ||
function createTemplateData(options, extend) { | ||
function createTemplateData(options, src, attrs) { | ||
var extend = {}; | ||
if (src) { | ||
extend.src = src; | ||
} | ||
if (attrs) { | ||
extend.attributes = attrs; | ||
} | ||
return { | ||
data: extend ? _.extend({}, options.data, extend) : options.data | ||
data: _.extend({}, options.data, extend) | ||
}; | ||
} | ||
function processTemplate(template, options, extend) { | ||
return grunt.template.process(template, createTemplateData(options, extend)); | ||
function processTemplate(template, options, src, attrs) { | ||
return grunt.template.process(template, createTemplateData(options, src, attrs)); | ||
} | ||
function processHtmlTagTemplate(options, extend) { | ||
var template = templates[options.type + (options.inline ? "-inline" : "")]; | ||
if (options.noprocess) { | ||
return template.replace("<%= src %>", extend.src); | ||
function createAttributes(options, src) { | ||
var attrs = options.attributes || ""; | ||
if (options.type === "script") { | ||
attrs = 'type="text/javascript" ' + attrs; | ||
} | ||
else if (options.type === "style" && !options.inline) { | ||
if (path.extname(src) === ".less") { | ||
attrs = 'type="text/css" rel="stylesheet/less" ' + attrs; | ||
} | ||
else { | ||
attrs = 'type="text/css" rel="stylesheet" ' + attrs; | ||
} | ||
} | ||
return attrs.trim(); | ||
} | ||
function processHtmlTagTemplate(options, src) { | ||
var template = templates[options.type + (options.inline ? "-inline" : "")], | ||
attrs = createAttributes(options, src); | ||
if (!options.inline || options.noprocess) { | ||
return template | ||
.replace("<%= src %>", src) | ||
.replace("<%= attributes %>", attrs); | ||
} | ||
else { | ||
return processTemplate(template, options, extend); | ||
return processTemplate(template, options, src, attrs); | ||
} | ||
@@ -163,3 +205,3 @@ } | ||
var content = options.files.map(grunt.file.read).join(EOL); | ||
return processHtmlTagTemplate(options, { src: content }); | ||
return processHtmlTagTemplate(options, content); | ||
} | ||
@@ -169,3 +211,3 @@ else { | ||
var url = options.relative ? path.relative(options.dest, f) : f; | ||
url = url.replace(/\\/g, '/'); | ||
@@ -176,4 +218,4 @@ | ||
} | ||
return processHtmlTagTemplate(options, { src: url }); | ||
return processHtmlTagTemplate(options, url); | ||
}).join(EOL); | ||
@@ -189,6 +231,6 @@ } | ||
templates = { | ||
'script': '<script type="text/javascript" src="<%= src %>"></script>', | ||
'script-inline': '<script type="text/javascript"><%= src %></script>', | ||
'style': '<link type="text/css" rel="stylesheet" href="<%= src %>" />', | ||
'style-inline': '<style><%= src %></style>' | ||
'script': '<script <%= attributes %> src="<%= src %>"></script>', | ||
'script-inline': '<script <%= attributes %>><%= src %></script>', | ||
'style': '<link <%= attributes %> href="<%= src %>" />', | ||
'style-inline': '<style <%= attributes %>><%= src %></style>' | ||
}, | ||
@@ -205,2 +247,6 @@ validators = { | ||
validate: function (tag, params) { | ||
if (!validators[tag.type]) { | ||
return false; | ||
} | ||
return validators[tag.type](tag, params); | ||
@@ -252,33 +298,41 @@ } | ||
tags.forEach(function (tag) { | ||
var raw = tag.lines.join(EOL), | ||
result = "", | ||
tagFiles = validators.validate(tag, params); | ||
tags.forEach(function (tag) { | ||
var raw = tag.lines.join(EOL), | ||
result = "", | ||
tagFiles = validators.validate(tag, params); | ||
if (tagFiles) { | ||
var options = _.extend({}, tag, { | ||
data: _.extend({}, config, params.data), | ||
files: tagFiles, | ||
dest: dest, | ||
prefix: params.prefix, | ||
if (tagFiles) { | ||
var options = _.extend({}, tag, { | ||
data: _.extend({}, config, params.data), | ||
files: tagFiles, | ||
dest: dest, | ||
prefix: params.prefix, | ||
relative: params.relative, | ||
params: params | ||
}); | ||
}); | ||
result = processors.transform(options); | ||
result = processors.transform(options); | ||
} | ||
else if (tagFiles === false) { | ||
grunt.log.warn("Unknown tag detected: '" + tag.type + "'"); | ||
if (!params.allowUnknownTags) { | ||
grunt.fail.warn("Use 'parseTag' or 'allowUnknownTags' options to avoid this issue"); | ||
} | ||
} | ||
else if (tag.optional) { | ||
if (params.logOptionals) | ||
grunt.log.error().error("Tag with type: '" + tag.type + "' and name: '" + tag.name + "' is not configured in your Gruntfile.js but is set optional, deleting block !"); | ||
} | ||
else { | ||
grunt.fail.warn("Tag with type '" + tag.type + "' and name: '" + tag.name + "' is not configured in your Gruntfile.js !"); | ||
} | ||
else if (tag.optional) { | ||
if (params.logOptionals) { | ||
grunt.log.warn("Tag with type: '" + tag.type + "' and name: '" + tag.name + "' is not configured in your Gruntfile.js but is set optional, deleting block !"); | ||
} | ||
} | ||
else { | ||
grunt.fail.warn("Tag with type '" + tag.type + "' and name: '" + tag.name + "' is not configured in your Gruntfile.js !"); | ||
} | ||
content = content.replace(raw, function () { return result }); | ||
}); | ||
content = content.replace(raw, function () { return result }); | ||
}); | ||
if (params.beautify) { | ||
content = beautify.html(content, _.isObject(params.beautify) ? params.beautify : {}); | ||
} | ||
if (params.beautify) { | ||
content = beautify.html(content, _.isObject(params.beautify) ? params.beautify : {}); | ||
} | ||
@@ -297,3 +351,4 @@ return content; | ||
data: {}, | ||
parseTag: 'build' | ||
parseTag: 'build', | ||
processPath: defaultProcessPath | ||
}); | ||
@@ -300,0 +355,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42646
1
1
27
364
224
- Removedgrunt@0.4.x
- Removedabbrev@1.1.1(transitive)
- Removedargparse@0.1.16(transitive)
- Removedasync@0.1.22(transitive)
- Removedcoffee-script@1.3.3(transitive)
- Removedcolors@0.6.2(transitive)
- Removeddateformat@1.0.2-1.2.3(transitive)
- Removedesprima@1.0.4(transitive)
- Removedeventemitter2@0.4.14(transitive)
- Removedexit@0.1.2(transitive)
- Removedfindup-sync@0.1.3(transitive)
- Removedgetobject@0.1.0(transitive)
- Removedglob@3.1.213.2.11(transitive)
- Removedgraceful-fs@1.2.3(transitive)
- Removedgrunt@0.4.5(transitive)
- Removedgrunt-legacy-log@0.1.3(transitive)
- Removedgrunt-legacy-log-utils@0.1.1(transitive)
- Removedgrunt-legacy-util@0.2.0(transitive)
- Removedhooker@0.2.3(transitive)
- Removediconv-lite@0.2.11(transitive)
- Removedinherits@1.0.22.0.4(transitive)
- Removedjs-yaml@2.0.5(transitive)
- Removedlodash@0.9.22.4.2(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.2.140.3.0(transitive)
- Removednopt@1.0.10(transitive)
- Removedrimraf@2.2.8(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedunderscore@1.7.0(transitive)
- Removedunderscore.string@2.2.12.3.32.4.0(transitive)
- Removedwhich@1.0.9(transitive)
Updatedjs-beautify@^1.5.5