Skip to content

Instantly share code, notes, and snippets.

@rockwood
Created February 10, 2012 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rockwood/1792543 to your computer and use it in GitHub Desktop.
Save rockwood/1792543 to your computer and use it in GitHub Desktop.
Flatiron view loader
var flatiron = require('flatiron'),
path = require('path'),
plates = require('plates'),
app = flatiron.app;
app.config.file({ file: path.join(__dirname, 'config', 'config.json') });
app.use(flatiron.plugins.http);
app.use(require("./plugins/load"));
app.router.get('/', function () {
var that = this;
app.load(path.join(__dirname, 'views', 'test.html'), function(err, view){
var data = { "test": "Rockwood" };
this.res.writeHead(200, { 'Content-Type': 'text/html' })
that.res.end(plates.bind(view, data));
});
});
app.listen(3000, function () {
console.log('Application is now started on port 3000');
});
var fs = require('fs');
exports.name = 'Load a file';
exports.attach = function (options) {
this.load = function(path, next){
fs.readFile(path , 'utf8', function(err, fileString){
if(err){
next(err);
} else {
next(null, fileString);
}
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment