Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #49 from edwardhotchkiss/master

sync
  • Loading branch information...
commit 330faa8827d095c27d2ff7ea59ea6a8263318c28 2 parents edf786f + c19e3df
Edward Hotchkiss authored
View
10 lib/blueprint/loader.js
@@ -33,8 +33,8 @@ function models(directory) {
});
};
-function controllers(directory) {
- directory = process.cwd() + (directory || "/app/controllers");
+function controllers(directory, app) {
+ directory = process.cwd() + directory || "/app/controllers";
fs.readdir(path.normalize(directory), function(error, files) {
if (error) {
if (new RegExp(/ENOENT/).test(error.message)) {
@@ -48,17 +48,17 @@ function controllers(directory) {
return;
};
var controller = file.replace(".js", "");
- require(directory+"/"+controller);
+ require(directory+"/"+controller)(app);
});
};
});
};
-var load = exports.load = function(which, directory) {
+var load = exports.load = function(which, directory, app) {
if (which === "models") {
models(directory);
} else if (which === "controllers") {
- controllers(directory);
+ controllers(directory, app);
} else {
throw new Error("usage: blueprint --help");
};
View
1  lib/blueprint/router.js
@@ -89,7 +89,6 @@ var logger = function(request, response) {
var staticHandler = function(request, response) {
var staticFile = path.normalize(process.cwd() + "/public" + request.url);
- console.log(staticFile);
fs.stat(staticFile, function(error, results) {
if (error) {
response.redirect("/404.html", 404);
View
4 templates/app.js
@@ -22,8 +22,8 @@ blueprint.conf.use();
load|require /controllers
*/
-blueprint.load("models");
-blueprint.load("controllers");
+blueprint.load("models", "/app/models/");
+blueprint.load("controllers", "/app/controllers/", app);
// connect to mongodb via mongoose
mongoose.connect(blueprint.conf.get("mongodb"));
View
19 templates/app/controllers/items.js
@@ -0,0 +1,19 @@
+
+/*
+
+ default route
+ fetch all "Item"'s
+
+*/
+
+module.exports = controllers = function(app) {
+ app.get("/", false, function(request, response) {
+ Item.find({}, function(error, items) {
+ if (error) {
+ console.error(error);
+ } else {
+ response.send(items);
+ }
+ });
+ });
+};
View
28 templates/app/models/Item.js
@@ -18,6 +18,34 @@ var ItemSchema = new Schema({
var Item = mongoose.model("Item", ItemSchema);
+/*
+ Setup a small mongodb doc
+*/
+
+/*Item.find({}, function(error, items) {
+ if (error) {
+ console.error(error);
+ } else {
+ items.forEach(function(item) {
+ item.remove();
+ });
+ };
+});
+
+var itemA = new Item({
+ title : "Item A",
+ content : "This is item A's content!"
+});
+
+var itemB = new Item({
+ title : "Item B",
+ content : "This is item B's content, excited yet?"
+});
+
+itemA.save();
+itemB.save();
+*/
+
module.exports = Item;
/* EOF */
Please sign in to comment.
Something went wrong with that request. Please try again.