deep-views
Views controller, dom directives and dom-sheets for deepjs
For jquery dom manipulator, take a look there.
Simple View :
var deep = require("deepjs");
require("deep-views/index");
require("deep-views/lib/jquery-dom")("dom");
var view = deep.View({
how: "<b>Hello my friend</b>",
where: "dom.htmlOf::#content"
});
view.refresh();
"What" is injected in "how".
var view = deep.View({
what: {
fullName:"John Rambo"
},
how: function (what) {
return "<b>Hello " + what.fullName + "</b>";
},
where: "dom.replace::#content"
});
"What" could be loadable.
var deep = require("deepjs");
require("deep-views/index");
require("deep-views/lib/jquery-dom")("dom");
require("deep-marked/lib/jq-ajax")("marked");
require("deep-jquery/lib/ajax/json")("json");
var view = deep.View({
what: "json::/json/profile.json",
how: "marked::/templates/my-template.html",
where: "dom.prependTo::#content"
});
"What" could be deeply structured. every loadable string (with a valid protocol in front) will be replaced by its result.
var view = deep.View({
what: {
datas:"json::/json/profile.json",
otherDatas:"json::/json/comments.json"
},
how: "swig::/templates/simple-template.html",
where: "dom.appendTo::#content"
});
"done" is executed after "where". Use it to bind custom behaviour.
var view = deep.View({
what: "json::/json/profile.json",
how: "swig::/templates/simple-template.html",
where: "dom.appendTo::#content",
done: function (renderObject) {
$(renderObject.placed).find("#fullname-span").click(function () {
window.alert("You clicked on a name");
});
}
});
Full description :
var view = deep.View({
init:function(){
},
what:{ }
how: function(what){
return something;
},
where: function( howOutput ){
return placed_dom_element;
},
done: function ( renderedObject ) {
},
fail: function ( renderedObject ) {
},
clean: function(){
}
});
view.refresh();
A config entry could be added :
var view = deep.View({
config:{
scope:"browser",
relink:false
},
how: "swig::/templates/simple-template.html",
where: "dom.appendTo::#content"
});
Directives could be used with views html output.
Docs on directives and dom-sheets coming soon.
Licence
LGPL 3.0