Skip to content

Commit

Permalink
bump 0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Jul 22, 2013
1 parent 540dbfc commit e535b2e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
39 changes: 30 additions & 9 deletions dist/templatable-debug.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
define("arale/templatable/0.9.1/templatable-debug", [ "$-debug", "gallery/handlebars/1.0.2/handlebars-debug" ], function(require, exports, module) {
define("arale/templatable/0.9.2/templatable-debug", [ "$-debug", "gallery/handlebars/1.0.2/handlebars-debug" ], function(require, exports, module) {
var $ = require("$-debug");
var Handlebars = require("gallery/handlebars/1.0.2/handlebars-debug");
var compiledTemplates = {};
// 提供 Template 模板支持,默认引擎是 Handlebars
module.exports = {
// Handlebars 的 helpers
templateHelpers: null,
// Handlebars 的 partials
templatePartials: null,
// template 对应的 DOM-like object
templateObject: null,
// 根据配置的模板和传入的数据,构建 this.element 和 templateElement
Expand All @@ -22,22 +24,33 @@ define("arale/templatable/0.9.1/templatable-debug", [ "$-debug", "gallery/handle
// 编译模板,混入数据,返回 html 结果
compile: function(template, model) {
template || (template = this.get("template"));
model || (model = this.get("model"));
model || (model = this.get("model")) || (model = {});
if (model.toJSON) {
model = model.toJSON();
}
// handlebars runtime
if (isFunction(template)) {
return template(model, {
helpers: this.templateHelpers
helpers: this.templateHelpers,
partials: this.templatePartials
});
} else {
var helpers = this.templateHelpers;
var partials = this.templatePartials;
var helper, partial;
// 注册 helpers
if (helpers) {
for (var name in helpers) {
if (helpers.hasOwnProperty(name)) {
Handlebars.registerHelper(name, helpers[name]);
for (helper in helpers) {
if (helpers.hasOwnProperty(helper)) {
Handlebars.registerHelper(helper, helpers[helper]);
}
}
}
// 注册 partials
if (partials) {
for (partial in partials) {
if (partials.hasOwnProperty(partial)) {
Handlebars.registerPartial(partial, partials[partial]);
}
}
}
Expand All @@ -49,9 +62,17 @@ define("arale/templatable/0.9.1/templatable-debug", [ "$-debug", "gallery/handle
var html = compiledTemplate(model);
// 卸载 helpers
if (helpers) {
for (name in helpers) {
if (helpers.hasOwnProperty(name)) {
delete Handlebars.helpers[name];
for (helper in helpers) {
if (helpers.hasOwnProperty(helper)) {
delete Handlebars.helpers[helper];
}
}
}
// 卸载 partials
if (partials) {
for (partial in partials) {
if (partials.hasOwnProperty(partial)) {
delete Handlebars.partials[partial];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/templatable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"family": "arale",
"name": "templatable",
"version": "0.9.1",
"version": "0.9.2",
"description": "处理组件的模板渲染,混入到 Widget 中使用。",
"keywords": ["utility", "widget"],
"homepage": "http://aralejs.org/templatable/",
Expand Down

0 comments on commit e535b2e

Please sign in to comment.