grunt-processhtml
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "grunt-processhtml", | ||
"description": "Process html files at build time to modify them depending on the release environment", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/dciccale/grunt-processhtml", | ||
@@ -6,0 +6,0 @@ "author": { |
'use strict'; | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var utils = require('./utils'); | ||
exports.init = function (grunt) { | ||
var _ = grunt.util._; | ||
var _tmplData; | ||
var _tmplData, _filePath; | ||
var getBlocks = function (content) { | ||
// <!-- build:<type>[:target] [value] --> | ||
// - type (required) js, css, href, remove, template | ||
// - target|attribute i.e. dev, release or [href] [src] | ||
// - value (optional) i.e. script.min.js | ||
/* | ||
* <!-- build:<type>[:target] [value] --> | ||
* - type (required) js, css, href, remove, template | ||
* - target|attribute i.e. dev, release or [href] [src] | ||
* - value (optional) i.e. script.min.js | ||
*/ | ||
var regbuild = /<!--\s*build:(\[?\w+\]?)(?::(\w+))?(?:\s*([^\s]+)\s*-->)*/; | ||
@@ -54,14 +58,6 @@ // <!-- /build --> | ||
var _escapeRegExp = function (str) { | ||
return str.replace(/([.?*+\^=!:$\[\]\\(){}|\-])/g, '\\$1'); | ||
}; | ||
var _blockToRegExp = function (blockLine) { | ||
var escaped = _escapeRegExp(blockLine); | ||
return new RegExp(escaped.replace(/^\s*|[\r\n]+\s*/g, '\\s*').replace(/\n{1}$/g, '\\n')); | ||
}; | ||
var HTMLProcessor = function (content, tmplData) { | ||
var HTMLProcessor = function (content, tmplData, filePath) { | ||
this.content = content; | ||
_tmplData = tmplData || {}; | ||
_filePath = filePath || ''; | ||
this.target = tmplData.environment; | ||
@@ -98,3 +94,3 @@ this.linefeed = /\r\n/g.test(content) ? '\r\n' : '\n'; | ||
remove: function (content, block, blockLine, blockContent) { | ||
var blockRegExp = _blockToRegExp(blockLine); | ||
var blockRegExp = utils.blockToRegExp(blockLine); | ||
return content.replace(blockRegExp, ''); | ||
@@ -108,2 +104,12 @@ }, | ||
return content.replace(blockLine, compiledTmpl); | ||
}, | ||
include: function (content, block, blockLine, blockContent) { | ||
var filePath = path.join(path.dirname(_filePath), block.asset); | ||
var fileContent; | ||
if (fs.existsSync(filePath)) { | ||
fileContent = block.indent + fs.readFileSync(filePath); | ||
content = content.replace(blockLine, fileContent); | ||
} | ||
return content; | ||
} | ||
@@ -127,3 +133,3 @@ }; | ||
this.blocks.forEach(function (block) { | ||
_.each(this.blocks, function (block) { | ||
// parse through correct block type also checking the build target | ||
@@ -130,0 +136,0 @@ if (_blockTypes[block.type] && (!block.target || block.target === this.target)) { |
@@ -37,3 +37,3 @@ /* | ||
var content = grunt.file.read(filepath); | ||
var html = new HTMLProcessor(content, data); | ||
var html = new HTMLProcessor(content, data, filepath); | ||
content = html.process(); | ||
@@ -40,0 +40,0 @@ if (options.process) { |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
15713
7
168
1