Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bones

Package Overview
Dependencies
Maintainers
0
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bones - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

examples/simple/controllers/Default.bones

62

bones.js

@@ -1,21 +0,21 @@

module.exports = {
$: require('jquery'),
_: require('underscore'),
express: require('express'),
mirror: require('mirror'),
exports.$ = require('jquery');
exports._ = require('underscore');
exports.mirror = require('mirror');
utils: require('bones/server/utils'),
exports.utils = require('bones/server/utils');
exports.middleware = require('bones/server/middleware');
server: true,
exports.server = true;
Backbone: require('bones/server/backbone'),
Controller: require('bones/server/controller'),
Model: require('bones/server/model'),
Collection: require('bones/server/collection'),
Router: require('bones/server/router'),
View: require('bones/server/view'),
Server: require('bones/server/server'),
Command: require('bones/server/command'),
exports.Backbone = require('bones/server/backbone');
exports.Controller = require('bones/server/controller');
exports.Model = require('bones/server/model');
exports.Collection = require('bones/server/collection');
exports.Router = require('bones/server/router');
exports.View = require('bones/server/view');
exports.Server = require('bones/server/server');
exports.Command = require('bones/server/command');
get plugin() {
Object.defineProperty(exports, 'plugin', {
get: function() {
if (!global.__BonesPlugin__) {

@@ -27,19 +27,19 @@ var Plugin = require('./server/plugin');

return global.__BonesPlugin__;
},
}
});
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');
},
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');
};
start: function() {
return this.plugin.start();
}
exports.start = function() {
return this.plugin.start();
};

@@ -41,1 +41,15 @@ Backbone.Controller.prototype.route = function(route, name, callback) {

};
Backbone.History.prototype.getFragment = function(loc) {
var hashStrip = /#!/;
return (loc || window.location).hash.replace(hashStrip, '');
};
Backbone.History.prototype._saveLocation = Backbone.History.prototype.saveLocation;
Backbone.History.prototype.saveLocation = function(fragment) {
var hashStrip = /#!/;
// Next two lines are duplicated withing the original saveLocation method.
fragment = (fragment || '').replace(hashStrip, '');
if (this.fragment == fragment) return;
Backbone.History.prototype._saveLocation('!' + fragment);
};

