Skip to content

Commit

Permalink
solve compress error in template
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Mar 29, 2011
1 parent fe2ac20 commit 830d91a
Show file tree
Hide file tree
Showing 32 changed files with 1,067 additions and 666 deletions.
598 changes: 301 additions & 297 deletions build/kissy-aio-min.js

Large diffs are not rendered by default.

204 changes: 199 additions & 5 deletions build/kissy-aio.js
Expand Up @@ -67,7 +67,7 @@ build time: ${build.time}
*/
version: '1.20dev',

buildTime:'20110329141358',
buildTime:'20110329183028',

/**
* Returns a new object containing all of the properties of
Expand Down Expand Up @@ -8844,6 +8844,199 @@ Copyright 2011, KISSY UI Library v1.20dev
MIT Licensed
build time: ${build.time}
*/
/**
* @fileoverview KISSY Template Engine.
* @author yyfrankyy(yyfrankyy@gmail.com)
* @see https://github.com/yyfrankyy/kissy/tree/template/src/template
* @version 0.3
*/
KISSY.add('template/base', function(S) {

var
/**
* Template Cache
*/
templateCache = {},

/**
* start/end tag mark
*/
tagStartEnd = {
'#': 'start',
'/': 'end'
},

/**
* Regexp Cache
*/
regexpCache = {},
getRegexp = function(regexp) {
if (!(regexp in regexpCache)) {
regexpCache[regexp] = new RegExp(regexp, 'ig');
}
return regexpCache[regexp];
},

// static string
KS_TEMPL_STAT_PARAM = 'KS_TEMPL_STAT_PARAM',
KS_TEMPL = 'KS_TEMPL',
KS_DATA = 'KS_DATA_',
KS_EMPTY = '',

PREFIX = '");',
SUFFIX = KS_TEMPL + '.push("',

PARSER_SYNTAX_ERROR = 'KISSY.Template: Syntax Error. ',
PARSER_RENDER_ERROR = 'KISSY.Template: Render Error. ',

PARSER_PREFIX = 'var ' + KS_TEMPL + '=[],' + KS_TEMPL_STAT_PARAM + '=false;with(',
PARSER_MIDDLE = '||{}){try{' + KS_TEMPL + '.push("',
PARSER_SUFFIX = '");}catch(e){' + KS_TEMPL + '=["' + PARSER_RENDER_ERROR + '" + e.message]}};return ' + KS_TEMPL + '.join("");',

/*
* build a static parser
*/
buildParser = function(templ) {
var _parser, _empty_index;
return S.trim(templ).replace(getRegexp('[\r\t\n]'), ' ').replace(getRegexp('(["\'])'), '\\$1')
.replace(getRegexp('\{\{([#/]?)(?!\}\})([^}]*)\}\}'), function(all, expr, oper) {
_parser = KS_EMPTY;
// is an expression
if (expr) {
oper = S.trim(oper);
_empty_index = oper.indexOf(' ');
oper = _empty_index === -1 ? [oper, ''] :
[oper.substring(0, oper.indexOf(' ')), oper.substring(oper.indexOf(' '))];
for (var i in Statements) {
if (oper[0] !== i) continue;
oper.shift();
if (expr in tagStartEnd) {
_parser = Statements[i][tagStartEnd[expr]].replace(
getRegexp(KS_TEMPL_STAT_PARAM),
oper.join(KS_EMPTY).replace(getRegexp('\\\\([\'"])'), '$1')
);
}
}
}

// return array directly
else {
_parser = KS_TEMPL + '.push(' + oper.replace(getRegexp('\\\\([\'"])'), '$1') + ');';
}
return PREFIX + _parser + SUFFIX;

});
},

/**
* expressions
*/
Statements = {
'if': {
start: 'if(' + KS_TEMPL_STAT_PARAM + '){',
end: '}'
},
'else': {
start: '}else{'
},
'elseif': {
start: '}else if(' + KS_TEMPL_STAT_PARAM + '){'
},
// KISSY.each function wrap
'each': {
start: 'KISSY.each(' + KS_TEMPL_STAT_PARAM + ', function(_ks_value, _ks_index){',
end: '});'
},
// comments
'!': {
start: '/*' + KS_TEMPL_STAT_PARAM + '*/'
}
},

/**
* @param {String} templ template to be rendered.
* @return return this for chain.
*/
Template = function(templ//, config
) {
if (!(templ in templateCache)) {
var _ks_data = KS_DATA + S.now(), func,
_parser = [
PARSER_PREFIX,
_ks_data,
PARSER_MIDDLE,
buildParser(templ),
PARSER_SUFFIX
];

try {
func = new Function(_ks_data, _parser.join(KS_EMPTY));
} catch (e) {
_parser[3] = PREFIX + SUFFIX + PARSER_SYNTAX_ERROR + ',' + e.message + PREFIX + SUFFIX;
func = new Function(_ks_data, _parser.join(KS_EMPTY));
}

templateCache[templ] = {
name: _ks_data,
parser: _parser.join(KS_EMPTY),
render: func
};
}
return templateCache[templ];
};

S.mix(Template, {
/**
* Logging Compiled Template Codes
* @param {String} templ template string.
*/
log: function(templ) {
if (templ in templateCache) {
if ('js_beautify' in window) {
// S.log(js_beautify(templateCache[templ].parser, {
// indent_size:4,
// indent_char:" ",
// preserve_newlines: true,
// braces_on_own_line: false,
// keep_array_indentation: false,
// space_after_anon_function: true
// }), 'info');
} else {
S.log(templateCache[templ].parser, 'info');
}
} else {
Template(templ);
this.log(templ);
}
},

/**
* add statement for extending template tags
* @param {String} statement tag name.
* @param {String} o extent tag object.
*/
addStatement: function(statement, o) {
if (S['isString'](statement) && S['isObject'](o)) {
Statements[statement] = o;
}
}

});

return Template;

});
KISSY.add("template", function(S, T) {
S.Template = T;
return T;
}, {
requires:["template/base"]
});
/*
Copyright 2011, KISSY UI Library v1.20dev
MIT Licensed
build time: ${build.time}
*/
/**
* @module Flash 全局静态类
* @author kingfo<oicuicu@gmail.com>
Expand Down Expand Up @@ -11209,7 +11402,8 @@ KISSY.add("uibase/loadingrender", function(S, Node) {
if (!self._loadingExtEl) {
self._loadingExtEl = new Node("<div " +
"class='" +
"ks-ext-loading'" +
this.get("prefixCls") +
"ext-loading'" +
" style='position: absolute;" +
"border: none;" +
"width: 100%;" +
Expand Down Expand Up @@ -11280,7 +11474,7 @@ KISSY.add("uibase/maskrender", function(S) {
function initMask() {
var UA = S.require("ua"),Node = S.require("node/node"),DOM = S.require("dom");
mask = new Node("<div class='" +
"ks-ext-mask'>").prependTo(document.body);
this.get("prefixCls") + "ext-mask'>").prependTo(document.body);
mask.css({
"position":"absolute",
left:0,
Expand Down Expand Up @@ -11469,7 +11663,7 @@ KISSY.add("uibase/positionrender", function() {

__renderUI:function() {
var el = this.get("el");
el.addClass("ks-ext-position");
el.addClass(this.get("prefixCls") + "ext-position");
el.css("display", "");
},

Expand Down Expand Up @@ -13421,7 +13615,7 @@ KISSY.add('overlay/dialog', function(S, Overlay, UIBase, DialogRender) {
], {
renderUI:function() {
var self = this;
self.get("view").get("el").addClass("ks-dialog");
self.get("view").get("el").addClass(this.get("view").get("prefixCls")+"dialog");
//设置值,drag-ext 绑定时用到
self.set("handlers", [self.get("view").get("header")]);
}
Expand Down
2 changes: 1 addition & 1 deletion build/kissy-min.js

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

2 changes: 1 addition & 1 deletion build/kissy-nodejs-min.js

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

2 changes: 1 addition & 1 deletion build/kissy-nodejs.js
Expand Up @@ -248,7 +248,7 @@ build time: ${build.time}
*/
version: '1.20dev',

