Introduced core.

This commit is contained in:
Borys Levytskyi
2015-04-04 16:33:33 +03:00
parent dd2175f04a
commit d96bcb0517
17 changed files with 48 additions and 42 deletions

View File

@@ -1,4 +1,7 @@
(function(app){
(function(app, core){
var should = core.should;
function Command(name) {
this.name = name;
this.executionHandlers = [];
@@ -49,4 +52,5 @@
};
window.commandr = commandr;
})(window.app);
})(window.app, window.core);

View File

@@ -1,22 +1,20 @@
(function(app, should, Container) {
(function(app, core) {
var controllerDi = app.di; // TODO: Compbine
var should = core.should;
app.controller = function(name, instOrFactory) {
should.beString(name, "name");
if(instOrFactory == null) {
return controllerDi.resolve(name);
return this.get(name);
}
var reg = new Container.Registration(instOrFactory);
var reg = new core.Container.Registration(instOrFactory);
reg.onFirstTimeResolve = function (inst) {
addControllerMixin(inst);
};
controllerDi.register(name, reg);
this.set(name, reg);
};
app.run(function(){
@@ -78,4 +76,4 @@
}
}
})(window.app, window.should, window.Container);
})(window.app, window.core);

View File

@@ -1,60 +0,0 @@
(function(){
var HtmlBuilder = {};
HtmlBuilder.element = function(template, model) {
var el = document.createElement('div');
el.innerHTML = HtmlBuilder.template(template, model);
return el.children[0];
};
HtmlBuilder.template = function(template, model) {
should.beString(template, "template");
var regex = /(?:{([^}]+)})/g, html;
if(model == null){
html = template;
} else {
html = template.replace(regex, function(m, g1) {
return HtmlBuilder.escapeHtml(model[g1]);
});
}
return html;
};
function getAttributesStr(attr) {
if(attr == null) {
return '';
}
var str = [];
for(var key in attr) {
if(key == 'html')
continue;
str.push(key + '="' + HtmlBuilder.escapeHtml(attr[key]) + '"');
}
return str.join(' ');
}
HtmlBuilder.escapeHtml = function(obj) {
if(obj == null) {
return obj;
}
if(typeof obj != 'string') {
obj = obj.toString();
}
return obj
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
window.HtmlBuilder = HtmlBuilder;
})();