nested-html-loader
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -18,6 +18,8 @@ /* | ||
//preprocess html with nested html file link. | ||
content = preprocessNestedHtml(content, this.resourcePath); | ||
this.cacheable && this.cacheable(); | ||
var query = loaderUtils.parseQuery(this.query); | ||
content = preprocessNestedHtml(content, this.resourcePath, query); | ||
var attributes = ["img:src"]; | ||
@@ -24,0 +26,0 @@ if(query.attrs !== undefined) { |
var fs = require("fs"); | ||
var path = require("path"); | ||
var replaceReg = /\{\{\include\:(.*?)}\}/g; | ||
var replaceReg = /\{\{include\:(.*?)\}\}/g; | ||
var conditionReg = /\{\{if\:\s*(.*?)\s*\}\}([\s\S]*?)\{\{\/if\s*\}\}/g; | ||
@@ -16,4 +17,3 @@ function readFileContentByPath(path) { | ||
module.exports = function preprocessNestedHtml(content, physicalPath){ | ||
var dir = path.dirname(physicalPath); | ||
function handleInclude(content, dir) { | ||
content = content.replace(replaceReg, function(match, rpath){ | ||
@@ -32,2 +32,21 @@ var actualPath; | ||
return content; | ||
} | ||
} | ||
function handleCondition(content, query) { | ||
content = content.replace(conditionReg, function(match, expr, markup){ | ||
if(query[expr]) { | ||
return markup; | ||
} | ||
return ''; | ||
}); | ||
return content; | ||
} | ||
function preprocessNestedHtml(content, physicalPath, query){ | ||
var dir = path.dirname(physicalPath); | ||
content = handleInclude(content, dir); | ||
content = handleCondition(content, query); | ||
return content; | ||
} | ||
module.exports = preprocessNestedHtml |
{ | ||
"name": "nested-html-loader", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "Daniel @hujiang.com", | ||
@@ -5,0 +5,0 @@ "description": "html loader module for webpack with additional fetures", |
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
8399
150