Socket
Socket
Sign inDemoInstall

a-simple-templater

Package Overview
Dependencies
5
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    a-simple-templater

make a simple templated website


Version published
Maintainers
1
Install size
239 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 21 May 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc