mirror of
https://github.com/HackPlan/gulp-angular-cloak.git
synced 2026-01-12 22:44:20 +08:00
update packages and extract angular-html5
This commit is contained in:
34
index.js
34
index.js
@@ -6,33 +6,9 @@ module.exports = function (params) {
|
||||
//perhaps in the future
|
||||
params = params || {};
|
||||
var verbose = params.verbose || false;
|
||||
var customPrefixes = params.customPrefixes || [];
|
||||
|
||||
//find ng-something by default
|
||||
var prefix = 'ng-';
|
||||
//optionally add custom prefixes
|
||||
if (customPrefixes && customPrefixes.length) {
|
||||
var additions = customPrefixes.join('|');
|
||||
prefix += '|';
|
||||
prefix += additions;
|
||||
}
|
||||
|
||||
//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(allowedPreChars + prefix + '(\\w+)', 'ig');
|
||||
|
||||
//replace with data-ng-something
|
||||
var replaceStr = '$1data-$2$3';
|
||||
var htmlify = require('angular-html5')({
|
||||
customPrefixes: params.customPrefixes
|
||||
});
|
||||
|
||||
return through.obj(function (file, enc, cb) {
|
||||
//pass through
|
||||
@@ -49,8 +25,8 @@ module.exports = function (params) {
|
||||
|
||||
var data = file.contents.toString('utf8');
|
||||
//if ng-directives exist
|
||||
if (replaceRegex.test(data)) {
|
||||
data = data.replace(replaceRegex, replaceStr);
|
||||
if (htmlify.test(data)) {
|
||||
data = htmlify.replace(data);
|
||||
//put contents back
|
||||
file.contents = new Buffer(data);
|
||||
if (verbose) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) [2014] [Gilad Peleg]
|
||||
Copyright (©) 2014 Gilad Peleg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
||||
@@ -36,10 +36,12 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"mocha": "^1.20.0"
|
||||
"gulp-util": "^2.2.16",
|
||||
"mocha": "^1.20.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"angular-html5": "^0.1.1",
|
||||
"gulp-util": "^2.2.14",
|
||||
"through2": "^0.4.2"
|
||||
"through2": "^0.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ You can add additional prefixes using the option `customPrefixes`.
|
||||
|
||||
This plugin plays nice with `type="text/ng-template"` and won't break it.
|
||||
|
||||
*Issues with the output should be reported on the ng-annotate [issue tracker](https://github.com/pgilad/angular-html5/issues).*
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://npmjs.org/package/gulp-angular-htmlify)
|
||||
|
||||
Reference in New Issue
Block a user