Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: naneau/gunther
base: 0a097097bc
...
head fork: naneau/gunther
compare: 0d0e46807c
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  lib/gunther-min.js
@@ -1 +1 @@
-(function(){var a,b,c,d,e,f,g,h,i=function(a,b){return function(){return a.apply(b,arguments)}},j=Object.prototype.hasOwnProperty,k=function(a,b){function d(){this.constructor=a}for(var c in b)j.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a},l=Array.prototype.slice;b={},window.Gunther=b,typeof require!=null&&(module.exports=b),b.IDGenerator=function(){function a(){this.value=0}return a.prototype.generate=function(){return this.value++},a}(),b.HTML=function(){function a(){}return a.elements=["a","abbr","address","article","aside","audio","b","bdi","bdo","blockquote","body","button","canvas","caption","cite","code","colgroup","datalist","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","html","i","iframe","ins","kbd","label","legend","li","map","mark","menu","meter","nav","noscript","object","ol","optgroup","option","output","p","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","u","ul","video","area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","applet","acronym","bgsound","dir","frameset","noframes","isindex","listing","nextid","noembed","plaintext","rb","strike","xmp","big","blink","center","font","marquee","multicol","nobr","spacer","tt","basefont","frame","date"],a.eventNames=["load","unload","blur","change","focus","reset","select","submit","abort","keydown","keyup","keypress","click","dblclick","mousedown","mouseout","mouseover","mouseup"],a}(),a=function(){function a(a,b,c){var d,e,f,g;this.model=a,this.propertyNames=b,this.valueGenerator=c,this.valueGenerator==null&&typeof this.propertyNames=="string"&&(this.valueGenerator=i(function(){return this.model.get(this.propertyNames[0])},this)),this.propertyNames=[].concat(this.propertyNames),g=this.propertyNames;for(e=0,f=g.length;e<f;e++)d=g[e],this.model.bind("change:"+d,i(function(){return this.trigger("change",this.getValue())},this))}return a.prototype.getValue=function(){var a;return a=this.valueGenerator(),a instanceof b.Template?a.render():a},a}(),_.extend(a.prototype,Backbone.Events),c=function(){function a(){a.__super__.constructor.apply(this,arguments)}return k(a,Backbone.View),a.generator=new b.IDGenerator,a.prototype.initialize=function(b){return this.key="_subview-"+a.generator.generate(),this.elementKey="element-"+this.key,this.prepend=b.prepend!=null?b.prepend:!1,this.generator=b.generator,this.model.each(i(function(a){return this.initItem(a)},this)),this.model.bind("add",i(function(a){return this.initItem(a),this.renderItem(a)},this)),this.model.bind("remove",i(function(a){if(a[this.key]==null)return;return a[this.key]instanceof Backbone.View?a[this.key].remove():a[this.elementKey].remove()},this))},a.prototype.initItem=function(a){return a[this.key]=this.generator(a)},a.prototype.renderItem=function(a){if(a[this.key]instanceof b.Template)a[this.elementKey]=a[this.key].render(a);else if(a[this.key]instanceof Backbone.View)a[this.key].render(),a[this.elementKey]=a[this.key].el;else throw new Error("Generator must return either a Gunther.Template or a Backbone.View instance");return this.prepend?this.el.prepend(a[this.elementKey]):this.el.append(a[this.elementKey])},a.prototype.render=function(){return this.model.each(i(function(a){return this.renderItem(a)},this))},a}(),b.Template=function(){function d(a){this.fn=a,null}return d.domParsers=[],d.createHtmlElement=function(a){return $(document.createElement(a))},d.addAttributes=function(c,d){var e,f,g,h,i,j;j=[];for(h=0,i=d.length;h<i;h++)e=d[h],j.push(function(){var d;d=[];for(f in e)g=e[f],d.push(function(d,e){return _.include(b.HTML.eventNames,d)?c.bind(d,function(){var a;return a=1<=arguments.length?l.call(arguments,0):[],e.apply(null,a)}):e instanceof a?(c.attr(d,e.getValue()),e.bind("change",function(a){return c.attr(d,a)})):c.attr(d,e)}(f,g));return d}());return j},d.generateChildren=function(b,c,d){var e;e=c.apply(d),typeof e!="object"&&b.append(document.createTextNode(e));if(e instanceof a)return b.html(e.getValue()),e.bind("change",function(a){return b.html(a)});if(e instanceof Backbone.View)return e.el=b,e.render()},d.prototype.render=function(){var a,c,d,e,f,g,h,i,j;a=1<=arguments.length?l.call(arguments,0):[],this.root=$("<div />"),this.current=this.root,this.fn.apply(this,a),d=this.root.children(),j=b.Template.domParsers;for(f=0,h=j.length;f<h;f++){e=j[f];for(g=0,i=d.length;g<i;g++)c=d[g],e(c)}return d},d.prototype.renderInto=function(){var a,b,c,d,e,f;c=arguments[0],a=2<=arguments.length?l.call(arguments,1):[],f=this.render.apply(this,a);for(d=0,e=f.length;d<e;d++)b=f[d],c.append(b);return new Backbone.View({el:c})},d.prototype.text=function(b){var c,d;return d=document.createTextNode(""),typeof b=="string"?d.nodeValue=b:(typeof b=="function"&&(c=b.apply(this)),c instanceof a&&(d.nodeValue=c.getValue(),c.bind("change",function(a){return d.nodeValue=a}))),this.current.append(d)},d.prototype.addElement=function(){var a,c,d,e;return e=arguments[0],a=2<=arguments.length?l.call(arguments,1):[],c=this.current,d=b.Template.createHtmlElement(e),this.current=d,typeof a[a.length-1]=="function"&&b.Template.generateChildren(d,a.pop(),this),b.Template.addAttributes(d,a),c.append(d),this.current=c,null},d.prototype.bind=function(){var b;return b=1<=arguments.length?l.call(arguments,0):[],function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return typeof e=="object"?e:d}(a,b,function(){})},d.prototype.itemSubView=function(a){return new c(a)},d.prototype.e=function(){var a,b;return b=arguments[0],a=2<=arguments.length?l.call(arguments,1):[],this.addElement.apply(this,[b].concat(l.call(a)))},d.prototype.t=function(){var a;return a=1<=arguments.length?l.call(arguments,0):[],this.text.apply(this,a)},d}(),h=b.HTML.elements,e=function(a){return b.Template.prototype[a]=function(){var b;return b=1<=arguments.length?l.call(arguments,0):[],this.addElement.apply(this,[a].concat(l.call(b)))}};for(f=0,g=h.length;f<g;f++)d=h[f],e(d)}).call(this)
+((function(){var a,b,c,d,e,f,g,h,i=Object.prototype.hasOwnProperty,j=function(a,b){function d(){this.constructor=a}for(var c in b)i.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a},k=Array.prototype.slice;b={},typeof require!=null?module.exports=b:window.Gunther=b,b.IDGenerator=function(){function a(){this.value=0}return a.prototype.generate=function(){return this.value++},a}(),b.HTML=function(){function a(){}return a.elements=["a","abbr","address","article","aside","audio","b","bdi","bdo","blockquote","body","button","canvas","caption","cite","code","colgroup","datalist","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","html","i","iframe","ins","kbd","label","legend","li","map","mark","menu","meter","nav","noscript","object","ol","optgroup","option","output","p","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","u","ul","video","area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","applet","acronym","bgsound","dir","frameset","noframes","isindex","listing","nextid","noembed","plaintext","rb","strike","xmp","big","blink","center","font","marquee","multicol","nobr","spacer","tt","basefont","frame","date"],a.eventNames=["load","unload","blur","change","focus","reset","select","submit","abort","keydown","keyup","keypress","click","dblclick","mousedown","mouseout","mouseover","mouseup"],a}(),a=function(){function a(a,b,c){var d,e,f,g,h=this;this.model=a,this.propertyNames=b,this.valueGenerator=c,this.valueGenerator==null&&typeof this.propertyNames=="string"&&(this.valueGenerator=function(){return h.model.get(h.propertyNames[0])}),this.propertyNames=[].concat(this.propertyNames),g=this.propertyNames;for(e=0,f=g.length;e<f;e++)d=g[e],this.model.bind("change:"+d,function(){return h.trigger("change",h.getValue())})}return a.prototype.getValue=function(){var a;return a=this.valueGenerator(),a instanceof b.Template?a.render():a},a}(),_.extend(a.prototype,Backbone.Events),c=function(a){function c(){c.__super__.constructor.apply(this,arguments)}return j(c,a),c.generator=new b.IDGenerator,c.prototype.initialize=function(a){var b=this;return this.key="_subview-"+c.generator.generate(),this.elementKey="element-"+this.key,this.prepend=a.prepend!=null?a.prepend:!1,this.generator=a.generator,this.model.each(function(a){return b.initItem(a)}),this.model.bind("add",function(a){return b.initItem(a),b.renderItem(a)}),this.model.bind("remove",function(a){if(a[b.key]==null)return;return a[b.key]instanceof Backbone.View?a[b.key].remove():a[b.elementKey].remove()})},c.prototype.initItem=function(a){return a[this.key]=this.generator(a)},c.prototype.renderItem=function(a){if(a[this.key]instanceof b.Template)a[this.elementKey]=a[this.key].render(a);else{if(!(a[this.key]instanceof Backbone.View))throw new Error("Generator must return either a Gunther.Template or a Backbone.View instance");a[this.key].render(),a[this.elementKey]=a[this.key].el}return this.prepend?this.el.prepend(a[this.elementKey]):this.el.append(a[this.elementKey])},c.prototype.render=function(){var a=this;return this.model.each(function(b){return a.renderItem(b)})},c}(Backbone.View),b.Template=function(){function d(a){this.fn=a,null}return d.domParsers=[],d.createHtmlElement=function(a){return $(document.createElement(a))},d.addAttributes=function(c,d){var e,f,g,h,i,j;j=[];for(h=0,i=d.length;h<i;h++)e=d[h],j.push(function(){var d;d=[];for(f in e)g=e[f],d.push(function(d,e){return _.include(b.HTML.eventNames,d)?c.bind(d,function(){var a;return a=1<=arguments.length?k.call(arguments,0):[],e.apply(null,a)}):e instanceof a?(c.attr(d,e.getValue()),e.bind("change",function(a){return c.attr(d,a)})):c.attr(d,e)}(f,g));return d}());return j},d.generateChildren=function(b,c,d){var e;e=c.apply(d),typeof e!="object"&&b.append(document.createTextNode(e));if(e instanceof a)return b.html(e.getValue()),e.bind("change",function(a){return b.html(a)});if(e instanceof Backbone.View)return e.el=b,e.render()},d.prototype.render=function(){var a,c,d,e,f,g,h,i,j;a=1<=arguments.length?k.call(arguments,0):[],this.root=$("<div />"),this.current=this.root,this.fn.apply(this,a),d=this.root.children(),j=b.Template.domParsers;for(f=0,h=j.length;f<h;f++){e=j[f];for(g=0,i=d.length;g<i;g++)c=d[g],e(c)}return d},d.prototype.renderInto=function(){var a,b,c,d,e,f;c=arguments[0],a=2<=arguments.length?k.call(arguments,1):[],f=this.render.apply(this,a);for(d=0,e=f.length;d<e;d++)b=f[d],c.append(b);return new Backbone.View({el:c})},d.prototype.text=function(b){var c,d;return d=document.createTextNode(""),typeof b=="string"?d.nodeValue=b:(typeof b=="function"&&(c=b.apply(this)),c instanceof a&&(d.nodeValue=c.getValue(),c.bind("change",function(a){return d.nodeValue=a}))),this.current.append(d)},d.prototype.addElement=function(){var a,c,d,e;return e=arguments[0],a=2<=arguments.length?k.call(arguments,1):[],c=this.current,d=b.Template.createHtmlElement(e),this.current=d,typeof a[a.length-1]=="function"&&b.Template.generateChildren(d,a.pop(),this),b.Template.addAttributes(d,a),c.append(d),this.current=c,null},d.prototype.bind=function(){var b;return b=1<=arguments.length?k.call(arguments,0):[],function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return typeof e=="object"?e:d}(a,b,function(){})},d.prototype.itemSubView=function(a){return new c(a)},d.prototype.e=function(){var a,b;return b=arguments[0],a=2<=arguments.length?k.call(arguments,1):[],this.addElement.apply(this,[b].concat(k.call(a)))},d.prototype.t=function(){var a;return a=1<=arguments.length?k.call(arguments,0):[],this.text.apply(this,a)},d}(),h=b.HTML.elements,e=function(a){return b.Template.prototype[a]=function(){var b;return b=1<=arguments.length?k.call(arguments,0):[],this.addElement.apply(this,[a].concat(k.call(b)))}};for(f=0,g=h.length;f<g;f++)d=h[f],e(d)})).call(this);
View
124 lib/gunther.js
@@ -1,53 +1,66 @@
(function() {
- var BoundProperty, Gunther, ItemSubView, htmlElement, _fn, _i, _len, _ref;
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
- for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
- function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype;
- child.prototype = new ctor;
- child.__super__ = parent.prototype;
- return child;
- }, __slice = Array.prototype.slice;
+ var BoundProperty, Gunther, ItemSubView, htmlElement, _fn, _i, _len, _ref,
+ __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
+ __slice = Array.prototype.slice;
+
Gunther = {};
- window.Gunther = Gunther;
+
if ((typeof require) != null) {
module.exports = Gunther;
+ } else {
+ window.Gunther = Gunther;
}
+
Gunther.IDGenerator = (function() {
+
function IDGenerator() {
this.value = 0;
}
+
IDGenerator.prototype.generate = function() {
return this.value++;
};
+
return IDGenerator;
+
})();
+
Gunther.HTML = (function() {
+
function HTML() {}
+
HTML.elements = ["a", "abbr", "address", "article", "aside", "audio", "b", "bdi", "bdo", "blockquote", "body", "button", "canvas", "caption", "cite", "code", "colgroup", "datalist", "dd", "del", "details", "dfn", "div", "dl", "dt", "em", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "html", "i", "iframe", "ins", "kbd", "label", "legend", "li", "map", "mark", "menu", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "span", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "u", "ul", "video", "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr", "applet", "acronym", "bgsound", "dir", "frameset", "noframes", "isindex", "listing", "nextid", "noembed", "plaintext", "rb", "strike", "xmp", "big", "blink", "center", "font", "marquee", "multicol", "nobr", "spacer", "tt", "basefont", "frame", "date"];
+
HTML.eventNames = ['load', 'unload', 'blur', 'change', 'focus', 'reset', 'select', 'submit', 'abort', 'keydown', 'keyup', 'keypress', 'click', 'dblclick', 'mousedown', 'mouseout', 'mouseover', 'mouseup'];
+
return HTML;
+
})();
+
BoundProperty = (function() {
+
function BoundProperty(model, propertyNames, valueGenerator) {
- var propertyName, _i, _len, _ref;
+ var propertyName, _i, _len, _ref,
+ _this = this;
this.model = model;
this.propertyNames = propertyNames;
this.valueGenerator = valueGenerator;
if (!(this.valueGenerator != null) && typeof this.propertyNames === 'string') {
- this.valueGenerator = __bind(function() {
- return this.model.get(this.propertyNames[0]);
- }, this);
+ this.valueGenerator = function() {
+ return _this.model.get(_this.propertyNames[0]);
+ };
}
this.propertyNames = [].concat(this.propertyNames);
_ref = this.propertyNames;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
propertyName = _ref[_i];
- this.model.bind("change:" + propertyName, __bind(function() {
- return this.trigger('change', this.getValue());
- }, this));
+ this.model.bind("change:" + propertyName, function() {
+ return _this.trigger('change', _this.getValue());
+ });
}
}
+
BoundProperty.prototype.getValue = function() {
var generatedValue;
generatedValue = this.valueGenerator();
@@ -57,41 +70,50 @@
return generatedValue;
}
};
+
return BoundProperty;
+
})();
+
_.extend(BoundProperty.prototype, Backbone.Events);
- ItemSubView = (function() {
- __extends(ItemSubView, Backbone.View);
+
+ ItemSubView = (function(_super) {
+
+ __extends(ItemSubView, _super);
+
function ItemSubView() {
ItemSubView.__super__.constructor.apply(this, arguments);
}
+
ItemSubView.generator = new Gunther.IDGenerator;
+
ItemSubView.prototype.initialize = function(options) {
+ var _this = this;
this.key = "_subview-" + (ItemSubView.generator.generate());
this.elementKey = "element-" + this.key;
this.prepend = options.prepend != null ? options.prepend : false;
this.generator = options.generator;
- this.model.each(__bind(function(item) {
- return this.initItem(item);
- }, this));
- this.model.bind('add', __bind(function(item) {
- this.initItem(item);
- return this.renderItem(item);
- }, this));
- return this.model.bind('remove', __bind(function(item) {
- if (!(item[this.key] != null)) {
- return;
- }
- if (item[this.key] instanceof Backbone.View) {
- return item[this.key].remove();
+ this.model.each(function(item) {
+ return _this.initItem(item);
+ });
+ this.model.bind('add', function(item) {
+ _this.initItem(item);
+ return _this.renderItem(item);
+ });
+ return this.model.bind('remove', function(item) {
+ if (!(item[_this.key] != null)) return;
+ if (item[_this.key] instanceof Backbone.View) {
+ return item[_this.key].remove();
} else {
- return item[this.elementKey].remove();
+ return item[_this.elementKey].remove();
}
- }, this));
+ });
};
+
ItemSubView.prototype.initItem = function(item) {
return item[this.key] = this.generator(item);
};
+
ItemSubView.prototype.renderItem = function(item) {
if (item[this.key] instanceof Gunther.Template) {
item[this.elementKey] = item[this.key].render(item);
@@ -107,18 +129,26 @@
return this.el.append(item[this.elementKey]);
}
};
+
ItemSubView.prototype.render = function() {
- return this.model.each(__bind(function(item) {
- return this.renderItem(item);
- }, this));
+ var _this = this;
+ return this.model.each(function(item) {
+ return _this.renderItem(item);
+ });
};
+
return ItemSubView;
- })();
+
+ })(Backbone.View);
+
Gunther.Template = (function() {
+
Template.domParsers = [];
+
Template.createHtmlElement = function(tagName) {
return $(document.createElement(tagName));
};
+
Template.addAttributes = function(el, attributes) {
var attribute, attributeName, attributeValue, _i, _len, _results;
_results = [];
@@ -151,6 +181,7 @@
}
return _results;
};
+
Template.generateChildren = function(el, childFn, scope) {
var childResult;
childResult = childFn.apply(scope);
@@ -167,10 +198,12 @@
return childResult.render();
}
};
+
function Template(fn) {
this.fn = fn;
null;
}
+
Template.prototype.render = function() {
var args, child, children, domParser, _i, _j, _len, _len2, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
@@ -188,6 +221,7 @@
}
return children;
};
+
Template.prototype.renderInto = function() {
var args, child, el, _i, _len, _ref;
el = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
@@ -200,15 +234,14 @@
el: el
});
};
+
Template.prototype.text = function(text) {
var childResult, el;
el = document.createTextNode('');
if (typeof text === 'string') {
el.nodeValue = text;
} else {
- if (typeof text === 'function') {
- childResult = text.apply(this);
- }
+ if (typeof text === 'function') childResult = text.apply(this);
if (childResult instanceof BoundProperty) {
el.nodeValue = childResult.getValue();
childResult.bind('change', function(newVal) {
@@ -218,6 +251,7 @@
}
return this.current.append(el);
};
+
Template.prototype.addElement = function() {
var args, current, el, tagName;
tagName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
@@ -232,6 +266,7 @@
this.current = current;
return null;
};
+
Template.prototype.bind = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
@@ -241,21 +276,27 @@
return typeof result === "object" ? result : child;
})(BoundProperty, args, function() {});
};
+
Template.prototype.itemSubView = function(options) {
return new ItemSubView(options);
};
+
Template.prototype.e = function() {
var args, tagName;
tagName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return this.addElement.apply(this, [tagName].concat(__slice.call(args)));
};
+
Template.prototype.t = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.text.apply(this, args);
};
+
return Template;
+
})();
+
_ref = Gunther.HTML.elements;
_fn = function(htmlElement) {
return Gunther.Template.prototype[htmlElement] = function() {
@@ -268,4 +309,5 @@
htmlElement = _ref[_i];
_fn(htmlElement);
}
+
}).call(this);
View
2  package.json
@@ -3,7 +3,7 @@
"name": "gunther",
"main": "./lib/gunther.js",
"description": "Gunther is a template/view drop-in for Backbone.js",
- "version": "0.0.10",
+ "version": "0.0.11",
"homepage": "http://naneau.net/projects/gunther",
"repository": {
"type": "git",
View
10 src/root.coffee
@@ -1,9 +1,11 @@
# Set up the global "namespace" for Gunther to live in
Gunther = {}
-# Export Gunther to the global scope
-window.Gunther = Gunther
-
# Export through CommonJS if we have a require function
# This is a tad hacky for now
-module.exports = Gunther if (typeof require)?
+#
+if (typeof require)?
+ module.exports = Gunther
+else
+ # Export Gunther to the global scope
+ window.Gunther = Gunther

No commit comments for this range

Something went wrong with that request. Please try again.