@@ -18,3 +18,3 @@ $(function() {

} else if (kind === 'view') {
var view = callback(views, templates);
var view = callback(models, views, templates);
views[view.title] = view;

@@ -21,0 +21,0 @@ } else if (kind === 'controller') {

// ---- start __NAME__ view ----
Bones.initialize('view', function(views, templates) {
Bones.initialize('view', function(models, views, templates) {
var view;
var _ = require('underscore');
var path = require('path');
var fs = require('fs');
var bones = require('bones');
var Bones = require('bones');

@@ -11,6 +11,7 @@ require('bones').load(__dirname);

var content = fs.readFileSync(filename, 'utf8');
var name = bones.utils.camelize(path.basename(filename).replace(/\..+$/, ''));
var name = path.basename(filename).replace(/\..+$/, '');
try {
module.exports = _.template(content);
Bones.plugin.add(module.exports, filename);
} catch (err) {

@@ -17,0 +18,0 @@ var lines = err.message.split('\n');

{
"name": "bones",
"version": "1.1.0",
"version": "1.2.0",

@@ -8,8 +8,8 @@ "main": "./bones.js",

"dependencies": {
"underscore": ">= 1.1.6 < 1.2.0",
"express": ">= 2.2.2 < 2.3.0",
"backbone": ">= 0.3.3 < 0.4.0",
"jquery": ">= 1.5.1 < 1.6.0",
"optimist": ">= 0.1.9 < 0.2.0",
"mirror": ">= 0.1.0 < 0.2.0"
"underscore": "1.1.x",
"express": "2.2.x",
"backbone": "0.3.x",
"jquery": "1.5.x",
"optimist": "0.1.x",
"mirror": "0.1.x"
},

@@ -16,0 +16,0 @@

@@ -29,2 +29,4 @@ Bones

See https://github.com/developmentseed/skeleton for an example app that layout.
### Application layout

@@ -31,0 +33,0 @@

@@ -56,5 +56,7 @@ var Backbone = require('./backbone');

var context = Object.create(controller, { req: { value: req }, res: { value: res } });
callback.apply(context, args);
callback.apply(context, args.concat([ function(content) {
res.send(content);
}]));
controller.trigger.apply(controller, ['route:' + name].concat(args));
});
};

@@ -1,4 +0,4 @@

var middleware = exports;
exports = module.exports = require('express');
middleware.csrf = function(conf) {
exports['csrf'] = function csrf() {
return function(req, res, next) {

@@ -13,3 +13,17 @@ if (req.method === 'GET') {

}
};
}
};
exports['fragmentRedirect'] = function fragmentRedirect() {
return function(req, res, next) {
// @see https://code.google.com/web/ajaxcrawling/docs/specification.html
if (req.query._escaped_fragment_ === undefined) {
next();
} else {
// Force the first char of the path to be a slash to prevent
// foreign redirects.
var path = '/' + req.query._escaped_fragment_.substr(1);
res.redirect(path, 301);
}
}
};

@@ -7,4 +7,5 @@ var path = require('path');

var _ = require('underscore');
var Bones = require('bones');
var utils = require('bones').utils;
var utils = Bones.utils;

@@ -33,2 +34,6 @@ // Load wrappers

module._compile(content, filename);
if (module.exports) {
Bones.plugin.add(module.exports, filename);
}
};

@@ -54,4 +59,3 @@

Plugin.prototype.require = function(dir, kind) {
var plugin = this, dir = path.join(dir, kind);
dir = path.join(dir, kind);
try {

@@ -63,14 +67,3 @@ fs.readdirSync(dir).sort(alphabetical).forEach(function(name) {

fs.statSync(file).isFile()) {
var component = require(file);
if (component) {
if (!component.files) component.files = [];
component.files.push(file);
if (!component.title) {
component.title = utils.camelize(
path.basename(file).replace(/\..+$/, ''));
}
plugin[kind][component.title] = component;
}
require(file);
}

@@ -85,2 +78,14 @@ });

Plugin.prototype.add = function(component, filename) {
if (!component.files) component.files = [];
component.files.push(filename);
if (!component.title) {
component.title = path.basename(filename).replace(/\..+$/, '');
}
var kind = path.basename(path.dirname(filename));
Bones.plugin[kind][component.title] = component;
};
Plugin.prototype.start = function() {

@@ -87,0 +92,0 @@ this.argv = require('optimist').argv;

@@ -6,3 +6,3 @@ var Bones = require('bones');

var Backbone = Bones.Backbone;
var express = Bones.express;
var middleware = Bones.middleware;
var mirror = Bones.mirror;

@@ -9,0 +9,0 @@

var Backbone = require('./backbone');
var _ = require('underscore');
var express = require('express');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var middleware = require('..').middleware;
module.exports = Server;
util.inherits(Server, EventEmitter);
function Server(plugin) {

@@ -19,2 +22,3 @@ this.plugin = plugin;

this.middleware(plugin);
this.initialize(plugin);

@@ -34,6 +38,13 @@ };

middleware: function(plugin) {
this.server.use(middleware.bodyParser());
this.server.use(middleware.cookieParser());
this.server.use(middleware.csrf());
this.server.use(middleware.fragmentRedirect());
},
port: 3000,
start: function() {
this.server.listen(this.port);
start: function(callback) {
this.server.listen(this.port, callback);
return this;

@@ -40,0 +51,0 @@ },

@@ -6,3 +6,3 @@ var Bones = require('bones');

var Backbone = Bones.Backbone;
var express = Bones.express;
var middleware = Bones.middleware;
var mirror = Bones.mirror;

@@ -9,0 +9,0 @@

@@ -48,3 +48,3 @@ var utils = module.exports = require('../shared/utils');

var kind = utils.singularize(path.basename(path.dirname(filename)));
var name = utils.camelize(path.basename(filename).replace(/\..+$/, ''));
var name = path.basename(filename).replace(/\..+$/, '');

@@ -51,0 +51,0 @@ wrappers[kind] = wrappers[kind] || {};

@@ -7,2 +7,3 @@ var Bones = require('bones');

var models = Bones.plugin.models;
var views = Bones.plugin.views;

@@ -9,0 +10,0 @@ var templates = Bones.plugin.templates;

@@ -8,14 +8,2 @@ var Bones = Bones || {};

Bones.utils.camelize = function(text) {
return text.replace(/(?:^|_)(.)/g, function(all, chr) {
return chr.toUpperCase();
});
};
Bones.utils.underscoreify = function(text) {
return text.replace(/[A-Z]/g, function(match) {
return '_'+ match.toLowerCase();
}).replace(/^_/, '');
};
// From https://github.com/visionmedia/lingo/blob/master/lib/languages/en.js

@@ -22,0 +10,0 @@ Bones.utils.uncountable = [ 'advice', 'enegery', 'excretion', 'digestion',

@@ -9,3 +9,3 @@ var assert = require('assert');

assert.response(main.server, {
url: '/api/house',
url: '/api/House',
method: 'GET'

@@ -12,0 +12,0 @@ }, {

@@ -52,2 +52,15 @@ var assert = require('assert');

}, {
body: 'Forbidden',
status: 403
});
assert.response(main.server, {
url: '/page/foo',
method: 'POST',
headers: {
'content-type': 'application/json',
'cookie': 'bones.token=1f4a1137268b8e384e50d0fb72c627c4'
},
body: '{"bones.token":"1f4a1137268b8e384e50d0fb72c627c4"}'
}, {
body: 'Cannot POST /page/foo',

@@ -60,3 +73,3 @@ status: 404

assert.response(main.server, {
url: '/api/page/foo',
url: '/api/Page/foo',
method: 'GET'

@@ -70,5 +83,16 @@ }, {

url: '/api/page/foo',
method: 'GET'
}, {
body: 'Cannot GET /api/page/foo',
status: 404
});
assert.response(main.server, {
url: '/api/Page/foo',
method: 'PUT',
headers: { 'content-type': 'application/json' },
body: '{"id":"foo","key":"value"}'
headers: {
'content-type': 'application/json',
'cookie': 'bones.token=1f4a1137268b8e384e50d0fb72c627c4'
},
body: '{"bones.token":"1f4a1137268b8e384e50d0fb72c627c4","id":"foo","key":"value"}'
}, {

@@ -75,0 +99,0 @@ body: '{"id":"foo","key":"value","method":"update"}',

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc