Comparing version 1.2.2 to 1.2.3
32
bones.js
@@ -0,1 +1,6 @@ | ||
if (global.__BonesPlugin__) { | ||
console.trace("\033[0;31mMultiple instances of bones are not supported.\033[0m"); | ||
process.exit(1); | ||
} | ||
exports.$ = require('jquery'); | ||
@@ -19,27 +24,12 @@ exports._ = require('underscore'); | ||
Object.defineProperty(exports, 'plugin', { | ||
get: function() { | ||
if (!global.__BonesPlugin__) { | ||
var Plugin = require('./server/plugin'); | ||
global.__BonesPlugin__ = new Plugin(); | ||
require('./core'); | ||
} | ||
return global.__BonesPlugin__; | ||
} | ||
}); | ||
exports.load = function(dir) { | ||
this.plugin.directories.push(dir); | ||
this.plugin | ||
.require(dir, 'controllers') | ||
.require(dir, 'models') | ||
.require(dir, 'routers') | ||
.require(dir, 'templates') | ||
.require(dir, 'views') | ||
.require(dir, 'servers') | ||
.require(dir, 'commands'); | ||
return exports.plugin.load(dir); | ||
}; | ||
exports.start = function() { | ||
return this.plugin.start(); | ||
return exports.plugin.start(); | ||
}; | ||
var Plugin = require('./server/plugin'); | ||
exports.plugin = global.__BonesPlugin__ = new Plugin(); | ||
exports.plugin.load(__dirname); |
@@ -57,5 +57,6 @@ Backbone.Controller.prototype.route = function(route, name, callback) { | ||
// Generate CSRF protection cookie. Callers should provide the request path | ||
// to ensure the cookie is not pervasive across all requests. | ||
Backbone.csrf = function(path) { | ||
// Generate CSRF protection token that is valid for the specified amount of | ||
// msec. The default is 1 second. Callers should provide the request path to | ||
// ensure the cookie is not pervasive across requests. | ||
Backbone.csrf = function(path, timeout) { | ||
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789'; | ||
@@ -66,3 +67,11 @@ var token = ''; | ||
} | ||
document.cookie = 'bones.token=' + token + ';max-age=60;'; | ||
// Remove hashes, query strings from cookie path. | ||
path = path || '/'; | ||
path = path.split('#')[0].split('?')[0]; | ||
var expires = new Date(+new Date + (timeout || 1000)).toGMTString(); | ||
document.cookie = 'bones.token=' + token | ||
+ ';expires=' + expires | ||
+ ';path=' + path + ';'; | ||
return token; | ||
@@ -82,7 +91,11 @@ }; | ||
if (method !== 'read') { | ||
var clone = model.clone(); | ||
clone.set({ 'bones.token': Backbone.csrf(getUrl(model)) }); | ||
var token = Backbone.csrf(getUrl(model)); | ||
model.set({ 'bones.token': token }, { silent: true }); | ||
var result = parent.call(this, method, model, success, error); | ||
model.unset('bones.token', { silent: true }); | ||
return result; | ||
} else { | ||
return parent.call(this, method, model, success, error); | ||
} | ||
return parent.call(this, method, clone || model, success, error); | ||
}); |
{ | ||
"name": "bones", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
@@ -5,0 +5,0 @@ "main": "./bones.js", |
@@ -39,2 +39,29 @@ var path = require('path'); | ||
// Default template engine. | ||
require.extensions['._'] = function(module, filename) { | ||
var content = fs.readFileSync(filename, 'utf8'); | ||
var name = path.basename(filename).replace(/\..+$/, ''); | ||
try { | ||
module.exports = _.template(content); | ||
Bones.plugin.add(module.exports, filename); | ||
} catch (err) { | ||
var lines = err.message.split('\n'); | ||
lines.splice(1, 0, ' in template ' + filename); | ||
err.message = lines.join('\n'); | ||
throw err; | ||
} | ||
module.exports.register = function(app) { | ||
if (app.assets) { | ||
app.assets.templates.push({ | ||
filename: filename, | ||
content: 'template = ' + module.exports + ';' | ||
}); | ||
} | ||
}; | ||
}; | ||
module.exports = Plugin; | ||
@@ -58,2 +85,16 @@ function Plugin() { | ||
Plugin.prototype.load = function(dir) { | ||
if (this.directories.indexOf(dir) < 0) { | ||
this.directories.push(dir); | ||
this.require(dir, 'controllers'); | ||
this.require(dir, 'models'); | ||
this.require(dir, 'routers'); | ||
this.require(dir, 'templates'); | ||
this.require(dir, 'views'); | ||
this.require(dir, 'servers'); | ||
this.require(dir, 'commands'); | ||
} | ||
return this; | ||
} | ||
Plugin.prototype.require = function(dir, kind) { | ||
@@ -60,0 +101,0 @@ dir = path.join(dir, kind); |
Sorry, the diff of this file is not supported yet
271615
7841
5
80