grunt-static-hbs

0.2.0 • Public • Published

Static HBS

NPM version

A simple plugin for Grunt which compiles handlebars templates into static html files. It works by using hbs to compile and render the templates, allowing us to seamlessly transition from using express to using Grunt. By using hbs, we get the advantage of having both the power of handlebars and the power of hbs specific extensions. Because hbs is an express library, this plugin simulates an express rendering call on each of the files in order to compile the templates.

Installation

This plugin requires Grunt which uses Node.js. If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with this process you may install this plugin using the following command:

$ npm install grunt-static-hbs

Once the plugin has been installed, it may be enabled inside your Gruntfile using the following:

grunt.loadNpmTasks ("grunt-static-hbs");

Quick Start

"hbs":
{
    target1:
    {
        options:
        {
            layout: "path/to/layout.html",
 
            helpers:
            {
                "helper1": "path/to/helper.js",
                "helper2": function (...) { }
            },
 
            partials:
            {
                "partial1": "path/to/partial.html",
                "partial2": "some inline partial"
            }
        },
 
        files:
        {
            "result1.html": "path/to/source.html",
 
            "result2.html":
            {
                 source: "path/to/source.html",
                 layout: "path/to/layout.html",
                context: "path/to/context.json"
            },
 
            "result3.html":
            {
                 source: "path/to/source.html",
                context: { some: "context" }
            }
        }
    },
 
    target2:
    {
        ...
    }
}

Documentation

Options

  • layout A path to your layout file.
  • helpers An object containing helpers specified as a path to a module exposing a function or a function.
  • partials An object containing partials specified as a path to a partial or a string representing a partial.

Files

"path/to/result.html": "path/to/source.html"
  • source A path to your input file. Attempts to use "path/to/source.json" as a context.
"path/to/result.html": { additional options }
  • source A path to your input file.
  • layout A path to your layout file, overriding layout specified in options.
  • context A context, either as a path to a json file or an inline object.

Author

Package Sidebar

Install

npm i grunt-static-hbs

Weekly Downloads

2

Version

0.2.0

License

Zlib

Last publish

Collaborators

  • dkrutsko