temple-backbone
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -5,124 +5,148 @@ /* | ||
* MIT License | ||
* Version 1.0.8-alpha | ||
* Version 1.1.0 | ||
*/ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),(f.Temple||(f.Temple={})).Backbone=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
var Backbone = (function() { | ||
if (this.Backbone) return this.Backbone; | ||
return _dereq_("backbone"); | ||
}).call(typeof window !== "undefined" ? window : this); | ||
(function ( global, factory ) { | ||
var Temple = (function() { | ||
if (this.Temple) return this.Temple; | ||
return _dereq_("templejs"); | ||
}).call(typeof window !== "undefined" ? window : this); | ||
'use strict'; | ||
module.exports = function() { | ||
// attach handlers | ||
this.handle(ModelHandler); | ||
this.handle(CollectionHandler); | ||
} | ||
// Common JS (i.e. browserify) environment | ||
if ( typeof module !== 'undefined' && module.exports && typeof require === 'function' ) { | ||
factory( require( 'temple-mustache' ), require( 'backbone' ) ); | ||
} | ||
var ModelHandler = { | ||
match: function(model) { | ||
return model instanceof Backbone.Model; | ||
}, | ||
construct: function(model) { | ||
this.listenTo(model, "change", function() { | ||
for (var k in model.changed) { | ||
this.set(k, model.changed[k], { reset: true }); | ||
} | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
get: function(model, path) { | ||
return model.get(path); | ||
}, | ||
set: function(model, path, value) { | ||
model.set(path, value); | ||
return true; | ||
}, | ||
keys: function(model) { | ||
return model.keys(); | ||
}, | ||
merge: function(model, mixin) { | ||
if (!Temple.util.isPlainObject(mixin)) return false; | ||
for (var k in mixin) this.set(k, mixin[k]); | ||
return true; | ||
}, | ||
deleteProperty: function(model, path) { | ||
model.unset(path); | ||
return true; | ||
}, | ||
destroy: function(model) { | ||
this.stopListening(model); | ||
// AMD? | ||
else if ( typeof define === 'function' && define.amd ) { | ||
define([ 'temple-mustache', 'backbone' ], factory ); | ||
} | ||
} | ||
var CollectionHandler = { | ||
match: function(col) { | ||
return col instanceof Backbone.Collection; | ||
}, | ||
construct: function(col) { | ||
var self = this, | ||
model_cache = col.toArray(); | ||
// browser global | ||
else if ( global.Mustache && global.Backbone ) { | ||
factory( global.Mustache, global.Backbone ); | ||
} | ||
this.set("length", col.length); | ||
else { | ||
throw new Error( 'Could not find Temple Mustache or Backbone!' ); | ||
} | ||
this.listenTo(col, "add remove sort reset", function() { | ||
var models = col.toArray(); | ||
}( typeof window !== 'undefined' ? window : this, function ( Mustache, Backbone ) { | ||
models.forEach(function(model, index) { | ||
self.set(index.toString(), model); | ||
self.set(model.cid, model); | ||
if (model.id != null) self.set(model.id, model); | ||
}); | ||
Mustache.registerPlugin("backbone", function() { | ||
this.registerProxy(ModelProxy); | ||
this.registerProxy(CollectionProxy); | ||
}); | ||
// calculate difference between old and new | ||
var diff = model_cache.filter(function(model) { | ||
return models.indexOf(model) < 0; | ||
var ModelProxy = Mustache.Proxy.extend({ | ||
constructor: function(target, model) { | ||
this.target = target; | ||
this.model = model; | ||
this.target.on("change", this._onChange = function() { | ||
for (var k in this.changed) { | ||
model.set(k, this.changed[k], { reset: true }); | ||
} | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
get: function(path) { | ||
return ModelProxy.get(this.target, path); | ||
}, | ||
set: function(path, value) { | ||
this.target.set(path, value); | ||
return true; | ||
}, | ||
keys: function() { | ||
return this.target.keys(); | ||
}, | ||
unset: function(path) { | ||
this.target.unset(path); | ||
return true; | ||
}, | ||
merge: function(mixin) { | ||
if (!Mustache.util.isPlainObject(mixin)) return false; | ||
this.target.set(mixin); | ||
return true; | ||
}, | ||
destroy: function() { | ||
this.target.off("change", this._onChange); | ||
} | ||
}, { | ||
match: function(target) { | ||
return target instanceof Backbone.Model; | ||
}, | ||
get: function(target, path) { | ||
return target.get(path); | ||
} | ||
}); | ||
// remove old models | ||
if (diff.length) { | ||
diff.forEach(function(model) { | ||
self.unset(model.cid); | ||
if (model.id != null) self.unset(model.id); | ||
var CollectionProxy = Mustache.Proxy.extend({ | ||
constructor: function(target, model) { | ||
this.target = target; | ||
this.model = model; | ||
var model_cache = target.toArray(); | ||
this.set("length", target.length); | ||
this.listenTo(target, "add remove sort reset", function() { | ||
var models = target.toArray(); | ||
models.forEach(function(m, index) { | ||
model.set(index.toString(), m); | ||
model.set(m.cid, m); | ||
if (m.id != null) model.set(m.id, m); | ||
}); | ||
for (var i = 0; i < diff.length; i++) { | ||
self.unset((models.length + i).toString()); | ||
// calculate difference between old and new | ||
var diff = model_cache.filter(function(m) { | ||
return models.indexOf(m) < 0; | ||
}); | ||
// remove old models | ||
if (diff.length) { | ||
diff.forEach(function(m) { | ||
model.unset(m.cid); | ||
if (m.id != null) model.unset(m.id); | ||
}); | ||
for (var i = 0; i < diff.length; i++) { | ||
model.unset((models.length + i).toString()); | ||
} | ||
} | ||
} | ||
model_cache = models; | ||
self.set("length", col.length); | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
toArray: function(col) { | ||
return col.toArray(); | ||
}, | ||
get: function(col, path) { | ||
if (path === "length") return col.length; | ||
return col.at(path) || col.get(path); | ||
}, | ||
set: function(col, path, value) { | ||
return true; | ||
}, | ||
keys: function(col) { | ||
return Object.keys(col.toArray()); | ||
}, | ||
merge: function(col, mixin) { | ||
return false; | ||
}, | ||
deleteProperty: function(col, path) { | ||
return true; | ||
}, | ||
destroy: function(col) { | ||
this.stopListening(col); | ||
} | ||
} | ||
},{"templejs":"+QSU3/"}]},{},[1]) | ||
(1) | ||
}); | ||
model_cache = models; | ||
model.set("length", target.length); | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
toArray: function() { | ||
return this.target.toArray(); | ||
}, | ||
get: function(path) { | ||
return CollectionProxy.get(this.target, path); | ||
}, | ||
set: function(path, value) { | ||
return true; | ||
}, | ||
keys: function() { | ||
return Object.keys(this.target.toArray()); | ||
}, | ||
unset: function(path) { | ||
return true; | ||
}, | ||
merge: function(mixin) { | ||
return false; | ||
}, | ||
destroy: function() { | ||
this.stopListening(this.target); | ||
} | ||
}, { | ||
match: function(target) { | ||
return target instanceof Backbone.Collection; | ||
}, | ||
get: function(target, path) { | ||
if (path === "length") return target.length; | ||
return target.at(path) || target.get(path); | ||
} | ||
}); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),(b.Temple||(b.Temple={})).Backbone=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){var c=function(){return this.Backbone?this.Backbone:a("backbone")}.call("undefined"!=typeof window?window:this),d=function(){return this.Temple?this.Temple:a("templejs")}.call("undefined"!=typeof window?window:this);b.exports=function(){this.handle(e),this.handle(f)};var e={match:function(a){return a instanceof c.Model},construct:function(a){this.listenTo(a,"change",function(){for(var b in a.changed)this.set(b,a.changed[b],{reset:!0})})},isLeaf:function(){return!1},get:function(a,b){return a.get(b)},set:function(a,b,c){return a.set(b,c),!0},keys:function(a){return a.keys()},merge:function(a,b){if(!d.util.isPlainObject(b))return!1;for(var c in b)this.set(c,b[c]);return!0},deleteProperty:function(a,b){return a.unset(b),!0},destroy:function(a){this.stopListening(a)}},f={match:function(a){return a instanceof c.Collection},construct:function(a){var b=this,c=a.toArray();this.set("length",a.length),this.listenTo(a,"add remove sort reset",function(){var d=a.toArray();d.forEach(function(a,c){b.set(c.toString(),a),b.set(a.cid,a),null!=a.id&&b.set(a.id,a)});var e=c.filter(function(a){return d.indexOf(a)<0});if(e.length){e.forEach(function(a){b.unset(a.cid),null!=a.id&&b.unset(a.id)});for(var f=0;f<e.length;f++)b.unset((d.length+f).toString())}c=d,b.set("length",a.length)})},isLeaf:function(){return!1},toArray:function(a){return a.toArray()},get:function(a,b){return"length"===b?a.length:a.at(b)||a.get(b)},set:function(){return!0},keys:function(a){return Object.keys(a.toArray())},merge:function(){return!1},deleteProperty:function(){return!0},destroy:function(a){this.stopListening(a)}}},{templejs:"+QSU3/"}]},{},[1])(1)}); | ||
!function(a,b){"use strict";if("undefined"!=typeof module&&module.exports&&"function"==typeof require)b(require("temple-mustache"),require("backbone"));else if("function"==typeof define&&define.amd)define(["temple-mustache","backbone"],b);else{if(!a.Mustache||!a.Backbone)throw new Error("Could not find Temple Mustache or Backbone!");b(a.Mustache,a.Backbone)}}("undefined"!=typeof window?window:this,function(a,b){a.registerPlugin("backbone",function(){this.registerProxy(c),this.registerProxy(d)});var c=a.Proxy.extend({constructor:function(a,b){this.target=a,this.model=b,this.target.on("change",this._onChange=function(){for(var a in this.changed)b.set(a,this.changed[a],{reset:!0})})},isLeaf:function(){return!1},get:function(a){return c.get(this.target,a)},set:function(a,b){return this.target.set(a,b),!0},keys:function(){return this.target.keys()},unset:function(a){return this.target.unset(a),!0},merge:function(b){return a.util.isPlainObject(b)?(this.target.set(b),!0):!1},destroy:function(){this.target.off("change",this._onChange)}},{match:function(a){return a instanceof b.Model},get:function(a,b){return a.get(b)}}),d=a.Proxy.extend({constructor:function(a,b){this.target=a,this.model=b;var c=a.toArray();this.set("length",a.length),this.listenTo(a,"add remove sort reset",function(){var d=a.toArray();d.forEach(function(a,c){b.set(c.toString(),a),b.set(a.cid,a),null!=a.id&&b.set(a.id,a)});var e=c.filter(function(a){return d.indexOf(a)<0});if(e.length){e.forEach(function(a){b.unset(a.cid),null!=a.id&&b.unset(a.id)});for(var f=0;f<e.length;f++)b.unset((d.length+f).toString())}c=d,b.set("length",a.length)})},isLeaf:function(){return!1},toArray:function(){return this.target.toArray()},get:function(a){return d.get(this.target,a)},set:function(){return!0},keys:function(){return Object.keys(this.target.toArray())},unset:function(){return!0},merge:function(){return!1},destroy:function(){this.stopListening(this.target)}},{match:function(a){return a instanceof b.Collection},get:function(a,b){return"length"===b?a.length:a.at(b)||a.get(b)}})}); |
@@ -5,15 +5,5 @@ module.exports = function(grunt) { | ||
pkg: grunt.file.readJSON('package.json'), | ||
browserify: { | ||
dist: { | ||
src: "lib/backbone.js", | ||
dest: "dist/temple.backbone.js", | ||
options: { | ||
external: [ "templejs", "backbone" ], | ||
bundleOptions: { standalone: "Temple.Backbone" } | ||
} | ||
} | ||
}, | ||
wrap2000: { | ||
dist: { | ||
src: 'dist/temple.backbone.js', | ||
src: 'lib/backbone.js', | ||
dest: 'dist/temple.backbone.js' | ||
@@ -33,8 +23,7 @@ }, | ||
grunt.loadNpmTasks('grunt-browserify'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-wrap2000'); | ||
grunt.registerTask('default', [ 'browserify', 'wrap2000', 'uglify' ]); | ||
grunt.registerTask('default', [ 'wrap2000', 'uglify' ]); | ||
} |
@@ -1,116 +0,144 @@ | ||
var Backbone = (function() { | ||
if (this.Backbone) return this.Backbone; | ||
return require("backbone"); | ||
}).call(typeof window !== "undefined" ? window : this); | ||
(function ( global, factory ) { | ||
var Temple = (function() { | ||
if (this.Temple) return this.Temple; | ||
return require("templejs"); | ||
}).call(typeof window !== "undefined" ? window : this); | ||
'use strict'; | ||
module.exports = function() { | ||
// attach handlers | ||
this.handle(ModelHandler); | ||
this.handle(CollectionHandler); | ||
} | ||
// Common JS (i.e. browserify) environment | ||
if ( typeof module !== 'undefined' && module.exports && typeof require === 'function' ) { | ||
factory( require( 'temple-mustache' ), require( 'backbone' ) ); | ||
} | ||
var ModelHandler = { | ||
match: function(model) { | ||
return model instanceof Backbone.Model; | ||
}, | ||
construct: function(model) { | ||
this.listenTo(model, "change", function() { | ||
for (var k in model.changed) { | ||
this.set(k, model.changed[k], { reset: true }); | ||
} | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
get: function(model, path) { | ||
return model.get(path); | ||
}, | ||
set: function(model, path, value) { | ||
model.set(path, value); | ||
return true; | ||
}, | ||
keys: function(model) { | ||
return model.keys(); | ||
}, | ||
merge: function(model, mixin) { | ||
if (!Temple.util.isPlainObject(mixin)) return false; | ||
for (var k in mixin) this.set(k, mixin[k]); | ||
return true; | ||
}, | ||
deleteProperty: function(model, path) { | ||
model.unset(path); | ||
return true; | ||
}, | ||
destroy: function(model) { | ||
this.stopListening(model); | ||
// AMD? | ||
else if ( typeof define === 'function' && define.amd ) { | ||
define([ 'temple-mustache', 'backbone' ], factory ); | ||
} | ||
} | ||
var CollectionHandler = { | ||
match: function(col) { | ||
return col instanceof Backbone.Collection; | ||
}, | ||
construct: function(col) { | ||
var self = this, | ||
model_cache = col.toArray(); | ||
// browser global | ||
else if ( global.Mustache && global.Backbone ) { | ||
factory( global.Mustache, global.Backbone ); | ||
} | ||
this.set("length", col.length); | ||
else { | ||
throw new Error( 'Could not find Temple Mustache or Backbone!' ); | ||
} | ||
this.listenTo(col, "add remove sort reset", function() { | ||
var models = col.toArray(); | ||
}( typeof window !== 'undefined' ? window : this, function ( Mustache, Backbone ) { | ||
models.forEach(function(model, index) { | ||
self.set(index.toString(), model); | ||
self.set(model.cid, model); | ||
if (model.id != null) self.set(model.id, model); | ||
}); | ||
Mustache.registerPlugin("backbone", function() { | ||
this.registerProxy(ModelProxy); | ||
this.registerProxy(CollectionProxy); | ||
}); | ||
// calculate difference between old and new | ||
var diff = model_cache.filter(function(model) { | ||
return models.indexOf(model) < 0; | ||
var ModelProxy = Mustache.Proxy.extend({ | ||
constructor: function(target, model) { | ||
this.target = target; | ||
this.model = model; | ||
this.target.on("change", this._onChange = function() { | ||
for (var k in this.changed) { | ||
model.set(k, this.changed[k], { reset: true }); | ||
} | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
get: function(path) { | ||
return ModelProxy.get(this.target, path); | ||
}, | ||
set: function(path, value) { | ||
this.target.set(path, value); | ||
return true; | ||
}, | ||
keys: function() { | ||
return this.target.keys(); | ||
}, | ||
unset: function(path) { | ||
this.target.unset(path); | ||
return true; | ||
}, | ||
merge: function(mixin) { | ||
if (!Mustache.util.isPlainObject(mixin)) return false; | ||
this.target.set(mixin); | ||
return true; | ||
}, | ||
destroy: function() { | ||
this.target.off("change", this._onChange); | ||
} | ||
}, { | ||
match: function(target) { | ||
return target instanceof Backbone.Model; | ||
}, | ||
get: function(target, path) { | ||
return target.get(path); | ||
} | ||
}); | ||
// remove old models | ||
if (diff.length) { | ||
diff.forEach(function(model) { | ||
self.unset(model.cid); | ||
if (model.id != null) self.unset(model.id); | ||
var CollectionProxy = Mustache.Proxy.extend({ | ||
constructor: function(target, model) { | ||
this.target = target; | ||
this.model = model; | ||
var model_cache = target.toArray(); | ||
this.set("length", target.length); | ||
this.listenTo(target, "add remove sort reset", function() { | ||
var models = target.toArray(); | ||
models.forEach(function(m, index) { | ||
model.set(index.toString(), m); | ||
model.set(m.cid, m); | ||
if (m.id != null) model.set(m.id, m); | ||
}); | ||
for (var i = 0; i < diff.length; i++) { | ||
self.unset((models.length + i).toString()); | ||
// calculate difference between old and new | ||
var diff = model_cache.filter(function(m) { | ||
return models.indexOf(m) < 0; | ||
}); | ||
// remove old models | ||
if (diff.length) { | ||
diff.forEach(function(m) { | ||
model.unset(m.cid); | ||
if (m.id != null) model.unset(m.id); | ||
}); | ||
for (var i = 0; i < diff.length; i++) { | ||
model.unset((models.length + i).toString()); | ||
} | ||
} | ||
} | ||
model_cache = models; | ||
self.set("length", col.length); | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
toArray: function(col) { | ||
return col.toArray(); | ||
}, | ||
get: function(col, path) { | ||
if (path === "length") return col.length; | ||
return col.at(path) || col.get(path); | ||
}, | ||
set: function(col, path, value) { | ||
return true; | ||
}, | ||
keys: function(col) { | ||
return Object.keys(col.toArray()); | ||
}, | ||
merge: function(col, mixin) { | ||
return false; | ||
}, | ||
deleteProperty: function(col, path) { | ||
return true; | ||
}, | ||
destroy: function(col) { | ||
this.stopListening(col); | ||
} | ||
} | ||
model_cache = models; | ||
model.set("length", target.length); | ||
}); | ||
}, | ||
isLeaf: function() { return false; }, | ||
toArray: function() { | ||
return this.target.toArray(); | ||
}, | ||
get: function(path) { | ||
return CollectionProxy.get(this.target, path); | ||
}, | ||
set: function(path, value) { | ||
return true; | ||
}, | ||
keys: function() { | ||
return Object.keys(this.target.toArray()); | ||
}, | ||
unset: function(path) { | ||
return true; | ||
}, | ||
merge: function(mixin) { | ||
return false; | ||
}, | ||
destroy: function() { | ||
this.stopListening(this.target); | ||
} | ||
}, { | ||
match: function(target) { | ||
return target instanceof Backbone.Collection; | ||
}, | ||
get: function(target, path) { | ||
if (path === "length") return target.length; | ||
return target.at(path) || target.get(path); | ||
} | ||
}); | ||
})); |
{ | ||
"name": "temple-backbone", | ||
"description": "Adds Backbone specific handlers to Temple.", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"author": "Beneath the Ink <info@beneaththeink.com>", | ||
@@ -21,3 +21,2 @@ "contributors": [ | ||
"grunt": "0.4.5", | ||
"grunt-browserify": "2.1.0", | ||
"grunt-contrib-uglify": "0.4.0", | ||
@@ -24,0 +23,0 @@ "grunt-wrap2000": "0.1.0" |
@@ -20,4 +20,4 @@ describe("Backbone", function() { | ||
function render(template, scope) { | ||
tpl = new Temple.Mustache(template || "<span></span>", scope); | ||
tpl.use(Temple.Backbone); | ||
tpl = new Mustache(template || "<span></span>", scope); | ||
tpl.use("backbone"); | ||
tpl.paint(doc); | ||
@@ -24,0 +24,0 @@ return tpl; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
644988
4
20636
17
8