mirror of
https://github.com/HackPlan/gulp-angular-cloak.git
synced 2026-01-12 22:44:20 +08:00
better prechars handling including ng-template script
This commit is contained in:
15
fixtures/angular-templates.html
Normal file
15
fixtures/angular-templates.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html ng-app="myApp">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>fixture</title>
|
||||
<script type="text/ng-template" id="/tpl.html"> </script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
9
index.js
9
index.js
@@ -9,7 +9,7 @@ module.exports = function (params) {
|
||||
var customPrefixes = params.customPrefixes || [];
|
||||
|
||||
//find ng-something by default
|
||||
var prefix = '[^\/]ng-'; //Denis Bondarenko changed to support templates, inlined with script tag like ...type="text/ng-template"
|
||||
var prefix = 'ng-';
|
||||
//optionally add custom prefixes
|
||||
if (customPrefixes && customPrefixes.length) {
|
||||
var additions = customPrefixes.join('|');
|
||||
@@ -20,11 +20,16 @@ module.exports = function (params) {
|
||||
//wrap around to insert into replace str later
|
||||
prefix = '(' + prefix + '){1}';
|
||||
|
||||
//handle the following:
|
||||
//1. ' ng-'
|
||||
//2. '<ng-'
|
||||
//3. '</ng-'
|
||||
var allowedPreChars = '(\\s|<|<\/){1}';
|
||||
//build find/replace regex
|
||||
//$1 -> allowable pre-chars
|
||||
//$2 -> prefix match
|
||||
//$3 -> actual directive (partially)
|
||||
var replaceRegex = new RegExp('([\\s<\/]+)' + prefix + '(\\w+)', 'ig');
|
||||
var replaceRegex = new RegExp(allowedPreChars + prefix + '(\\w+)', 'ig');
|
||||
|
||||
//replace with data-ng-something
|
||||
var replaceStr = '$1data-$2$3';
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"bugs": "https://github.com/pgilad/gulp-angular-htmlify/issues",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"watchTest": "mocha --watch",
|
||||
"watchTest": "mocha -R spec --watch",
|
||||
"test": "mocha"
|
||||
},
|
||||
"keywords": [
|
||||
|
||||
24
test.js
24
test.js
@@ -143,3 +143,27 @@ it('should work with custom prefixes', function (cb) {
|
||||
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should not modify ng-template script', function (cb) {
|
||||
var stream = htmlify();
|
||||
var filename = './fixtures/angular-templates.html';
|
||||
|
||||
stream.on('data', function (file) {
|
||||
//make sure ng-app turned into data-ng-app
|
||||
var contents = file.contents.toString('utf8');
|
||||
//validate that ng-templates don't change
|
||||
assert(/type="text\/ng-template"/.test(contents));
|
||||
});
|
||||
|
||||
stream.on('end', cb);
|
||||
|
||||
var testFile = fs.readFileSync(filename);
|
||||
|
||||
stream.write(new gutil.File({
|
||||
path: filename,
|
||||
cwd: '.',
|
||||
contents: new Buffer(testFile.toString())
|
||||
}));
|
||||
|
||||
stream.end();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user