|
3 __coverage__['build/template-base/template-base.js'] = {"path":"build/template-base/template-base.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":44}}},"2":{"name":"Template","line":54,"loc":{"start":{"line":54,"column":0},"end":{"line":54,"column":36}}},"3":{"name":"(anonymous_3)","line":127,"loc":{"start":{"line":127,"column":20},"end":{"line":127,"column":54}}},"4":{"name":"(anonymous_4)","line":144,"loc":{"start":{"line":144,"column":15},"end":{"line":144,"column":39}}},"5":{"name":"(anonymous_5)","line":177,"loc":{"start":{"line":177,"column":18},"end":{"line":177,"column":57}}},"6":{"name":"(anonymous_6)","line":202,"loc":{"start":{"line":202,"column":13},"end":{"line":202,"column":38}}},"7":{"name":"(anonymous_7)","line":218,"loc":{"start":{"line":218,"column":16},"end":{"line":218,"column":41}}},"8":{"name":"(anonymous_8)","line":235,"loc":{"start":{"line":235,"column":12},"end":{"line":235,"column":43}}},"9":{"name":"(anonymous_9)","line":257,"loc":{"start":{"line":257,"column":12},"end":{"line":257,"column":44}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":272,"column":44}},"2":{"start":{"line":54,"column":0},"end":{"line":74,"column":1}},"3":{"start":{"line":61,"column":4},"end":{"line":61,"column":29}},"4":{"start":{"line":69,"column":4},"end":{"line":69,"column":45}},"5":{"start":{"line":71,"column":4},"end":{"line":73,"column":5}},"6":{"start":{"line":72,"column":8},"end":{"line":72,"column":46}},"7":{"start":{"line":85,"column":0},"end":{"line":85,"column":24}},"8":{"start":{"line":127,"column":0},"end":{"line":130,"column":2}},"9":{"start":{"line":128,"column":4},"end":{"line":128,"column":48}},"10":{"start":{"line":129,"column":4},"end":{"line":129,"column":20}},"11":{"start":{"line":144,"column":0},"end":{"line":177,"column":0}},"12":{"start":{"line":145,"column":4},"end":{"line":145,"column":44}},"13":{"start":{"line":177,"column":0},"end":{"line":188,"column":2}},"14":{"start":{"line":178,"column":4},"end":{"line":179,"column":22}},"15":{"start":{"line":181,"column":4},"end":{"line":185,"column":5}},"16":{"start":{"line":182,"column":8},"end":{"line":182,"column":41}},"17":{"start":{"line":184,"column":8},"end":{"line":184,"column":65}},"18":{"start":{"line":187,"column":4},"end":{"line":187,"column":18}},"19":{"start":{"line":190,"column":0},"end":{"line":263,"column":2}},"20":{"start":{"line":203,"column":8},"end":{"line":203,"column":76}},"21":{"start":{"line":204,"column":8},"end":{"line":204,"column":50}},"22":{"start":{"line":219,"column":8},"end":{"line":219,"column":76}},"23":{"start":{"line":220,"column":8},"end":{"line":220,"column":53}},"24":{"start":{"line":236,"column":8},"end":{"line":236,"column":76}},"25":{"start":{"line":238,"column":8},"end":{"line":240,"column":9}},"26":{"start":{"line":239,"column":12},"end":{"line":239,"column":59}},"27":{"start":{"line":242,"column":8},"end":{"line":242,"column":65}},"28":{"start":{"line":258,"column":8},"end":{"line":258,"column":76}},"29":{"start":{"line":260,"column":8},"end":{"line":261,"column":28}},"30":{"start":{"line":269,"column":0},"end":{"line":269,"column":65}}},"branchMap":{"1":{"line":69,"type":"binary-expr","locations":[{"start":{"line":69,"column":18},"end":{"line":69,"column":24}},{"start":{"line":69,"column":28},"end":{"line":69,"column":44}}]},"2":{"line":71,"type":"if","locations":[{"start":{"line":71,"column":4},"end":{"line":71,"column":4}},{"start":{"line":71,"column":4},"end":{"line":71,"column":4}}]},"3":{"line":181,"type":"if","locations":[{"start":{"line":181,"column":4},"end":{"line":181,"column":4}},{"start":{"line":181,"column":4},"end":{"line":181,"column":4}}]},"4":{"line":203,"type":"cond-expr","locations":[{"start":{"line":203,"column":28},"end":{"line":203,"column":59}},{"start":{"line":203,"column":62},"end":{"line":203,"column":75}}]},"5":{"line":219,"type":"cond-expr","locations":[{"start":{"line":219,"column":28},"end":{"line":219,"column":59}},{"start":{"line":219,"column":62},"end":{"line":219,"column":75}}]},"6":{"line":236,"type":"cond-expr","locations":[{"start":{"line":236,"column":28},"end":{"line":236,"column":59}},{"start":{"line":236,"column":62},"end":{"line":236,"column":75}}]},"7":{"line":238,"type":"if","locations":[{"start":{"line":238,"column":8},"end":{"line":238,"column":8}},{"start":{"line":238,"column":8},"end":{"line":238,"column":8}}]},"8":{"line":258,"type":"cond-expr","locations":[{"start":{"line":258,"column":28},"end":{"line":258,"column":59}},{"start":{"line":258,"column":62},"end":{"line":258,"column":75}}]},"9":{"line":260,"type":"cond-expr","locations":[{"start":{"line":260,"column":36},"end":{"line":260,"column":76}},{"start":{"line":261,"column":16},"end":{"line":261,"column":27}}]},"10":{"line":269,"type":"cond-expr","locations":[{"start":{"line":269,"column":26},"end":{"line":269,"column":53}},{"start":{"line":269,"column":56},"end":{"line":269,"column":64}}]}},"code":["(function () { YUI.add('template-base', function (Y, NAME) {","","/**","Virtual rollup of the `template-base` and `template-micro` modules.","","@module template","@main template","@since 3.8.0","**/","","/**","Provides a generic API for using template engines such as Handlebars and","`Y.Template.Micro`.","","@module template","@submodule template-base","@since 3.8.0","**/","","/**","Provides a generic API for using template engines such as Handlebars and","`Y.Template.Micro`.","","### Examples","","Using with `Y.Template.Micro` (the default template engine):",""," YUI().use('template', function (Y) {"," var micro = new Y.Template(),"," html = micro.render('<%= data.message %>', {message: 'hello!'});",""," // ..."," });","","Using with Handlebars:",""," YUI().use('template-base', 'handlebars', function (Y) {"," var handlebars = new Y.Template(Y.Handlebars),"," html = handlebars.render('{{message}}', {message: 'hello!'});",""," // ..."," });","","@class Template","@param {Mixed} [engine=Y.Template.Micro] Template engine to use, such as"," `Y.Template.Micro` or `Y.Handlebars`. Defaults to `Y.Template.Micro` if not"," specified.","@param {Object} [defaults] Default options to use when instance methods are"," invoked.","@constructor","@since 3.8.0","**/","","function Template(engine, defaults) {"," /**"," Default options.",""," @property {Object} defaults"," @since 3.8.1"," **/"," this.defaults = defaults;",""," /**"," Template engine class.",""," @property {Mixed} engine"," @since 3.8.0"," **/"," this.engine = engine || Y.Template.Micro;",""," if (!this.engine) {"," Y.error('No template engine loaded.');"," }","}","","/**","Registry that maps template names to revived template functions.","","@property _registry","@type Object","@static","@protected","@since 3.12.0","**/","Template._registry = {};","","/**","Registers a pre-compiled template into the central template registry with a","given template string, allowing that template to be called and rendered by","that name using the `Y.Template.render()` static method.","","For example, given the following simple Handlebars template, in `foo.hbs`:","@example"," <p>{{tagline}}</p>","","It can be precompiled using the Handlebars CLI, and added into a YUI module","in the following way. Alternatively, `locator` can be used to automate this","process for you:","@example"," YUI.add('templates-foo', function (Y) {",""," var engine = new Y.Template(Y.Handlebars),"," precompiled;",""," precompiled = // Long precompiled template function here //",""," Y.Template.register('foo', engine.revive(precompiled));",""," }, '0.0.1', {requires: ['template-base', 'handlebars-base']});","","See the `Y.Template#render` method to see how a registered template is used.","","@method register","@param {String} templateName The template name.","@param {Function} template The function that returns the rendered string. The"," function should take the following parameters. If a pre-compiled template"," does not accept these parameters, it is up to the developer to normalize it."," @param {Object} [template.data] Data object to provide when rendering the"," template."," @param {Object} [template.options] Options to pass along to the template"," engine. See template engine docs for options supported by each engine.","@return {Function} revivedTemplate This is the same function as in `template`,"," and is done to maintain compatibility with the `Y.Template#revive()` method.","@static","@since 3.12.0","**/","Template.register = function (templateName, template) {"," Template._registry[templateName] = template;"," return template;","};","","/**","Returns the registered template function, given the template name. If an","unregistered template is accessed, this will return `undefined`.","","@method get","@param {String} templateName The template name.","@return {Function} revivedTemplate The revived template function, or `undefined`"," if it has not been registered.","@static","@since 3.12.0","**/","","Template.get = function (templateName) {"," return Template._registry[templateName];","}","","/**","Renders a template into a string, given the registered template name and data","to be interpolated. The template name must have been registered previously with","`register()`.","","Once the template has been registered and built into a YUI module, it can be","listed as a dependency for any other YUI module. Continuing from the above","example, the registered template can be used in the following way:","","@example"," YUI.add('bar', function (Y) {",""," var html = Y.Template.render('foo', {"," tagline: '\"bar\" is now template language agnostic'"," });",""," }, '0.0.1', {requires: ['template-base', 'templates-foo']});","","The template can now be used without having to know which specific rendering","engine generated it.","","@method render","@param {String} templateName The abstracted name to reference the template.","@param {Object} [data] The data to be interpolated into the template.","@param {Object} [options] Any additional options to be passed into the template.","@return {String} output The rendered result.","@static","@since 3.12.0","**/","Template.render = function (templateName, data, options) {"," var template = Template._registry[templateName],"," result = '';",""," if (template) {"," result = template(data, options);"," } else {"," Y.error('Unregistered template: \"' + templateName + '\"');"," }",""," return result;","};","","Template.prototype = {"," /**"," Compiles a template with the current template engine and returns a compiled"," template function.",""," @method compile"," @param {String} text Template text to compile."," @param {Object} [options] Options to pass along to the template engine. See"," template engine docs for options supported by each engine."," @return {Function} Compiled template function."," @since 3.8.0"," **/"," compile: function (text, options) {"," options = options ? Y.merge(this.defaults, options) : this.defaults;"," return this.engine.compile(text, options);"," },",""," /**"," Precompiles a template with the current template engine and returns a string"," containing JavaScript source code for the precompiled template.",""," @method precompile"," @param {String} text Template text to compile."," @param {Object} [options] Options to pass along to the template engine. See"," template engine docs for options supported by each engine."," @return {String} Source code for the precompiled template."," @since 3.8.0"," **/"," precompile: function (text, options) {"," options = options ? Y.merge(this.defaults, options) : this.defaults;"," return this.engine.precompile(text, options);"," },",""," /**"," Compiles and renders a template with the current template engine in a single"," step, and returns the rendered result.",""," @method render"," @param {String} text Template text to render."," @param {Object} data Data object to provide when rendering the template."," @param {Object} [options] Options to pass along to the template engine. See"," template engine docs for options supported by each engine."," @return {String} Rendered result."," @since 3.8.0"," **/"," render: function (text, data, options) {"," options = options ? Y.merge(this.defaults, options) : this.defaults;",""," if (this.engine.render) {"," return this.engine.render(text, data, options);"," }",""," return this.engine.compile(text, options)(data, options);"," },",""," /**"," Revives a precompiled template function into an executable template function"," using the current template engine. The precompiled code must already have"," been evaluated; this method won't evaluate it for you.",""," @method revive"," @param {Function} precompiled Precompiled template function."," @param {Object} [options] Options to pass along to the template engine. See"," template engine docs for options supported by each engine."," @return {Function} Compiled template function."," @since 3.8.0"," **/"," revive: function (precompiled, options) {"," options = options ? Y.merge(this.defaults, options) : this.defaults;",""," return this.engine.revive ? this.engine.revive(precompiled, options) :"," precompiled;"," }","};","","// Copy existing namespaced properties from Y.Template to the Template function","// if Y.Template already exists, then make the function the new Y.Template.","// This ensures that other modules can safely add stuff to the Y.Template","// namespace even if they're loaded before this one.","Y.Template = Y.Template ? Y.mix(Template, Y.Template) : Template;","","","}, '@VERSION@', {\"requires\": [\"yui-base\"]});","","}());"]}; |