GithubHelp home page GithubHelp logo

tplcpl's Introduction

TplCpl - templates compiler

This is a command-line utility to compile javascript templates (currently Jade and Underscore) for use client-side.

TplCpl compiles a whole directory of your project's templates into single JS-file and optionally minifies them with Uglify.js.

Using compiler

Under Linux:

Install TplCpl from npm:

sudo -g npm install tplcpl

tplcpl --help

Global (-g) installation is preferred to use the command line tool.

Usage:

tplcpl -t path/to/templates -o path/to/templates.js -c

You have to pass -t and -o options - templates directory and output JS-file respectively. -c option means "compress" - minify output file with Uglify.js.

During compilation a directory is traversed recursively.

Template engine to compile with is chosen by file's extension.

Jade templates must have .jade extension, underscore templates - .us extension.

Under Windows:

Download and run tplcpl-setup.exe Windows installer

TplCpl is installed to C:\tplcpl.

C:\tplcpl\bin\tplcpl -t path\to\templates -o path\to\templates.js -c

Under windows please avoid spaces in paths.

Using compiled templates

After templates are compiled, they may be used as following:

var html = Templating.tpl('my/template.jade', {foo:'bar'});
console.log(html);

A Templating namespace provides also a convenient way to add tpl() helper to your javascript "class".

Suppose we have an OOP module like this:

var MyModule = function () {

};
MyModule.prototype.myMethod = function () {

};

//etc...

Then we make:

Templating.enable(MyModule);

Now instances of MyModule will have a tpl() method:

var inst = new MyModule;
var h = inst.tpl('my/template.jade', {foo:'bar'});

Since tpl() is added with Templating.enable, templates rendering functions are bound to the calling object.

So in your jade or underscore templates you can use this variable referring to the object that calls tpl().

Underscore extension

There is a missing feature in Underscore templates - an escaping.

So it is added here.

Now

<%=variable%>

is used to escape special characters in a variable.

To show variable without escaping you should use:

<%-variable%>

Collaboration

I have written TplCpl for private use, so it is not a universal tool.

Feel free to fork it or submit an issue if you want to add any missing features.

tplcpl's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.