Giter Club home page Giter Club logo

ukhomeoffice.govuk-template-compiler's Introduction

hmpo-govuk-template

Compiles govuk mustache template into a more usable format and provide middleware for use in apps.

Existing govuk mustache template has simple mustache placeholders for content sections, which necessitates a two step compile process where sections are compiled individually and then again into the parent template.

Compiling the template to replace these placeholders with variables allows for templates to implement the govuk template as a parent partial.

Example

{{< govuk-template}}

    {{$main}}
        <h1>Page Content</h1>
    {{/main}}

{{/ govuk-template}}

Installation

npm install [--save] hmpo-govuk-template

Usage

The compilation of the template is performed automatically as an npm postinstall hook.

When used as part of an express app, a setup method is provided which will add a static-middleware (using serve-static) to serve the template assets without needing to copy them to any other location.

It will also add the template as a mustache partial with a name of "govuk-template".

To configure express middleware

require('hmpo-govuk-template').setup(app[, { ... options ...}]);

To only load the partial location but not serve the assets use the template function. The govukAssetPath local will need to set to the absolute public asset location.

app.use(function (req, res, next) {
    res.locals = res.locals || {};
    res.locals.govukAssetPath = '/absolute/asset/path'
});
app.use(require('hmpo-govuk-template').template);

To use the mustache partial

{{< govuk-template}}
    {{$pageTitle}}An example page{{/pageTitle}}
    {{$main}}
        <h1>Page Content</h1>
    {{/main}}
{{/ govuk-template}}

Options

A number of options can be passed with the app into the setup method:

  • path - Sets the base path for the location of static assets - Default: /govuk-assets

Other options are passed onto the serve-static configuration, and more details can be found in the serve-static documentation

Example

There is an example implmentation in '/example'. To run:

cd example
npm install
npm start

ukhomeoffice.govuk-template-compiler's People

Contributors

sebinsua avatar gavboulton avatar lennym avatar oliverweighell 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.