Created
February 10, 2012 20:29
-
-
Save rockwood/1792543 to your computer and use it in GitHub Desktop.
Flatiron view loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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