Permalink
Browse files

Added beardo.handler example and fixed some typos

  • Loading branch information...
1 parent cd462c9 commit 495b24c09be24d64a7a23e2032d4c1a4cdb979d2 @jxson committed Sep 26, 2012
View
@@ -1,6 +1,6 @@
# beardo
-Provides an easy way to use layout aware mustache templates in your [node.js][node] projects. Add mustache files to a templates directory and use `beardo`'s methods to simply asynchronously read and render them as appropriate for your setup.
+Provides an easy way to use layout aware mustache templates in your [node.js][node] projects. Add mustache files to a templates directory and use `beardo`'s methods to asynchronously read and render them as appropriate for your setup.
If you are using one of the http handlers (`beardo.middleware`, `beardo.handler`) [ETags][etags] get automatically added and 304 responses occur based on the `if-none-match` request header.
@@ -0,0 +1,28 @@
+var http = require('http')
+ , path = require('path')
+ , beardo = require('../')
+ , beardopts = { directory: path.resolve(__dirname, './templates') }
+ , server
+
+server = http.createServer(function(req, res) {
+ res.template = beardo.handler(req, res, beardopts)
+
+ switch (req.url) {
+ case '/':
+ var context = { title: 'Basic template with a layout'
+ , layout: 'default'
+ }
+
+ return res.template('index', context)
+
+ case '/text':
+ res.setHeader('content-type', 'text/plain')
+
+ return res.template('plain-text', { text: 'foo' })
+
+ default:
+ return res.template('404', 404)
+ }
+})
+
+server.listen(1337)
@@ -0,0 +1 @@
+<h1>404</h1>
@@ -0,0 +1 @@
+<p>Index</p>
@@ -0,0 +1 @@
+{{{ yield }}}
@@ -0,0 +1 @@
+{{ text }} bar

0 comments on commit 495b24c

Please sign in to comment.