buildTime:'20110329141358',
buildTime:'20110329183028',

/**
* Returns a new object containing all of the properties of
Expand Down
2 changes: 1 addition & 1 deletion build/kissy.js
Expand Up @@ -67,7 +67,7 @@ build time: ${build.time}
*/
version: '1.20dev',

buildTime:'20110329141358',
buildTime:'20110329183028',

/**
* Returns a new object containing all of the properties of
Expand Down
2 changes: 1 addition & 1 deletion build/overlay-min.js

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

2 changes: 1 addition & 1 deletion build/overlay.js
Expand Up @@ -91,7 +91,7 @@ KISSY.add('overlay/dialog', function(S, Overlay, UIBase, DialogRender) {
], {
renderUI:function() {
var self = this;
self.get("view").get("el").addClass("ks-dialog");
self.get("view").get("el").addClass(this.get("view").get("prefixCls")+"dialog");
//设置值,drag-ext 绑定时用到
self.set("handlers", [self.get("view").get("header")]);
}
Expand Down
2 changes: 1 addition & 1 deletion build/overlay/overlay-pkg-min.js

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

2 changes: 1 addition & 1 deletion build/overlay/overlay-pkg.js
Expand Up @@ -91,7 +91,7 @@ KISSY.add('overlay/dialog', function(S, Overlay, UIBase, DialogRender) {
], {
renderUI:function() {
var self = this;
self.get("view").get("el").addClass("ks-dialog");
self.get("view").get("el").addClass(this.get("view").get("prefixCls")+"dialog");
//设置值,drag-ext 绑定时用到
self.set("handlers", [self.get("view").get("header")]);
}
Expand Down
3 changes: 0 additions & 3 deletions build/packages/build.xml
Expand Up @@ -69,10 +69,7 @@
<path path="../sizzle.js"/>

<path path="../datalazyload.js"/>
<!--
cause error!
<path path="../template.js"/>
-->
<path path="../flash.js"/>
<path path="../dd.js"/>
<path path="../resizable.js"/>
Expand Down

0 comments on commit 830d91a

Please sign in to comment.