PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/webapp/lib/yui3/build/template-micro/template-micro-coverage.js

https://gitlab.com/fxaeberhard/Wedance-java
JavaScript | 294 lines | 118 code | 24 blank | 152 comment | 7 complexity | 23410009b7f2fe23311350918cfa2219 MD5 | raw file
  1. /*
  2. YUI 3.8.0 (build 5744)
  3. Copyright 2012 Yahoo! Inc. All rights reserved.
  4. Licensed under the BSD License.
  5. http://yuilibrary.com/license/
  6. */
  7. if (typeof _yuitest_coverage == "undefined"){
  8. _yuitest_coverage = {};
  9. _yuitest_coverline = function(src, line){
  10. var coverage = _yuitest_coverage[src];
  11. if (!coverage.lines[line]){
  12. coverage.calledLines++;
  13. }
  14. coverage.lines[line]++;
  15. };
  16. _yuitest_coverfunc = function(src, name, line){
  17. var coverage = _yuitest_coverage[src],
  18. funcId = name + ":" + line;
  19. if (!coverage.functions[funcId]){
  20. coverage.calledFunctions++;
  21. }
  22. coverage.functions[funcId]++;
  23. };
  24. }
  25. _yuitest_coverage["build/template-micro/template-micro.js"] = {
  26. lines: {},
  27. functions: {},
  28. coveredLines: 0,
  29. calledLines: 0,
  30. coveredFunctions: 0,
  31. calledFunctions: 0,
  32. path: "build/template-micro/template-micro.js",
  33. code: []
  34. };
  35. _yuitest_coverage["build/template-micro/template-micro.js"].code=["YUI.add('template-micro', function (Y, NAME) {","","/**","Adds the `Y.Template.Micro` template engine, which provides fast, simple","string-based micro-templating similar to ERB or Underscore templates.","","@module template","@submodule template-micro","@since 3.8.0","**/","","/**","Fast, simple string-based micro-templating engine similar to ERB or Underscore","templates.","","@class Template.Micro","@static","@since 3.8.0","**/","","// This code was heavily inspired by Underscore.js's _.template() method","// (written by Jeremy Ashkenas), which was in turn inspired by John Resig's","// micro-templating implementation.","","var Micro = Y.namespace('Template.Micro');","","/**","Default options for `Y.Template.Micro`.","","@property {Object} options",""," @param {RegExp} [options.code] Regex that matches code blocks like"," `<% ... %>`."," @param {RegExp} [options.escapedOutput] Regex that matches escaped output"," tags like `<%= ... %>`."," @param {RegExp} [options.rawOutput] Regex that matches raw output tags like"," `<%== ... %>`."," @param {RegExp} [options.stringEscape] Regex that matches characters that"," need to be escaped inside single-quoted JavaScript string literals.","","@static","@since 3.8.0","**/","Micro.options = {"," code : /<%([\\s\\S]+?)%>/g,"," escapedOutput: /<%=([\\s\\S]+?)%>/g,"," rawOutput : /<%==([\\s\\S]+?)%>/g,"," stringEscape : /\\\\|'|\\r|\\n|\\t|\\u2028|\\u2029/g","};","","/**","Compiles a template string into a JavaScript function. Pass a data object to the","function to render the template using the given data and get back a rendered","string.","","Within a template, use `<%= ... %>` to output the value of an expression (where","`...` is the JavaScript expression or data variable to evaluate). The output","will be HTML-escaped by default. To output a raw value without escaping, use","`<%== ... %>`, but be careful not to do this with untrusted user input.","","To execute arbitrary JavaScript code within the template without rendering its","output, use `<% ... %>`, where `...` is the code to be executed. This allows the","use of if/else blocks, loops, function calls, etc., although it's recommended","that you avoid embedding anything beyond basic flow control logic in your","templates.","","Properties of the data object passed to a template function are made available","on a `data` variable within the scope of the template. So, if you pass in","the object `{message: 'hello!'}`, you can print the value of the `message`","property using `<%= data.message %>`.","","@example",""," YUI().use('template-micro', function (Y) {"," var template = '<ul class=\"<%= data.classNames.list %>\">' +"," '<% Y.Array.each(data.items, function (item) { %>' +"," '<li><%= item %></li>' +"," '<% }); %>' +"," '</ul>';",""," // Compile the template into a function."," var compiled = Y.Template.Micro.compile(template);",""," // Render the template to HTML, passing in the data to use."," var html = compiled({"," classNames: {list: 'demo'},"," items : ['one', 'two', 'three', 'four']"," });"," });","","@method compile","@param {String} text Template text to compile.","@param {Object} [options] Options. If specified, these options will override the"," default options defined in `Y.Template.Micro.options`. See the documentation"," for that property for details on which options are available.","@return {Function} Compiled template function. Execute this function and pass in"," a data object to render the template with the given data.","@static","@since 3.8.0","**/","Micro.compile = function (text, options) {"," var blocks = [],"," tokenClose = \"\\uffff\","," tokenOpen = \"\\ufffe\","," source;",""," options = Y.merge(Micro.options, options);",""," // Parse the input text into a string of JavaScript code, with placeholders"," // for code blocks. Text outside of code blocks will be escaped for safe"," // usage within a double-quoted string literal."," source = \"var $b='',$t='\" +",""," // U+FFFE and U+FFFF are guaranteed to represent non-characters, so no"," // valid UTF-8 string should ever contain them. That means we can freely"," // strip them out of the input text (just to be safe) and then use them"," // for our own nefarious purposes as token placeholders!"," //"," // See http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Noncharacters"," text.replace(/\\ufffe|\\uffff/g, '')",""," .replace(options.rawOutput, function (match, code) {"," return tokenOpen + (blocks.push(\"'+\\n((\" + code + \")||$b)+\\n'\") - 1) + tokenClose;"," })",""," .replace(options.escapedOutput, function (match, code) {"," return tokenOpen + (blocks.push(\"'+\\n$e((\" + code + \")||$b)+\\n'\") - 1) + tokenClose;"," })",""," .replace(options.code, function (match, code) {"," return tokenOpen + (blocks.push(\"';\\n\" + code + \"\\n$t+='\") - 1) + tokenClose;"," })",""," .replace(options.stringEscape, \"\\\\$&\")",""," // Replace the token placeholders with code."," .replace(/\\ufffe(\\d+)\\uffff/g, function (match, index) {"," return blocks[parseInt(index, 10)];"," })",""," // Remove noop string concatenations that have been left behind."," .replace(/\\n\\$t\\+='';\\n/g, '\\n') +",""," \"';\\nreturn $t;\";",""," // If compile() was called from precompile(), return precompiled source."," if (options.precompile) {"," return \"function (Y, $e, data) {\\n\" + source + \"\\n}\";"," }",""," // Otherwise, return an executable function."," return this.revive(new Function('Y', '$e', 'data', source));","};","","/**","Precompiles the given template text into a string of JavaScript source code that","can be evaluated later in another context (or on another machine) to render the","template.","","A common use case is to precompile templates at build time or on the server,","then evaluate the code on the client to render a template. The client only needs","to revive and render the template, avoiding the work of the compilation step.","","@method precompile","@param {String} text Template text to precompile.","@param {Object} [options] Options. If specified, these options will override the"," default options defined in `Y.Template.Micro.options`. See the documentation"," for that property for details on which options are available.","@return {String} Source code for the precompiled template.","@static","@since 3.8.0","**/","Micro.precompile = function (text, options) {"," options || (options = {});"," options.precompile = true;",""," return this.compile(text, options);","};","","/**","Compiles and renders the given template text in a single step.","","This can be useful for single-use templates, but if you plan to render the same","template multiple times, it's much better to use `compile()` to compile it once,","then simply call the compiled function multiple times to avoid recompiling.","","@method render","@param {String} text Template text to render.","@param {Object} data Data to pass to the template.","@param {Object} [options] Options. If specified, these options will override the"," default options defined in `Y.Template.Micro.options`. See the documentation"," for that property for details on which options are available.","@return {String} Rendered result.","@static","@since 3.8.0","**/","Micro.render = function (text, data, options) {"," return this.compile(text, options)(data);","};","","/**","Revives a precompiled template function into a normal compiled template function","that can be called to render the template. The precompiled function must already","have been evaluated to a function -- you can't pass raw JavaScript code to","`revive()`.","","@method revive","@param {Function} precompiled Precompiled template function.","@return {Function} Revived template function, ready to be rendered.","@static","@since 3.8.0","**/","Micro.revive = function (precompiled) {"," return function (data) {"," data || (data = {});"," return precompiled.call(data, Y, Y.Escape.html, data);"," };","};","","","}, '3.8.0', {\"requires\": [\"escape\"]});"];
  36. _yuitest_coverage["build/template-micro/template-micro.js"].lines = {"1":0,"25":0,"44":0,"101":0,"102":0,"107":0,"112":0,"123":0,"127":0,"131":0,"138":0,"147":0,"148":0,"152":0,"173":0,"174":0,"175":0,"177":0,"197":0,"198":0,"213":0,"214":0,"215":0,"216":0};
  37. _yuitest_coverage["build/template-micro/template-micro.js"].functions = {"(anonymous 2):122":0,"(anonymous 3):126":0,"(anonymous 4):130":0,"(anonymous 5):137":0,"compile:101":0,"precompile:173":0,"render:197":0,"(anonymous 6):214":0,"revive:213":0,"(anonymous 1):1":0};
  38. _yuitest_coverage["build/template-micro/template-micro.js"].coveredLines = 24;
  39. _yuitest_coverage["build/template-micro/template-micro.js"].coveredFunctions = 10;
  40. _yuitest_coverline("build/template-micro/template-micro.js", 1);
  41. YUI.add('template-micro', function (Y, NAME) {
  42. /**
  43. Adds the `Y.Template.Micro` template engine, which provides fast, simple
  44. string-based micro-templating similar to ERB or Underscore templates.
  45. @module template
  46. @submodule template-micro
  47. @since 3.8.0
  48. **/
  49. /**
  50. Fast, simple string-based micro-templating engine similar to ERB or Underscore
  51. templates.
  52. @class Template.Micro
  53. @static
  54. @since 3.8.0
  55. **/
  56. // This code was heavily inspired by Underscore.js's _.template() method
  57. // (written by Jeremy Ashkenas), which was in turn inspired by John Resig's
  58. // micro-templating implementation.
  59. _yuitest_coverfunc("build/template-micro/template-micro.js", "(anonymous 1)", 1);
  60. _yuitest_coverline("build/template-micro/template-micro.js", 25);
  61. var Micro = Y.namespace('Template.Micro');
  62. /**
  63. Default options for `Y.Template.Micro`.
  64. @property {Object} options
  65. @param {RegExp} [options.code] Regex that matches code blocks like
  66. `<% ... %>`.
  67. @param {RegExp} [options.escapedOutput] Regex that matches escaped output
  68. tags like `<%= ... %>`.
  69. @param {RegExp} [options.rawOutput] Regex that matches raw output tags like
  70. `<%== ... %>`.
  71. @param {RegExp} [options.stringEscape] Regex that matches characters that
  72. need to be escaped inside single-quoted JavaScript string literals.
  73. @static
  74. @since 3.8.0
  75. **/
  76. _yuitest_coverline("build/template-micro/template-micro.js", 44);
  77. Micro.options = {
  78. code : /<%([\s\S]+?)%>/g,
  79. escapedOutput: /<%=([\s\S]+?)%>/g,
  80. rawOutput : /<%==([\s\S]+?)%>/g,
  81. stringEscape : /\\|'|\r|\n|\t|\u2028|\u2029/g
  82. };
  83. /**
  84. Compiles a template string into a JavaScript function. Pass a data object to the
  85. function to render the template using the given data and get back a rendered
  86. string.
  87. Within a template, use `<%= ... %>` to output the value of an expression (where
  88. `...` is the JavaScript expression or data variable to evaluate). The output
  89. will be HTML-escaped by default. To output a raw value without escaping, use
  90. `<%== ... %>`, but be careful not to do this with untrusted user input.
  91. To execute arbitrary JavaScript code within the template without rendering its
  92. output, use `<% ... %>`, where `...` is the code to be executed. This allows the
  93. use of if/else blocks, loops, function calls, etc., although it's recommended
  94. that you avoid embedding anything beyond basic flow control logic in your
  95. templates.
  96. Properties of the data object passed to a template function are made available
  97. on a `data` variable within the scope of the template. So, if you pass in
  98. the object `{message: 'hello!'}`, you can print the value of the `message`
  99. property using `<%= data.message %>`.
  100. @example
  101. YUI().use('template-micro', function (Y) {
  102. var template = '<ul class="<%= data.classNames.list %>">' +
  103. '<% Y.Array.each(data.items, function (item) { %>' +
  104. '<li><%= item %></li>' +
  105. '<% }); %>' +
  106. '</ul>';
  107. // Compile the template into a function.
  108. var compiled = Y.Template.Micro.compile(template);
  109. // Render the template to HTML, passing in the data to use.
  110. var html = compiled({
  111. classNames: {list: 'demo'},
  112. items : ['one', 'two', 'three', 'four']
  113. });
  114. });
  115. @method compile
  116. @param {String} text Template text to compile.
  117. @param {Object} [options] Options. If specified, these options will override the
  118. default options defined in `Y.Template.Micro.options`. See the documentation
  119. for that property for details on which options are available.
  120. @return {Function} Compiled template function. Execute this function and pass in
  121. a data object to render the template with the given data.
  122. @static
  123. @since 3.8.0
  124. **/
  125. _yuitest_coverline("build/template-micro/template-micro.js", 101);
  126. Micro.compile = function (text, options) {
  127. _yuitest_coverfunc("build/template-micro/template-micro.js", "compile", 101);
  128. _yuitest_coverline("build/template-micro/template-micro.js", 102);
  129. var blocks = [],
  130. tokenClose = "\uffff",
  131. tokenOpen = "\ufffe",
  132. source;
  133. _yuitest_coverline("build/template-micro/template-micro.js", 107);
  134. options = Y.merge(Micro.options, options);
  135. // Parse the input text into a string of JavaScript code, with placeholders
  136. // for code blocks. Text outside of code blocks will be escaped for safe
  137. // usage within a double-quoted string literal.
  138. _yuitest_coverline("build/template-micro/template-micro.js", 112);
  139. source = "var $b='',$t='" +
  140. // U+FFFE and U+FFFF are guaranteed to represent non-characters, so no
  141. // valid UTF-8 string should ever contain them. That means we can freely
  142. // strip them out of the input text (just to be safe) and then use them
  143. // for our own nefarious purposes as token placeholders!
  144. //
  145. // See http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Noncharacters
  146. text.replace(/\ufffe|\uffff/g, '')
  147. .replace(options.rawOutput, function (match, code) {
  148. _yuitest_coverfunc("build/template-micro/template-micro.js", "(anonymous 2)", 122);
  149. _yuitest_coverline("build/template-micro/template-micro.js", 123);
  150. return tokenOpen + (blocks.push("'+\n((" + code + ")||$b)+\n'") - 1) + tokenClose;
  151. })
  152. .replace(options.escapedOutput, function (match, code) {
  153. _yuitest_coverfunc("build/template-micro/template-micro.js", "(anonymous 3)", 126);
  154. _yuitest_coverline("build/template-micro/template-micro.js", 127);
  155. return tokenOpen + (blocks.push("'+\n$e((" + code + ")||$b)+\n'") - 1) + tokenClose;
  156. })
  157. .replace(options.code, function (match, code) {
  158. _yuitest_coverfunc("build/template-micro/template-micro.js", "(anonymous 4)", 130);
  159. _yuitest_coverline("build/template-micro/template-micro.js", 131);
  160. return tokenOpen + (blocks.push("';\n" + code + "\n$t+='") - 1) + tokenClose;
  161. })
  162. .replace(options.stringEscape, "\\$&")
  163. // Replace the token placeholders with code.
  164. .replace(/\ufffe(\d+)\uffff/g, function (match, index) {
  165. _yuitest_coverfunc("build/template-micro/template-micro.js", "(anonymous 5)", 137);
  166. _yuitest_coverline("build/template-micro/template-micro.js", 138);
  167. return blocks[parseInt(index, 10)];
  168. })
  169. // Remove noop string concatenations that have been left behind.
  170. .replace(/\n\$t\+='';\n/g, '\n') +
  171. "';\nreturn $t;";
  172. // If compile() was called from precompile(), return precompiled source.
  173. _yuitest_coverline("build/template-micro/template-micro.js", 147);
  174. if (options.precompile) {
  175. _yuitest_coverline("build/template-micro/template-micro.js", 148);
  176. return "function (Y, $e, data) {\n" + source + "\n}";
  177. }
  178. // Otherwise, return an executable function.
  179. _yuitest_coverline("build/template-micro/template-micro.js", 152);
  180. return this.revive(new Function('Y', '$e', 'data', source));
  181. };
  182. /**
  183. Precompiles the given template text into a string of JavaScript source code that
  184. can be evaluated later in another context (or on another machine) to render the
  185. template.
  186. A common use case is to precompile templates at build time or on the server,
  187. then evaluate the code on the client to render a template. The client only needs
  188. to revive and render the template, avoiding the work of the compilation step.
  189. @method precompile
  190. @param {String} text Template text to precompile.
  191. @param {Object} [options] Options. If specified, these options will override the
  192. default options defined in `Y.Template.Micro.options`. See the documentation
  193. for that property for details on which options are available.
  194. @return {String} Source code for the precompiled template.
  195. @static
  196. @since 3.8.0
  197. **/
  198. _yuitest_coverline("build/template-micro/template-micro.js", 173);
  199. Micro.precompile = function (text, options) {
  200. _yuitest_coverfunc("build/template-micro/template-micro.js", "precompile", 173);
  201. _yuitest_coverline("build/template-micro/template-micro.js", 174);
  202. options || (options = {});
  203. _yuitest_coverline("build/template-micro/template-micro.js", 175);
  204. options.precompile = true;
  205. _yuitest_coverline("build/template-micro/template-micro.js", 177);
  206. return this.compile(text, options);
  207. };
  208. /**
  209. Compiles and renders the given template text in a single step.
  210. This can be useful for single-use templates, but if you plan to render the same
  211. template multiple times, it's much better to use `compile()` to compile it once,
  212. then simply call the compiled function multiple times to avoid recompiling.
  213. @method render
  214. @param {String} text Template text to render.
  215. @param {Object} data Data to pass to the template.
  216. @param {Object} [options] Options. If specified, these options will override the
  217. default options defined in `Y.Template.Micro.options`. See the documentation
  218. for that property for details on which options are available.
  219. @return {String} Rendered result.
  220. @static
  221. @since 3.8.0
  222. **/
  223. _yuitest_coverline("build/template-micro/template-micro.js", 197);
  224. Micro.render = function (text, data, options) {
  225. _yuitest_coverfunc("build/template-micro/template-micro.js", "render", 197);
  226. _yuitest_coverline("build/template-micro/template-micro.js", 198);
  227. return this.compile(text, options)(data);
  228. };
  229. /**
  230. Revives a precompiled template function into a normal compiled template function
  231. that can be called to render the template. The precompiled function must already
  232. have been evaluated to a function -- you can't pass raw JavaScript code to
  233. `revive()`.
  234. @method revive
  235. @param {Function} precompiled Precompiled template function.
  236. @return {Function} Revived template function, ready to be rendered.
  237. @static
  238. @since 3.8.0
  239. **/
  240. _yuitest_coverline("build/template-micro/template-micro.js", 213);
  241. Micro.revive = function (precompiled) {
  242. _yuitest_coverfunc("build/template-micro/template-micro.js", "revive", 213);
  243. _yuitest_coverline("build/template-micro/template-micro.js", 214);
  244. return function (data) {
  245. _yuitest_coverfunc("build/template-micro/template-micro.js", "(anonymous 6)", 214);
  246. _yuitest_coverline("build/template-micro/template-micro.js", 215);
  247. data || (data = {});
  248. _yuitest_coverline("build/template-micro/template-micro.js", 216);
  249. return precompiled.call(data, Y, Y.Escape.html, data);
  250. };
  251. };
  252. }, '3.8.0', {"requires": ["escape"]});