templatejs

Node.js package for HTML / PHP / CSS / JS template files

npm install templatejs
16 downloads in the last month

template.js

This node.js package is supposed to ease the process of building websites based on templates.

This documentation is incomplete. Please take a look at the examples .

Installation

npm install templatejs

Usage

Files & Syntax

template.js uses two kinds of files.

  • Template files contain the file structure. Beneath static content they can reference other files and declare dynamic fields.
  • Input files contain dynamic content. There may be multiple input files for a single output file.

Syntax

There are three different types of codes. Each has multiple possible syntaxes.

  1. Include other files:
    {{ include FILE }}
    {{ # FILE }}
  2. Include dynamic content:
    {{ declare NAME }}
    {{ + NAME }}
  3. Define dynamic content:
    {{ NAME }}...{{ end NAME }}
    {{ NAME }}...{{ $ NAME }}
    {{ NAME: ... }}

It is possible (and often useful) to wrap these codes in comments. For this purpose template.js determines the programming language the template file is written in. It is also possible to set the language via the --language (-l) parameter which takes 'html', 'javascript' or 'plain' where plain means no comment wrapping. The codes above use the 'plain' syntax.

Syntax examples:

Plain HTML JavaScript
{{ declare title }}
<!-- {{ declare title }} -->
/* {{ declare title }} */
{{ title: Hello world }}
<!-- {{ title: Hello world }} -->
/* {{ title: Hello world }} */
{{ include head }}
<!-- {{ include head.html }} -->
/* {{ include head.js }} */

Command line interface

Try templatejs --help for information

Operation modes

template.js provides two modes of file generation:

  1. Default mode: This mode outputs the template resolving dynamic content. The output file is a valid input file producing the same output as the original input file did.
  2. Production mode: This mode outputs the template without any template.js control codes. The output is not a valid input file but contains only static content. Content insertion and file inclusion will be performed.

To enable the production mode add the -p / --production parameter.

Changelog

0.1.0

  • Completely rewritten
  • New and powerful syntax
  • Now provides a simple API

0.0.3

  • Increased allowed length of field names.

0.0.2

  • Added 'output' option
  • Fixed UTF8 encoding

0.0.1

  • First release
npm loves you