htmlprocessor
Advanced tools
Comparing version 0.1.1 to 0.1.2
#!/usr/bin/env node | ||
/* | ||
* node-htmlprocessor | ||
* https://github.com/dciccale/node-htmlprocessor | ||
* | ||
* Copyright (c) 2013-2014 Denis Ciccale (@tdecs) | ||
* Licensed under the MIT license. | ||
* https://github.com/dciccale/node-htmlprocessor/blob/master/LICENSE-MIT | ||
*/ | ||
var path = require('path'); | ||
@@ -4,0 +13,0 @@ var index = require('./index'); |
11
index.js
@@ -0,1 +1,12 @@ | ||
/* | ||
* node-htmlprocessor | ||
* https://github.com/dciccale/node-htmlprocessor | ||
* | ||
* Copyright (c) 2013-2014 Denis Ciccale (@tdecs) | ||
* Licensed under the MIT license. | ||
* https://github.com/dciccale/node-htmlprocessor/blob/master/LICENSE-MIT | ||
*/ | ||
'use strict'; | ||
var path = require('path'); | ||
@@ -2,0 +13,0 @@ var fs = require('fs'); |
@@ -0,1 +1,12 @@ | ||
/* | ||
* node-htmlprocessor | ||
* https://github.com/dciccale/node-htmlprocessor | ||
* | ||
* Copyright (c) 2013-2014 Denis Ciccale (@tdecs) | ||
* Licensed under the MIT license. | ||
* https://github.com/dciccale/node-htmlprocessor/blob/master/LICENSE-MIT | ||
*/ | ||
'use strict'; | ||
var fs = require('fs'); | ||
@@ -7,3 +18,2 @@ var path = require('path'); | ||
module.exports = { | ||
css: function (content, block, blockLine, blockContent) { | ||
@@ -47,3 +57,3 @@ return content.replace(blockLine, block.indent + '<link rel="stylesheet" href="' + block.asset + '">'); | ||
template: function (content, block, blockLine, blockContent) { | ||
var compiledTmpl = utils.template(blockContent, this.data, this.options.templateSettings); | ||
var compiledTmpl = utils._.template(blockContent, this.data, this.options.templateSettings); | ||
@@ -58,14 +68,14 @@ // Clean template output and fix indent | ||
var base = this.options.includeBase || path.dirname(filepath); | ||
var filepath = path.join(base, block.asset); | ||
var assetpath = path.join(base, block.asset); | ||
var l = blockLine.length; | ||
var fileContent, i; | ||
if (fs.existsSync(filepath)) { | ||
if (fs.existsSync(assetpath)) { | ||
// Recursively process included files | ||
if (this.options.recursive) { | ||
fileContent = this.process(filepath); | ||
fileContent = this.process(assetpath); | ||
} else { | ||
fileContent = fs.readFileSync(filepath).toString(); | ||
fileContent = fs.readFileSync(assetpath).toString(); | ||
} | ||
@@ -72,0 +82,0 @@ |
@@ -20,4 +20,4 @@ /* | ||
* <!-- build:<type>[:target] [value] --> | ||
* - type (required) js, css, href, remove, template | ||
* - target|attribute i.e. dev, release or [href] [src] | ||
* - type (required) js, css, attr, remove, template, include | ||
* - target|attribute (optional) i.e. dev, prod, release or attributes like [href] [src] | ||
* - value (optional) i.e. script.min.js | ||
@@ -81,3 +81,2 @@ */ | ||
this.options = utils._.extend({}, defaults, options); | ||
this.target = this.options.environment; | ||
this.data = utils._.extend({}, this.options.data, {environment: this.options.environment}); | ||
@@ -87,3 +86,3 @@ | ||
if (this.options.customBlockTypes.length) { | ||
utils._.each(this.options.customBlockTypes, function (processor) { | ||
this.options.customBlockTypes.forEach(function (processor) { | ||
require(path.resolve(processor)).call(this, this); | ||
@@ -115,3 +114,4 @@ | ||
var blockContent = this._getBlockContent(block); | ||
var result = this._blockTypes[block.type].call(this, content, block, blockLine, blockContent, filepath); | ||
var result = this._blockTypes[block.type].call(this, content, block, blockLine, blockContent, | ||
filepath); | ||
@@ -121,3 +121,3 @@ return result; | ||
// Strips blocks not matched for the current target | ||
// Strips blocks not matched for the current environment | ||
HTMLProcessor.prototype._strip = function (block, content) { | ||
@@ -138,4 +138,5 @@ var blockLine = this._getBlockLine(block); | ||
// Parse through correct block type checking the build target | ||
if (this._blockTypes[block.type] && (!block.targets || utils._.indexOf(block.targets, this.target) >= 0)) { | ||
// Parse through correct block type checking the build environment | ||
if (this._blockTypes[block.type] && (!block.targets || | ||
utils._.indexOf(block.targets, this.options.environment) >= 0)) { | ||
result = this._replace(block, result, filepath); | ||
@@ -164,3 +165,5 @@ } else if (this.options.strip) { | ||
HTMLProcessor.prototype.template = utils._.template; | ||
// Export the processor | ||
module.exports = HTMLProcessor; |
@@ -27,6 +27,2 @@ /* | ||
utils.template = function (tmpl, data, options) { | ||
return _.template(tmpl, data, options); | ||
}; | ||
utils.read = function (filepath, encoding) { | ||
@@ -33,0 +29,0 @@ var contents; |
{ | ||
"name": "htmlprocessor", | ||
"description": "Process html file using special comments", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Denis Ciccale", |
@@ -7,7 +7,7 @@ # htmlprocessor | ||
This module was originally merged into the [grunt-processhtml](github.com/dciccale/grunt-processhtml) task. | ||
This module was originally merged into the [grunt-processhtml](http://github.com/dciccale/grunt-processhtml) task. | ||
Now its a standalone module without grunt dependency. | ||
For plenty of documentation please visit [grunt-processhtml](github.com/dciccale/grunt-processhtml) | ||
For plenty of documentation please visit [grunt-processhtml](http://github.com/dciccale/grunt-processhtml) | ||
@@ -14,0 +14,0 @@ ## CLI |
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
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
40396
537