Skip to content
Browse files

Build Y.Template.

  • Loading branch information...
1 parent 907e819 commit 0ecec8862f21ab13a61b5c1459d164a68f273de0 @ericf ericf committed Dec 20, 2012
View
65 build/template-base/template-base-coverage.js
@@ -26,10 +26,10 @@ _yuitest_coverage["build/template-base/template-base.js"] = {
path: "build/template-base/template-base.js",
code: []
};
-_yuitest_coverage["build/template-base/template-base.js"].code=["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.","@constructor","@since 3.8.0","**/","","function Template(engine) {"," /**"," 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.');"," }","}","","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) {"," 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) {"," 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) {"," 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) {"," 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\"]});"];
-_yuitest_coverage["build/template-base/template-base.js"].lines = {"1":0,"52":0,"59":0,"61":0,"62":0,"66":0,"79":0,"94":0,"110":0,"111":0,"114":0,"130":0,"139":0};
-_yuitest_coverage["build/template-base/template-base.js"].functions = {"Template:52":0,"compile:78":0,"precompile:93":0,"render:109":0,"revive:129":0,"(anonymous 1):1":0};
-_yuitest_coverage["build/template-base/template-base.js"].coveredLines = 13;
+_yuitest_coverage["build/template-base/template-base.js"].code=["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.');"," }","}","","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\"]});"];
+_yuitest_coverage["build/template-base/template-base.js"].lines = {"1":0,"54":0,"61":0,"69":0,"71":0,"72":0,"76":0,"89":0,"90":0,"105":0,"106":0,"122":0,"124":0,"125":0,"128":0,"144":0,"146":0,"155":0};
+_yuitest_coverage["build/template-base/template-base.js"].functions = {"Template:54":0,"compile:88":0,"precompile:104":0,"render:121":0,"revive:143":0,"(anonymous 1):1":0};
+_yuitest_coverage["build/template-base/template-base.js"].coveredLines = 18;
_yuitest_coverage["build/template-base/template-base.js"].coveredFunctions = 6;
_yuitest_coverline("build/template-base/template-base.js", 1);
YUI.add('template-base', function (Y, NAME) {
@@ -79,31 +79,42 @@ Using with Handlebars:
@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
**/
_yuitest_coverfunc("build/template-base/template-base.js", "(anonymous 1)", 1);
-_yuitest_coverline("build/template-base/template-base.js", 52);
-function Template(engine) {
+_yuitest_coverline("build/template-base/template-base.js", 54);
+function Template(engine, defaults) {
+ /**
+ Default options.
+
+ @property {Object} defaults
+ @since 3.8.1
+ **/
+ _yuitest_coverfunc("build/template-base/template-base.js", "Template", 54);
+_yuitest_coverline("build/template-base/template-base.js", 61);
+this.defaults = defaults;
+
/**
Template engine class.
@property {Mixed} engine
@since 3.8.0
**/
- _yuitest_coverfunc("build/template-base/template-base.js", "Template", 52);
-_yuitest_coverline("build/template-base/template-base.js", 59);
+ _yuitest_coverline("build/template-base/template-base.js", 69);
this.engine = engine || Y.Template.Micro;
- _yuitest_coverline("build/template-base/template-base.js", 61);
+ _yuitest_coverline("build/template-base/template-base.js", 71);
if (!this.engine) {
- _yuitest_coverline("build/template-base/template-base.js", 62);
+ _yuitest_coverline("build/template-base/template-base.js", 72);
Y.error('No template engine loaded.');
}
}
-_yuitest_coverline("build/template-base/template-base.js", 66);
+_yuitest_coverline("build/template-base/template-base.js", 76);
Template.prototype = {
/**
Compiles a template with the current template engine and returns a compiled
@@ -117,8 +128,10 @@ Template.prototype = {
@since 3.8.0
**/
compile: function (text, options) {
- _yuitest_coverfunc("build/template-base/template-base.js", "compile", 78);
-_yuitest_coverline("build/template-base/template-base.js", 79);
+ _yuitest_coverfunc("build/template-base/template-base.js", "compile", 88);
+_yuitest_coverline("build/template-base/template-base.js", 89);
+options = options ? Y.merge(this.defaults, options) : this.defaults;
+ _yuitest_coverline("build/template-base/template-base.js", 90);
return this.engine.compile(text, options);
},
@@ -134,8 +147,10 @@ return this.engine.compile(text, options);
@since 3.8.0
**/
precompile: function (text, options) {
- _yuitest_coverfunc("build/template-base/template-base.js", "precompile", 93);
-_yuitest_coverline("build/template-base/template-base.js", 94);
+ _yuitest_coverfunc("build/template-base/template-base.js", "precompile", 104);
+_yuitest_coverline("build/template-base/template-base.js", 105);
+options = options ? Y.merge(this.defaults, options) : this.defaults;
+ _yuitest_coverline("build/template-base/template-base.js", 106);
return this.engine.precompile(text, options);
},
@@ -152,14 +167,17 @@ return this.engine.precompile(text, options);
@since 3.8.0
**/
render: function (text, data, options) {
- _yuitest_coverfunc("build/template-base/template-base.js", "render", 109);
-_yuitest_coverline("build/template-base/template-base.js", 110);
+ _yuitest_coverfunc("build/template-base/template-base.js", "render", 121);
+_yuitest_coverline("build/template-base/template-base.js", 122);
+options = options ? Y.merge(this.defaults, options) : this.defaults;
+
+ _yuitest_coverline("build/template-base/template-base.js", 124);
if (this.engine.render) {
- _yuitest_coverline("build/template-base/template-base.js", 111);
+ _yuitest_coverline("build/template-base/template-base.js", 125);
return this.engine.render(text, data, options);
}
- _yuitest_coverline("build/template-base/template-base.js", 114);
+ _yuitest_coverline("build/template-base/template-base.js", 128);
return this.engine.compile(text, options)(data, options);
},
@@ -176,8 +194,11 @@ return this.engine.compile(text, options)(data, options);
@since 3.8.0
**/
revive: function (precompiled, options) {
- _yuitest_coverfunc("build/template-base/template-base.js", "revive", 129);
-_yuitest_coverline("build/template-base/template-base.js", 130);
+ _yuitest_coverfunc("build/template-base/template-base.js", "revive", 143);
+_yuitest_coverline("build/template-base/template-base.js", 144);
+options = options ? Y.merge(this.defaults, options) : this.defaults;
+
+ _yuitest_coverline("build/template-base/template-base.js", 146);
return this.engine.revive ? this.engine.revive(precompiled, options) :
precompiled;
}
@@ -187,7 +208,7 @@ return this.engine.revive ? this.engine.revive(precompiled, options) :
// 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.
-_yuitest_coverline("build/template-base/template-base.js", 139);
+_yuitest_coverline("build/template-base/template-base.js", 155);
Y.Template = Y.Template ? Y.mix(Template, Y.Template) : Template;
View
18 build/template-base/template-base-debug.js
@@ -45,11 +45,21 @@ Using with Handlebars:
@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) {
+function Template(engine, defaults) {
+ /**
+ Default options.
+
+ @property {Object} defaults
+ @since 3.8.1
+ **/
+ this.defaults = defaults;
+
/**
Template engine class.
@@ -76,6 +86,7 @@ Template.prototype = {
@since 3.8.0
**/
compile: function (text, options) {
+ options = options ? Y.merge(this.defaults, options) : this.defaults;
return this.engine.compile(text, options);
},
@@ -91,6 +102,7 @@ Template.prototype = {
@since 3.8.0
**/
precompile: function (text, options) {
+ options = options ? Y.merge(this.defaults, options) : this.defaults;
return this.engine.precompile(text, options);
},
@@ -107,6 +119,8 @@ Template.prototype = {
@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);
}
@@ -127,6 +141,8 @@ Template.prototype = {
@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;
}
View
2 build/template-base/template-base-min.js
@@ -1 +1 @@
-YUI.add("template-base",function(e,t){function n(t){this.engine=t||e.Template.Micro,this.engine||e.error("No template engine loaded.")}n.prototype={compile:function(e,t){return this.engine.compile(e,t)},precompile:function(e,t){return this.engine.precompile(e,t)},render:function(e,t,n){return this.engine.render?this.engine.render(e,t,n):this.engine.compile(e,n)(t,n)},revive:function(e,t){return this.engine.revive?this.engine.revive(e,t):e}},e.Template=e.Template?e.mix(n,e.Template):n},"@VERSION@",{requires:["yui-base"]});
+YUI.add("template-base",function(e,t){function n(t,n){this.defaults=n,this.engine=t||e.Template.Micro,this.engine||e.error("No template engine loaded.")}n.prototype={compile:function(t,n){return n=n?e.merge(this.defaults,n):this.defaults,this.engine.compile(t,n)},precompile:function(t,n){return n=n?e.merge(this.defaults,n):this.defaults,this.engine.precompile(t,n)},render:function(t,n,r){return r=r?e.merge(this.defaults,r):this.defaults,this.engine.render?this.engine.render(t,n,r):this.engine.compile(t,r)(n,r)},revive:function(t,n){return n=n?e.merge(this.defaults,n):this.defaults,this.engine.revive?this.engine.revive(t,n):t}},e.Template=e.Template?e.mix(n,e.Template):n},"@VERSION@",{requires:["yui-base"]});
View
18 build/template-base/template-base.js
@@ -45,11 +45,21 @@ Using with Handlebars:
@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) {
+function Template(engine, defaults) {
+ /**
+ Default options.
+
+ @property {Object} defaults
+ @since 3.8.1
+ **/
+ this.defaults = defaults;
+
/**
Template engine class.
@@ -76,6 +86,7 @@ Template.prototype = {
@since 3.8.0
**/
compile: function (text, options) {
+ options = options ? Y.merge(this.defaults, options) : this.defaults;
return this.engine.compile(text, options);
},
@@ -91,6 +102,7 @@ Template.prototype = {
@since 3.8.0
**/
precompile: function (text, options) {
+ options = options ? Y.merge(this.defaults, options) : this.defaults;
return this.engine.precompile(text, options);
},
@@ -107,6 +119,8 @@ Template.prototype = {
@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);
}
@@ -127,6 +141,8 @@ Template.prototype = {
@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;
}

0 comments on commit 0ecec88

Please sign in to comment.
Something went wrong with that request. Please try again.