@dadi/web-pugjs

    1.1.1 • Public • Published
    DADI Web

    Pug.js engine interface

    npm (scoped) coverage Build Status JavaScript Style Guide semantic-release

    This module allows Pug.js templates to be used with DADI Web.

    Installation

    • Add this module as a dependency:

      npm install @dadi/web-pugjs --save
      
    • Include it in the engines array passed to Web:

      require('@dadi/web')({
        engines: [
          require('@dadi/web-pugjs')
        ]
      })

    Usage

    Include paths

    Partials can be included using the include keyword and paths to the included files can be absolute or relative (see Pug's documentation).

    The base directory for absolute paths is the pages/ directory. Take the following directory tree.

    pages/
    |_ partials/
    |_ |_ common/
    |_ |_ |_ header.pug
    |_ |_ contact-info.pug
    |_ home.pug
    

    To include header.pug from contact-info.pug, you can do:

    //- Absolute path
    include /partials/common/header.pug
     
    //- Relative path
    include common/header.pug

    Helper functions

    Add a DADI Web configuration setting for helpers, pointing to a directory containing helper files. Each .js helper file will be added as a property to template locals for use within templates.

    Configuration

      engines: {
        pug: {
          paths: {
            helpers: 'test/workspace/helpers'
          }
        }
      }
    

    Directory structure

    helpers/
    |_ trim.js
    pages/
    |_ partials/
    |_ |_ common/
    |_ |_ |_ header.pug
    |_ |_ contact-info.pug
    |_ home.pug
    

    Locals

    The function is added to the template locals, along with data objects:

    {
      products: [
        { name: 'The Old Man and the Sea' }
      ],
      trim: [Function]
    }
    

    Usage

    Use the function in templates like so:

    h1= trim(product.name)
    

    Install

    npm i @dadi/web-pugjs

    DownloadsWeekly Downloads

    0

    Version

    1.1.1

    License

    none

    Last publish

    Collaborators

    • jeanluc.thiebaut
    • josephdenne
    • jimlambie
    • arthurmingard
    • eduardoboucas
    • abovedave
    • adamkdean