Skip to content

Commit

Permalink
#27 - merging master
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Trevino committed Mar 30, 2015
2 parents c53ac66 + 2e0ebd4 commit f14ebff
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -59,10 +59,11 @@ jefferson(app, conf);
## Configuration
* **routes** - (*required*) - A map of routes by name. Each object in the map describes an endpoint to be wired. These endpoints must contain an HTTP method, a path, and an array of middleware functions.
* **aliases**: (*optional*) - A map of alias-name to handler chain. Routes may use these aliases in lieu of repeated function groups.
* **proxies**: (*optional*) - An array of proxy objects invoked around all middleware functions in order. Each proxy object should have an init() function that accepts a delegate middleware function and returns a new middleware function.
* **params**: (*optional*) - A map of path-parameter name to resolver functions.
* **pre**: (*optional*) - (object) Boilerplate section of pre-middleware functions
* **post**: (*optional*) - (object) Boilerplate section of post-middleware functions
* **proxies**: (*optional*) - An array of proxy objects invoked around all middleware functions in order. Each proxy object should have an init() function that accepts a delegate middleware function and returns a new middleware function.
* **params**: (*optional*) - A map of path-parameter name to resolver functions.
* **engines**: (*optional*) - An array of objects describing templating engines to use in the app. `{ ext: <string>, callback: <function> }`
* **locals**: (*optional*) - (object) An object that will populate app.locals (http://expressjs.com/api.html#app.locals)

Boilerplate Config Sections (pre/post):
Expand Down
19 changes: 19 additions & 0 deletions src/domain/appsection/engines.js
@@ -0,0 +1,19 @@
"use strict";

/**
* Configures templating engines for an app
*/
class EngineResolver {
constructor(app, conf) {
this.app = app;
this.conf = conf;
}

configure() {
this.conf.engines.forEach((it) => {
this.app.engine(it.ext, it.callback);
});
}
}

module.exports = EngineResolver;
28 changes: 28 additions & 0 deletions src/domain/appsection/engines.test.js
@@ -0,0 +1,28 @@
"use strict";

let chai = require("chai");
let expect = chai.expect;
let EngineConfig = require("./engines");

describe("The 'engines' configuration section", () => {
it("can configure templating engines for an app", () => {
let engines = {};
let app = {
engine (ext, callback) {
engines[ext] = callback;
}
};
let conf = {
engines: [
{
ext: "jade",
callback: () => "derp"
}
]
};

new EngineConfig(app, conf).configure();
expect(engines.jade).to.be.a.function;
expect(engines.jade()).to.equal("derp");
});
});
1 change: 1 addition & 0 deletions src/domain/configuration.js
Expand Up @@ -24,6 +24,7 @@ class Configuration {
this.aliases = conf.aliases || {};
this.proxies = conf.proxies || [];
this.locals = conf.locals || {};
this.engines = conf.engines || [];
this.pre = boilerplateSection(conf.pre);
this.post = boilerplateSection(conf.post);
}
Expand Down
1 change: 1 addition & 0 deletions src/jefferson.js
Expand Up @@ -7,6 +7,7 @@ var Configuration = require("./domain/configuration");
var debug = require("debug")("jefferson");
let AppSectionClasses = [
require("./domain/appsection/locals"),
require("./domain/appsection/engines"),
require("./domain/appsection/resolvers"),
require("./domain/appsection/routes")
];
Expand Down

0 comments on commit f14ebff

Please sign in to comment.