dimples

0.2.1 • Public • Published

Dimples

JavaScript and HTML templates can be just as cute as pair of dimples!

NPM version Travis Codecov License

Intro

A build step that manages Pug templates for use in JavaScript applications. Here's a demo of it being used.

Installation

via npm

npm i dimples --save

Example

Input (app.js)

document.body.innerHTML = '@tpl.Master';

build step

var dimples = require('dimples'),
    fs = require('fs');
 
fs.readFile('app.js', function(e, input) {
    if (!== null) {
        throw e;
    }
 
    var code = (
        new dimples(input, {
            views: './views/',
            compress: false
        })
    ).code;
 
    fs.writeFile('output.js', code);
});

becomes (output.js)

var $dimples = (function(d) {
    return (== void 0) ? ({
        data: {},
        get: function(a) {
            return this.data[a];
        },
        add: function(tpls) {
            for (var key in tpls) {
                if (tpls.hasOwnProperty(key)) this.data[key] = tpls[key];
            }
        }
    }) : d;
})($dimples);
 
$dimples.add({1997400449: '<h1>Hello World</h1>'});
 
document.body.innerHTML = $dimples.get(1997400449);

API

constructor(input: Buffer|string, options: Config)

input is either a Buffer or a string of the source JavaScript options is an object containing 1 required property: views which is the directory of where to start finding templates. Also specify a compress property, which will compress the output of the dimples manager.

.compile(void): Buffer

Returns a Buffer of the new source with pug templates.

.code: string

Returns a string of the new source with pug templates.


Build

  • npm i typscript typings -g
  • npm i
  • typings i
  • npm run build

License

MIT

Copyright(c) 2016 Marais Rossouw

Package Sidebar

Install

npm i dimples

Weekly Downloads

1

Version

0.2.1

License

MIT

Last publish

Collaborators

  • marais