Browse files

update readme and republish stache 0.1.0

  • Loading branch information...
1 parent 8b32172 commit 83bc1236a985870de066c74cf391d7920bce0971 @fat committed Jul 4, 2011
Showing with 53 additions and 24 deletions.
  1. +52 −23 README.md
  2. +1 −1 package.json
View
75 README.md
@@ -9,6 +9,7 @@ Whuuuuuut?
Getting this junk running is SUPER easy! check the deets below...
+
setting it up
-------------
@@ -18,45 +19,72 @@ first...
Now, when you're configuring your express app, just add this little code in somewhere near the top:
- app.set('view engine', 'mustache')
- app.register(".mustache", require('stache'));
+```javascript
+app.set('view engine', 'mustache')
+app.register(".mustache", require('stache'));
+```
*BOOOM!* you're all set!
+
how to actually use it
----------------------
render your views with res.render...
- app.get('/', function (req, res) {
- res.render("index", {
- locals: {
- title: req.params.what
- },
- partials: {
- heading: '<title>{{title}}</title>'
- }
- });
- });
+```javascript
+app.get('/', function (req, res) {
+ res.render("index", {
+ locals: {
+ title: req.params.what
+ },
+ partials: {
+ heading: '<title>{{title}}</title>'
+ }
+ });
+});
+```
Notice you can pass local vars here as well as partials to your templates.
+You can also now use mustache with helpers and dynamicHelpers!
+
+```javascript
+// helpers
+app.helpers({
+ three: function(){
+ return 1 + 2;
+ }
+});
+
+// dynamicHelpers
+app.dynamicHelpers({
+ page: function(req, res){
+ return req.url;
+ }
+});
+```
+
+Reference these just like you would locals:
+```html
+ You are currently viewing: {{page}}
+```
Layouts
-------
Stache supports layouts! *swaggg!* Which means you can have something like this:
-
- <!-- layout.mustache -->
- <html>
- <head>
- {{>scripts}}
- </head>
- <body>
- {{{yield}}}
- </body>
- </html>
-
+```html
+<!-- layout.mustache -->
+<html>
+<head>
+ {{>scripts}}
+</head>
+<body>
+ {{{yield}}}
+</body>
+</html>
+```
Note: yield is a special local var, which will be replaced automatically by the template you specified with res.render.
@@ -65,6 +93,7 @@ Partials
Looking at the example above, check out that partial reference for scripts!! If when calling your res.render method you don't explicitly specify a script partial, stache will automatically check your views directory for a script.mustache to load as a partial. Pretty boss huh?
+
What? I still don't get it...
-----------------------------
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "stache",
"description": "mustache templating for your express apps",
- "version": "0.0.4",
+ "version": "0.1.0",
"authors": ["Jacob Thornton <@fat>"],
"keywords": ["mustache", "express", "stache"],
"main": "./index.js",

0 comments on commit 83bc123

Please sign in to comment.