1.0.7 • Published 9 years ago

a-simple-templater v1.0.7

Weekly downloads
11
License
BSD
Repository
github
Last release
9 years ago

a-simple-templater

NPM

Make your routes. Uses mustache templates by default.

Your index.js

var templater = require('a-simple-templater');
var fs = require('fs')

var routes = [
  {
    url: '/',
    template: '<h1>{{title}}</h1>',
    data: function (params, cb)  {
      cb({
        title: 'hey whats up ' + params.id
      })
    }
  },
  {
    url: '/hello/:id',
    template: fs.readFileSync('templates/blog.html').toString(),
    data: function (params, cb) {
      cb({
        greeting: 'hello',
        place: 'world'
      })
    },
    onrender: function (params, data) {
      console.log('hello', data.place, params.id)
    }
  }
]

templater('#content', routes)

Your index.html

<html>
<body>
  <div id="content"></div>
  <script type="text/javascript" src="/bundle.js"></script>
</body>
</html>

A trick for gh-pages:

Rename index.html to 404.html and then symlink index to 404.

ln -s 404.html index.html

Overriding the default rendering engine (mustache) to use handlebars, for example:

var Handlebars = require('handlebars')
templater('#content', routes, function (source, data) {
  var template = Handlebars.compile(source)
  return template(data)
})

TODO

  • handle 404s correctly. make the 404.html trick for gh-pages not be necessary
1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago