htmltemplate-transform
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "htmltemplate-transform", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Pluggable transforms for HTML::Template", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var fs = require('fs'); | ||
var path = require('path'); | ||
var crypto = require('crypto'); | ||
var assert = require('assert'); | ||
@@ -13,3 +12,2 @@ | ||
var resolvePath = options.resolvePath; | ||
var hashTemplateFileName = options.hashTemplateFileName || hash; | ||
@@ -30,2 +28,4 @@ assert(Array.isArray(tags), 'Expected options.includeTags to be an array of available include tags.'); | ||
if (this.isRoot && !isNested) { | ||
this.state.parentFilePath = this.state.rootFilepath; | ||
this.after(function(root) { | ||
@@ -64,5 +64,11 @@ this.update( | ||
var include = resolvePath(node.name, state.rootFilepath, filename); | ||
var id = hashTemplateFileName(include); | ||
var include = resolvePath(node.name, state.parentFilePath, filename); | ||
var id = filepathAsBlockId( | ||
// Resolving the included filepath against root filepath to | ||
// have both human-readable output and disregard project | ||
// location. | ||
path.relative(path.dirname(state.rootFilepath), include) | ||
); | ||
var ast = parser.parse( | ||
@@ -75,3 +81,3 @@ fs.readFileSync(include, 'utf8'), | ||
this.state = assign({}, state, { | ||
rootFilepath: include | ||
parentFilePath: include | ||
}); | ||
@@ -126,6 +132,6 @@ | ||
function hash(string) { | ||
return 'block_' + crypto.createHash('md5').update(string).digest('hex'); | ||
function filepathAsBlockId(string) { | ||
return string.replace(/[^a-zA-Z0-9_]/g, '_'); | ||
} | ||
module.exports = inline; |
@@ -8,3 +8,3 @@ [ | ||
"type": "SingleAttribute", | ||
"name": "nested-include_inc" | ||
"name": "inc_nested_include_inc" | ||
} | ||
@@ -59,3 +59,3 @@ ], | ||
"type": "SingleAttribute", | ||
"name": "include_inc" | ||
"name": "inc_include_inc" | ||
} | ||
@@ -83,3 +83,3 @@ ], | ||
"type": "SingleAttribute", | ||
"name": "nested-include_inc" | ||
"name": "inc_nested_include_inc" | ||
}, | ||
@@ -158,3 +158,3 @@ { | ||
"type": "SingleAttribute", | ||
"name": "include_inc" | ||
"name": "inc_include_inc" | ||
} | ||
@@ -177,3 +177,3 @@ ] | ||
"type": "SingleAttribute", | ||
"name": "nested-include_inc" | ||
"name": "inc_nested_include_inc" | ||
}, | ||
@@ -180,0 +180,0 @@ { |
@@ -26,7 +26,2 @@ var fs = require('fs'); | ||
return path.resolve(path.dirname(from), to); | ||
}, | ||
// NOTE: This is just to make sure that tests have the same | ||
// regardless of project location. | ||
hashTemplateFileName: function(filename) { | ||
return path.basename(filename).replace(/\./, '_'); | ||
} | ||
@@ -33,0 +28,0 @@ }) |
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
37172
1075