New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-html-build

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-html-build - npm Package Compare versions

Comparing version 0.4.3 to 0.5.0

fixtures/css/another.less

8

Gruntfile.js

@@ -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 @@ },

8

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc