Skip to content

Commit

Permalink
some tests with mongodb and views
Browse files Browse the repository at this point in the history
  • Loading branch information
lancejpollard committed Feb 23, 2012
1 parent 50d0920 commit c583c48
Show file tree
Hide file tree
Showing 30 changed files with 619 additions and 406 deletions.
11 changes: 8 additions & 3 deletions lib/tower/application/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ Tower.Application = (function(_super) {
};

Application.prototype.watch = function() {
var child, forever;
var child, forever,
_this = this;
forever = require("forever");
child = new forever.Monitor("node_modules/design.io/bin/design.io", {
max: 3,
Expand All @@ -206,16 +207,20 @@ Tower.Application = (function(_super) {
ext = path.match(/\.(\w+)$/g);
if (ext) ext = ext[0];
if (ext && ext.match(/(js|coffee)/) && action.match(/(updated|deleted)/)) {
delete require.cache[require.resolve(path)];
_this.fileChanged(path);
}
return _;
});
} catch (error) {
return this;
return _this;
}
});
};

Application.prototype.fileChanged = function(path) {
return delete require.cache[require.resolve(path)];
};

return Application;

})(Tower.Class);
Expand Down
1 change: 1 addition & 0 deletions lib/tower/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Tower.Command = {
run: function(argv) {
var command;
command = argv[2];
if (!!command.match(/^-/)) command = "server";
if (!command) {
throw new Error("You must give tower a command (e.g. 'tower new my-app' or 'tower server')");
}
Expand Down
1 change: 1 addition & 0 deletions lib/tower/generator/generators/tower/app/templates/pack
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"async": ">= 0.0.1",
"mocha": ">= 0.12.1",
"chai": ">= 0.3.3",
"sinon": ">= 1.3.1",
"design.io": ">= 0.1.0",
"design.io-javascripts": ">= 0.0.1",
"design.io-stylesheets": ">= 0.0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
global.chai = require "chai"
global.assert = chai.assert
global.expect = chai.expect
global.chai = require "chai"
global.assert = chai.assert
global.expect = chai.expect
global.sinon = require 'sinon'
31 changes: 17 additions & 14 deletions lib/tower/model/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ Tower.Model.Scope = (function(_super) {
if (options == null) options = {};
this.model = options.model;
this.criteria = options.criteria || new Tower.Model.Criteria;
this.store = this.model.store();
}

Scope.prototype.store = function() {
return this.model.store();
};

Scope.prototype.find = function() {
var callback, conditions, criteria, options, _ref, _ref2;
_ref = this._extractArgs(arguments, {
Expand All @@ -32,31 +35,31 @@ Tower.Model.Scope = (function(_super) {
Scope.prototype.first = function(callback) {
var conditions, options, _ref;
_ref = this.toQuery("asc"), conditions = _ref.conditions, options = _ref.options;
return this.store.findOne(conditions, options, callback);
return this.store().findOne(conditions, options, callback);
};

Scope.prototype.last = function(callback) {
var conditions, options, _ref;
_ref = this.toQuery("desc"), conditions = _ref.conditions, options = _ref.options;
return this.store.findOne(conditions, options, callback);
return this.store().findOne(conditions, options, callback);
};

Scope.prototype.all = function(callback) {
var conditions, options, _ref;
_ref = this.toQuery(), conditions = _ref.conditions, options = _ref.options;
return this.store.find(conditions, options, callback);
return this.store().find(conditions, options, callback);
};

Scope.prototype.count = function(callback) {
var conditions, options, _ref;
_ref = this.toQuery(), conditions = _ref.conditions, options = _ref.options;
return this.store.count(conditions, options, callback);
return this.store().count(conditions, options, callback);
};

Scope.prototype.exists = function(callback) {
var conditions, options, _ref;
_ref = this.toQuery(), conditions = _ref.conditions, options = _ref.options;
return this.store.exists(conditions, options, callback);
return this.store().exists(conditions, options, callback);
};

Scope.prototype.batch = function() {};
Expand Down Expand Up @@ -138,9 +141,9 @@ Tower.Model.Scope = (function(_super) {

Scope.prototype._find = function(conditions, options, callback) {
if (conditions.id && conditions.id.hasOwnProperty("$in") && conditions.id.$in.length === 1) {
return this.store.findOne(conditions, options, callback);
return this.store().findOne(conditions, options, callback);
} else {
return this.store.find(conditions, options, callback);
return this.store().find(conditions, options, callback);
}
};

Expand All @@ -150,11 +153,11 @@ Tower.Model.Scope = (function(_super) {
result = [];
for (_i = 0, _len = attributes.length; _i < _len; _i++) {
object = attributes[_i];
result.push(this.store.serializeModel(Tower.Support.Object.extend({}, conditions, object)));
result.push(this.store().serializeModel(Tower.Support.Object.extend({}, conditions, object)));
}
return result;
} else {
return this.store.serializeModel(Tower.Support.Object.extend({}, conditions, attributes));
return this.store().serializeModel(Tower.Support.Object.extend({}, conditions, attributes));
}
};

Expand Down Expand Up @@ -184,7 +187,7 @@ Tower.Model.Scope = (function(_super) {
}
});
} else {
return this.store.create(data, opts, callback);
return this.store().create(data, opts, callback);
}
};

Expand All @@ -197,7 +200,7 @@ Tower.Model.Scope = (function(_super) {
};
return this._each(conditions, options, iterator, callback);
} else {
return this.store.update(data, conditions, options, callback);
return this.store().update(data, conditions, options, callback);
}
};

Expand All @@ -210,13 +213,13 @@ Tower.Model.Scope = (function(_super) {
};
return this._each(conditions, options, iterator, callback);
} else {
return this.store.destroy(conditions, options, callback);
return this.store().destroy(conditions, options, callback);
}
};

Scope.prototype._each = function(conditions, options, iterator, callback) {
var _this = this;
return this.store.find(conditions, options, function(error, records) {
return this.store().find(conditions, options, function(error, records) {
if (error) {
return callback.call(_this, error, records);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/tower/store/mongodb/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Tower.Store.MongoDB.Finders = {
delete attributes._id;
return new klass(attributes);
},
find: function(query, options, callback) {
find: function(conditions, options, callback) {
var self;
self = this;
query = this.serializeQuery(query);
conditions = this.serializeQuery(conditions);
options = this.serializeOptions(options);
this.collection().find(query, options).toArray(function(error, docs) {
this.collection().find(conditions, options).toArray(function(error, docs) {
var doc, _i, _len;
if (!error) {
for (_i = 0, _len = docs.length; _i < _len; _i++) {
Expand Down
2 changes: 2 additions & 0 deletions lib/tower/store/mongodb/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ Tower.Store.MongoDB.Persistence = {
return this;
},
destroy: function(query, options, callback) {
console.log("DESTRO");
query = this.serializeQuery(query);
options = this.serializeOptions(options);
console.log("DESTROY!");
this.collection().remove(query, options, function(error) {
if (callback) return callback.call(this, error);
});
Expand Down
42 changes: 17 additions & 25 deletions lib/tower/view/helpers/headHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,25 @@ Tower.View.HeadHelper = {
return result.join();
},
openGraphMetaTags: function(options) {
var result;
if (options == null) options = {};
result = [];
if (options.title) result.push(openGraphMetaTag("og:title", options.title));
if (options.type) result.push(openGraphMetaTag("og:type", options.type));
if (options.image) result.push(openGraphMetaTag("og:image", options.image));
if (options.site) result.push(openGraphMetaTag("og:siteName", options.site));
if (options.title) openGraphMetaTag("og:title", options.title);
if (options.type) openGraphMetaTag("og:type", options.type);
if (options.image) openGraphMetaTag("og:image", options.image);
if (options.site) openGraphMetaTag("og:siteName", options.site);
if (options.description) {
result.push(openGraphMetaTag("og:description", options.description));
}
if (options.email) result.push(openGraphMetaTag("og:email", options.email));
if (options.phone) {
result.push(openGraphMetaTag("og:phoneNumber", options.phone));
}
if (options.fax) result.push(openGraphMetaTag("og:faxNumber", options.fax));
if (options.lat) result.push(openGraphMetaTag("og:latitude", options.lat));
if (options.lng) result.push(openGraphMetaTag("og:longitude", options.lng));
if (options.street) {
result.push(openGraphMetaTag("og:street-address", options.street));
}
if (options.city) result.push(openGraphMetaTag("og:locality", options.city));
if (options.state) result.push(openGraphMetaTag("og:region", options.state));
if (options.zip) result.push(openGraphMetaTag("og:postal-code", options.zip));
if (options.country) {
result.push(openGraphMetaTag("og:country-name", options.country));
}
return result.join("\n");
openGraphMetaTag("og:description", options.description);
}
if (options.email) openGraphMetaTag("og:email", options.email);
if (options.phone) openGraphMetaTag("og:phoneNumber", options.phone);
if (options.fax) openGraphMetaTag("og:faxNumber", options.fax);
if (options.lat) openGraphMetaTag("og:latitude", options.lat);
if (options.lng) openGraphMetaTag("og:longitude", options.lng);
if (options.street) openGraphMetaTag("og:street-address", options.street);
if (options.city) openGraphMetaTag("og:locality", options.city);
if (options.state) openGraphMetaTag("og:region", options.state);
if (options.zip) openGraphMetaTag("og:postal-code", options.zip);
if (options.country) openGraphMetaTag("og:country-name", options.country);
return null;
},
openGraphMetaTag: function(property, content) {
return meta({
Expand Down
55 changes: 31 additions & 24 deletions lib/tower/view/helpers/renderingHelper.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@

Tower.View.RenderingHelper = {
partial: function(path, options, callback) {
var item, name, prefixes, template, tmpl, _i, _len, _ref;
if (typeof options === "function") {
callback = options;
options = {};
}
options || (options = {});
path = path.split("/");
path[path.length - 1] = "_" + path[path.length - 1];
path = path.join("/");
prefixes = options.prefixes;
if (this._context) prefixes || (prefixes = [this._context.collectionName]);
template = this._readTemplate(path, prefixes, options.type || Tower.View.engine);
template = this.renderWithEngine(String(template));
tmpl = "(function() {" + (String(template)) + "})";
if (options.collection) {
name = options.as || Tower.Support.String.camelize(options.collection[0].constructor.name, true);
_ref = options.collection;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
item = _ref[_i];
this[name] = item;
eval(tmpl).call(this);
delete this[name];
var item, locals, name, prefixes, template, tmpl, _i, _len, _ref;
try {
if (typeof options === "function") {
callback = options;
options = {};
}
} else {
eval(tmpl).call(this);
options || (options = {});
options.locals || (options.locals = {});
locals = options.locals;
path = path.split("/");
path[path.length - 1] = "_" + path[path.length - 1];
path = path.join("/");
prefixes = options.prefixes;
if (this._context) prefixes || (prefixes = [this._context.collectionName]);
template = this._readTemplate(path, prefixes, options.type || Tower.View.engine);
template = this.renderWithEngine(String(template));
if (options.collection) {
name = options.as || Tower.Support.String.camelize(options.collection[0].constructor.name, true);
tmpl = eval("(function(data) { with(data) { this." + name + " = " + name + "; " + (String(template)) + " } })");
_ref = options.collection;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
item = _ref[_i];
locals[name] = item;
tmpl.call(this, locals);
delete this[name];
}
} else {
tmpl = "(function(data) { with(data) { " + (String(template)) + " } })";
eval(tmpl).call(this, locals);
}
} catch (error) {
console.log(error);
}
return null;
},
Expand Down
5 changes: 4 additions & 1 deletion lib/tower/view/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Tower.View.Rendering = {
},
partial: function(path, options, callback) {
var prefixes, template;
console.log("PARTIAL");
if (typeof options === "function") {
callback = options;
options = {};
Expand Down Expand Up @@ -110,7 +111,9 @@ Tower.View.Rendering = {
renderWithEngine: function(template, engine) {
var mint;
mint = require("mint");
return mint[mint.engine(engine || "coffee")](template, {});
return mint[mint.engine(engine || "coffee")](template, {}, function(error, result) {
if (error) return console.log(error);
});
}
};

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"coffee-script": ">= 1.2.0",
"coffeekup": ">= 0.3.1",
"restler": ">= 0.0.1",
"useragent": ">= 1.0.5"
"useragent": ">= 1.0.5",
"URIjs": ">= 1.4.2"
},
"devDependencies": {
"coffee-script": ">= 1.2.0",
Expand All @@ -67,6 +68,7 @@
"design.io": ">= 0.3.0",
"mocha": ">= 0.8.1",
"chai": ">= 0.3.3",
"sinon": ">= 1.3.1",
"gzip": ">= 0.1.0",
"forever": ">= 0.8.5"
},
Expand Down
11 changes: 8 additions & 3 deletions src/tower/application/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,24 @@ class Tower.Application extends Tower.Class

child.start()

child.on "stdout", (data) ->
child.on "stdout", (data) =>
data = data.toString()
try
# [Sat, 18 Feb 2012 22:49:33 GMT] INFO updated public/stylesheets/vendor/stylesheets/bootstrap/reset.css
data.replace /\[([^\]]+)\] (\w+) (\w+) (.+)/, (_, date, type, action, path) ->
data.replace /\[([^\]]+)\] (\w+) (\w+) (.+)/, (_, date, type, action, path) =>
path = path.split('\033')[0]
ext = path.match(/\.(\w+)$/g)
ext = ext[0] if ext
if ext && ext.match(/(js|coffee)/) && action.match(/(updated|deleted)/)
delete require.cache[require.resolve(path)]
@fileChanged(path)
_
catch error
@

fileChanged: (path) ->
delete require.cache[require.resolve(path)]

if path.match

require './assets'

Expand Down
1 change: 1 addition & 0 deletions src/tower/command.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Tower.Command =
run: (argv) ->
command = argv[2]
command = "server" if !!command.match(/^-/)
throw new Error("You must give tower a command (e.g. 'tower new my-app' or 'tower server')") unless command
command = new Tower.Command[Tower.Support.String.camelize(command)](argv)
command.run()
Expand Down
Loading

0 comments on commit c583c48

Please sign in to comment.