HTML-Markup
HTML Template engine.
Installation
npm install html-markup
In case you want to build a server using express as your router.
npm init
npm install express
npm install html-markup
Features
- Complies with the Express view system
- Mark command tag using
#{ code /}
Commands
The markup language is composed of tag of this form:
#{command first_Arg, second_Arg, ... /}
The available commands are:
- set: Assign the value of the expression(2) to the variable name(1).
- get: Replace this tag by the value of the expression(1).
- get_if: If the condition(1) is true, replace this tag by the value of the expression(2) else by the second expression(3).
- include: Insert the content of the file indicate by the value of the expression(1).
- doLayout_: Insert the content of the child template.
- extends_: Define the parent of this template (see extends).
#{set title,'MyPage' /}#{set menu,'home' /}#{extends '/model.html' /}...#{include '/menu-' + menu + '.html' /}Bienvenue sur #{get title/}
Usage
You can use this script of three different ways. On command line: > node markup.js [html_file]
On your script:
var markup = markup;
Using Express:
var markup = var express = ;var app = ; app;app; // specify the views directoryapp; // register the template engine // What's on /dist folder is freely accessibleapp;// For the rest, we use the engineapp app;
Options
cache
If true, will keep static page into memory.params
Array of values accessible viaparams.name
query
Array of values accessible viaparams.query
debug
Output debug informationopen
Open tag, defaulting to "#{close
Closing tag, defaulting to "/}"directory
Change of directory (default is./views
)
Extends
A real advantage about this template is to insert content of other pages. You have two way of doing this, the extends and include commands.
The extends allow to define a parent. This is always the last executed command on the page.
Example
./views/model.html
#{get title/} ... ... #{include '/menu.html' /} #{doLayout /} ...
./views/index.html
#{set title 'MyPage' /}#{set menu, 'home' /}#{extends '/models.html' /}Welcome #{get_if query.user!=null, query.user, 'new visitor'}!This is my page
./views/menu.html
Home Portfolio About
RENDER (indentation corrected) /index.html?user=Fab
MyPage ... ... Home Portfolio About Welcome Fab! This is my page ...
License
This code is under the modified BSD license.