├── index.js ├── examples ├── views │ ├── fat.mustache │ ├── index.mustache │ ├── nav.mustache │ └── layout.mustache ├── public │ └── application.css └── app.js ├── README.md ├── package.json ├── test └── test.js └── lib └── stache.js /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/stache'); 2 | -------------------------------------------------------------------------------- /examples/views/fat.mustache: -------------------------------------------------------------------------------- 1 | My name is {{name}}, and i wanted to say "{{message}}" -------------------------------------------------------------------------------- /examples/views/index.mustache: -------------------------------------------------------------------------------- 1 | {{helloworld}}!!! You are currently viewing: {{hellopage}}! 2 | 3 | {{>img}} -------------------------------------------------------------------------------- /examples/views/nav.mustache: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Stache is no longer being actively maintained. 2 | ---------------------------------------------- 3 | 4 | But don't worry. Hogan.js is! and it's a part of TJ's consolidate: 5 | 6 | https://github.com/visionmedia/consolidate.js 7 | 8 | Use that instead! :{o 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stache", 3 | "description": "mustache templating for your express apps", 4 | "version": "0.1.0", 5 | "authors": ["Jacob Thornton <@fat>"], 6 | "keywords": ["mustache", "express", "stache"], 7 | "main": "./index.js", 8 | "engines": { "node": ">= 0.4.1" }, 9 | "dependencies": { 10 | "mustache": ">= 0.2.3", 11 | "express": ">= 2.1.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/views/layout.mustache: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
'
33 | }
34 | });
35 | });
36 |
37 | app.get('/user/:name', function (req, res) {
38 | res.render(req.params.name, {
39 | locals: {
40 | title: req.params.name + '\'s page'
41 | , name: req.params.name
42 | , message: 'stache it in your stache!'
43 | }
44 | });
45 | });
46 |
47 | //Run
48 | app.listen(3000);
49 |
50 | console.log('example running on port 3000')
--------------------------------------------------------------------------------
/lib/stache.js:
--------------------------------------------------------------------------------
1 | /*! written by @fat
2 | * but major props to donpark && bitdrift && mustache.js
3 | */
4 | var stache = {}
5 | , fs = require('fs')
6 | , path = require("path")
7 | , mustache = require('mustache')
8 | , views = './views'
9 |
10 | stache.compile = function (source, options) {
11 | views = (options && options.settings && options.settings.views) || views
12 |
13 | if (typeof source == 'string') {
14 | return function (options) {
15 | var partials_regex = new RegExp("{{([>-])([^\\/#\\^]+?)\\1?}}+", "g")
16 | , lines = source.split("\n")
17 | , i = 0
18 | , view
19 |
20 | function tag_replace_callback(match, operator, name) {
21 | if (operator == '>' && !options.partials[name]) {
22 | var partialFileName = views + '/' + name + (options.extension || '.mustache')
23 | return path.existsSync(partialFileName) ? fs.readFileSync(partialFileName, "utf-8") : ""
24 | }
25 | return match
26 | }
27 |
28 | options.partials = options.partials || {}
29 |
30 | if (options.body) {
31 | options.yield = options.body
32 | }
33 |
34 | for (i; i < lines.length; i++) {
35 | lines[i] = lines[i].replace(partials_regex, tag_replace_callback, this)
36 | }
37 |
38 | return mustache.to_html(lines.join('\n'), options, options.partials)
39 | }
40 | } else {
41 | return source
42 | }
43 | };
44 |
45 | stache.render = function(template, options) {
46 | template = stache.compile(template, options)
47 | return template(options)
48 | }
49 |
50 | module.exports = stache
--------------------------------------------------------------------------------