Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-processhtml

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-processhtml - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

tasks/lib/utils.js

2

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

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