RazorJS
RazorJS copied to clipboard
A simple JavaScript implementation of the Razor view engine for browsers and Node.
RazorJS
A JavaScript implementation of the Razor view engine that aims to be simple and compatible for use both in the browser and in Node--simple enough for templating:
Razor.compile('hello @model.name')({ name: 'world' }) == 'hello world'
As well as a Node view-engine:
var http = require('http'),
url = require('url'),
Razor = require('../bin/node/Razor.js');
http.createServer(function (req, res) {
var uri = url.parse(req.url),
path = uri.pathname.substr(1) || 'index';
Razor.view(path, function(template) {
if(template) {
template({ name: 'Andy Edinborough' }, function(html){
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
});
}
else {
res.writeHead(404, {'Content-Type': 'text/html'});
res.end('<h1>Not Found</h1>');
}
});
}).listen(1337, "127.0.0.1");
Live Demo
Try RazorJS in your browser now: http://jsbin.com/imihov/latest
Syntax
Description | Code | Notes |
---|
shamelessly stolen from @haacked (http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx) and modified for RazorJS