-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
335 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1 @@ | ||
/*! art-template@runtime | https://github.com/aui/art-template */ | ||
|
||
|
||
/** | ||
* 迭代器,支持数组与对象 | ||
* @param {array|Object} data | ||
* @param {function} callback | ||
*/ | ||
var each = function each(data, callback) { | ||
if (Array.isArray(data)) { | ||
for (var i = 0, len = data.length; i < len; i++) { | ||
callback(data[i], i, data); | ||
} | ||
} else { | ||
for (var _i in data) { | ||
callback(data[_i], _i); | ||
} | ||
} | ||
}; | ||
|
||
|
||
// 将目标转成字符 | ||
var toString = function toString(value) { | ||
if (typeof value !== 'string') { | ||
if (value === undefined || value === null) { | ||
value = ''; | ||
} else if (typeof value === 'function') { | ||
value = toString(value.call(value)); | ||
} else { | ||
value = JSON.stringify(value); | ||
} | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
|
||
// 编码 HTML 内容 | ||
var ESCAPE_REG = /["&'<>]/; | ||
var xmlEscape = function xmlEscape(content) { | ||
var html = '' + content; | ||
var regexResult = ESCAPE_REG.exec(html); | ||
if (!regexResult) { | ||
return content; | ||
} | ||
|
||
var result = ''; | ||
var i = void 0, | ||
lastIndex = void 0, | ||
char = void 0; | ||
for (i = regexResult.index, lastIndex = 0; i < html.length; i++) { | ||
|
||
switch (html.charCodeAt(i)) { | ||
case 34: | ||
char = '"'; | ||
break; | ||
case 38: | ||
char = '&'; | ||
break; | ||
case 39: | ||
char = '''; | ||
break; | ||
case 60: | ||
char = '<'; | ||
break; | ||
case 62: | ||
char = '>'; | ||
break; | ||
default: | ||
continue; | ||
} | ||
|
||
if (lastIndex !== i) { | ||
result += html.substring(lastIndex, i); | ||
} | ||
|
||
lastIndex = i + 1; | ||
result += char; | ||
} | ||
|
||
if (lastIndex !== i) { | ||
return result + html.substring(lastIndex, i); | ||
} else { | ||
return result; | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* 编码模板输出的内容 | ||
* @param {any} content | ||
* @return {string} | ||
*/ | ||
var escape = function escape(content) { | ||
return xmlEscape(toString(content)); | ||
}; | ||
|
||
|
||
var imports = { | ||
$each: each, | ||
$escape: escape | ||
}; | ||
|
||
|
||
module.exports = imports; | ||
module.exports = require('./runtime'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.