Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-simple-templater

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-simple-templater

make a simple templated website

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 21 May 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc