grunt-html-build
Advanced tools
Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "grunt-html-build", | ||
"description": "Grunt HTML Builder - Appends scripts and styles, Removes debug parts, append html partials, Template options", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"homepage": "https://github.com/spatools/grunt-html-build.git", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -229,2 +229,6 @@ # grunt-html-build [![NPM version](https://badge.fury.io/js/grunt-html-build.png)](http://badge.fury.io/js/grunt-html-build) | ||
* Remove deprecated undercore reference and replace by lodash dependency | ||
* Fix deep array flattening for Node.JS >= 4 | ||
* Fix deep array flattening for Node.JS >= 4 | ||
* 0.5.3 | ||
* Fix issue when EOL mismatch with OS EOL | ||
* Add nested tag support | ||
* Improve Tag search |
@@ -31,7 +31,7 @@ /* | ||
var // Init | ||
_ = require('lodash'), | ||
_ = require("lodash"), | ||
EOL = grunt.util.linefeed, | ||
URL = require('url'), | ||
path = require('path'), | ||
beautifier = require('js-beautify'), | ||
URL = require("url"), | ||
path = require("path"), | ||
beautifier = require("js-beautify"), | ||
beautify = { | ||
@@ -53,16 +53,17 @@ js: beautifier.js, | ||
//#region Private Methods | ||
function getBuildTags(content) { | ||
var lines = content.replace(/\r?\n/g, '\n').split(/\n/), | ||
tag = false, | ||
var startRegexp = new RegExp(regexTagStart), | ||
endRegexp = new RegExp(regexTagEnd), | ||
lines = content.replace(/\r?\n/g, "\n").split(/\n/), | ||
tags = [], | ||
last; | ||
last = { end: 0 }, | ||
current = null; | ||
lines.forEach(function (l) { | ||
var tagStart = l.match(new RegExp(regexTagStart)), | ||
tagEnd = new RegExp(regexTagEnd).test(l); | ||
var tagStart = l.match(startRegexp), | ||
tagEnd = endRegexp.test(l); | ||
if (tagStart) { | ||
tag = true; | ||
last = { | ||
current = { | ||
type: tagStart[1], | ||
@@ -75,15 +76,21 @@ inline: !!tagStart[2], | ||
attributes: tagStart[7], | ||
start: content.indexOf(l, last.end), | ||
parent: current, | ||
lines: [] | ||
}; | ||
tags.push(last); | ||
} | ||
// switch back tag flag when endbuild | ||
if (tag && tagEnd) { | ||
last.lines.push(l); | ||
tag = false; | ||
if (current && tagEnd) { | ||
current.end = content.indexOf(l, last.end) + l.length; | ||
current.raw = content.substring(current.start, current.end); | ||
tags.push(current); | ||
last = current; | ||
current = current.parent; | ||
} | ||
if (tag && last) { | ||
last.lines.push(l); | ||
if (current && !tagStart && !tagEnd) { | ||
current.lines.push(l); | ||
} | ||
@@ -94,2 +101,13 @@ }); | ||
} | ||
function rebuildTag(tag, newContent) { | ||
var startRegexp = new RegExp(regexTagStart), | ||
endRegexp = new RegExp(regexTagEnd); | ||
tag.raw = newContent; | ||
tag.lines = newContent.replace(/\r?\n/g, "\n").split(/\n/).filter(function(line) { | ||
return !startRegexp.test(line) && !endRegexp.test(line); | ||
}); | ||
} | ||
function defaultProcessPath(pathes, params, opt) { //takes an array of paths and validates them | ||
@@ -108,2 +126,3 @@ var local = grunt.file.expand(opt, pathes), | ||
} | ||
function validateBlockWithName(tag, params) { | ||
@@ -141,2 +160,3 @@ var src = params[tag.type + "s"], | ||
} | ||
function validateBlockAlways(tag) { | ||
@@ -196,4 +216,4 @@ return true; | ||
return template | ||
.replace("<%= src %>", src) | ||
.replace("<%= attributes %>", attrs); | ||
.replace("<%= src %>", src) | ||
.replace("<%= attributes %>", attrs); | ||
} | ||
@@ -207,3 +227,3 @@ else { | ||
if (options.inline) { | ||
var content = options.files.map(grunt.file.read).join(EOL); | ||
var content = options.files.map(grunt.file.read).join(options.EOL); | ||
return processHtmlTagTemplate(options, content); | ||
@@ -213,13 +233,13 @@ } | ||
var destDir = options.relative && isFileRegex.test(options.dest) ? path.dirname(options.dest) : options.dest; | ||
return options.files.map(function (f) { | ||
var url = options.relative ? path.relative(destDir, f) : f; | ||
url = url.replace(/\\/g, '/'); | ||
url = url.replace(/\\/g, "/"); | ||
if (options.prefix) { | ||
url = URL.resolve(options.prefix.replace(/\\/g, '/'), url); | ||
url = URL.resolve(options.prefix.replace(/\\/g, "/"), url); | ||
} | ||
return processHtmlTagTemplate(options, url); | ||
}).join(EOL); | ||
}).join(options.EOL); | ||
} | ||
@@ -234,6 +254,6 @@ } | ||
templates = { | ||
'script': '<script <%= attributes %> src="<%= src %>"></script>', | ||
'script-inline': '<script <%= attributes %>><%= src %></script>', | ||
'style': '<link <%= attributes %> href="<%= src %>" />', | ||
'style-inline': '<style <%= attributes %>><%= 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>' | ||
}, | ||
@@ -267,3 +287,3 @@ validators = { | ||
content; | ||
}).join(EOL); | ||
}).join(options.EOL); | ||
}, | ||
@@ -273,6 +293,4 @@ | ||
return options.lines | ||
.map(function (l) { return processTemplate(l, options); }) | ||
.join(EOL) | ||
.replace(new RegExp(regexTagStart), "") | ||
.replace(new RegExp(regexTagEnd), ""); | ||
.map(function (l) { return processTemplate(l, options); }) | ||
.join(options.EOL); | ||
}, | ||
@@ -283,4 +301,4 @@ remove: function (options) { | ||
var targets = options.name.split(","); | ||
if (targets.indexOf(grunt.task.current.target) < 0) { | ||
return options.lines.join(EOL).replace(new RegExp(regexTagStart), "").replace(new RegExp(regexTagEnd), ""); | ||
if (targets.indexOf(grunt.task.current.target) === -1) { | ||
return options.lines.join(options.EOL); | ||
} | ||
@@ -304,4 +322,3 @@ | ||
tags.forEach(function (tag) { | ||
var raw = tag.lines.join(EOL), | ||
result = "", | ||
var result = "", | ||
tagFiles = validators.validate(tag, params); | ||
@@ -316,2 +333,3 @@ | ||
relative: params.relative, | ||
EOL: params.EOL || EOL, | ||
params: params | ||
@@ -337,4 +355,8 @@ }); | ||
} | ||
content = content.replace(raw, function () { return result }); | ||
content = content.replace(tag.raw, result); | ||
if (tag.parent) { | ||
rebuildTag(tag.parent, tag.parent.raw.replace(tag.raw, result)); | ||
} | ||
}); | ||
@@ -349,3 +371,3 @@ | ||
grunt.registerMultiTask('htmlbuild', "Grunt HTML Builder - Replace scripts and styles, Removes debug parts, append html partials, Template options", function () { | ||
grunt.registerMultiTask("htmlbuild", "Grunt HTML Builder - Replace scripts and styles, Removes debug parts, append html partials, Template options", function () { | ||
var params = this.options({ | ||
@@ -359,3 +381,3 @@ beautify: false, | ||
data: {}, | ||
parseTag: 'build', | ||
parseTag: "build", | ||
processPath: defaultProcessPath | ||
@@ -362,0 +384,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44095
380
233