underscore-template-loader
Advanced tools
Comparing version 0.2.1 to 0.2.2
80
index.js
var _ = require('underscore'); | ||
var loaderUtils = require('loader-utils'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
function resolveContent(content, root) { | ||
var includeRegex = /<!--include\s+([\/\w\.]*?[\w]+\.[\w]+)-->/g; | ||
var matches = includeRegex.exec(content); | ||
module.exports = function() { | ||
var loaderUtils = require('loader-utils'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var includeRegex = /<!--include\s+([\/\w\.]*?[\w]+\.[\w]+)-->/g; | ||
var readFile = function(filepath, root) { | ||
var self = readFile; | ||
self.buffer = {} || self.buffer; | ||
if (filepath in self.buffer) { | ||
return self.buffer[filepath]; | ||
} | ||
var content = resolveContent(fs.readFileSync(path.join(root, filepath), 'utf8'), root); | ||
self.buffer[filepath] = content; | ||
return self.buffer[filepath]; | ||
}; | ||
var readContent = function(content, root) { | ||
var matches = includeRegex.exec(content); | ||
while (matches != null) { | ||
var file = loaderUtils.urlToRequest(matches[1]); | ||
var basename = path.basename(file); | ||
var dirname = path.join(root, path.dirname(file)); | ||
var rawContent = readFile(basename, dirname); | ||
content = content.replace(matches[0], rawContent); | ||
matches = includeRegex.exec(content); | ||
} | ||
while (matches != null) { | ||
var file = loaderUtils.urlToRequest(matches[1]); | ||
var rawContent = readFile(path.basename(file), path.join(root, path.dirname(file))); | ||
content = content.replace(matches[0], rawContent); | ||
matches = includeRegex.exec(content); | ||
} | ||
return content; | ||
} | ||
return content; | ||
}; | ||
return function(content) { | ||
this.cacheable && this.cacheable(); | ||
var callback = this.async(); | ||
content = readContent(content, this.context); | ||
var fn = _.template(content); | ||
callback(null, "module.exports = " + fn.source + ";"); | ||
}; | ||
}(); | ||
function readFile(filepath, root) { | ||
var self = readFile; | ||
if (typeof(self.buffer) == "undefined") { | ||
self.buffer = {}; | ||
} | ||
if (filepath in self.buffer) { | ||
return self.buffer[filepath]; | ||
} | ||
var content = resolveContent(fs.readFileSync(path.join(root, filepath), 'utf8'), root); | ||
self.buffer[filepath] = content; | ||
return self.buffer[filepath]; | ||
} | ||
module.exports = function(content) { | ||
this.cacheable && this.cacheable(); | ||
var callback = this.async(); | ||
content = resolveContent(content, this.context); | ||
var fn = _.template(content); | ||
callback(null, "module.exports = " + fn.source + ";"); | ||
}; | ||
module.exports._ = _; | ||
module.exports._ = _; |
{ | ||
"name": "underscore-template-loader", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "A Underscore template loader for Webpack", | ||
@@ -19,5 +19,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"underscore": "^1.6.0", | ||
"loader-utils": "^0.2.5" | ||
}, | ||
"peerDependencies": { | ||
"underscore": "^1.6.0" | ||
}, | ||
"keywords": [ | ||
@@ -31,2 +33,2 @@ "underscore", | ||
"readmeFilename": "README.md" | ||
} | ||
} |
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
4414
35
- Removedunderscore@^1.6.0