npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

customize-engine-handlebars

v4.0.4

Published

Use handlebars as engine for customize

Downloads

16,200

Readme

customize-engine-handlebars

NPM version Greenkeeper badge

Use handlebars as engine for customize

Installation

npm install customize-engine-handlebars

Usage

The following examples demonstrate how to use this module.

Configuration

The following usage example has a configuration for all possible properties of the Handlebars-engine:

const customize = require('customize')
customize()
  .registerEngine('handlebars', require('customize-engine-handlebars'))
  .load(require('./config-module.js'))
  .run()
  .then(console.log)

This example loads its configuration from the module config-module.js:

module.exports = function(customize) {
  return customize.merge({
    handlebars: {
      // Directory containing templates
      templates: 'templates',
      // Directory containing partials
      partials: 'partials',
      // JS-file exporting Handlebars helper-functions
      helpers: 'hb-helpers.js',
      // JS-file exporting a preprocessor function
      preprocessor: 'hb-preprocessor.js',
      // Input data for Handlebars
      data: {
        name: 'nknapp',
        city: 'Darmstadt'
      }
    }
  })
}

A quick note: If your are creating a real configuration-module, you should always use require.resolve or __dirname to determine the correct path to referenced files.

All the templates in the templates directory are called with the provided data (name and city). Each one generates an entry in the result of the engine. The templates call a partial that is inserted below the main content. Helper functions from the hb-helpers.js-file are registered with Handlebars and text2.txt.hbs uses the shout-helper from hb-helpers.js to turn a string into upper-case.

I'm {{name}}

I'm living in {{shout city}}.

{{>footer}}

The example also includes a preprocessor (hb-preprocessor.js) that calls the github API to retrieve information about the user.

const got = require('got')

module.exports = async function(data) {
  return {
    name: data.name,
    city: data.city,
    github: got('https://api.github.com/users/nknapp').json()
  }
}

The result is injected into the data as github property and rendered by the footer.hbs partial.

------
Github-Name: {{{github.name}}}

The output of this example is:

{
  "handlebars": {
    "subdir/text3.txt": "------\nBlog: https://blog.knappi.org\n",
    "text1.txt": "I'm nknapp\n\nI'm living in Darmstadt.\n\n------\nBlog: https://blog.knappi.org\n",
    "text2.txt": "I'm nknapp\n\nI'm living in DARMSTADT.\n\n------\nBlog: https://blog.knappi.org\n"
  }
}

More examples

see docs/examples.md for more examples

API-documentation

This package will always support the latest version of NodeJS and as well as the current LTS version. In the future, it will not be considered a breaking change to drop support of a pre-LTS version of NodeJS.

see docs/api.md

License

customize-engine-handlebars is published under the MIT-license.

See LICENSE.md for details.

Release-Notes

For release notes, see CHANGELOG.md

Contributing guidelines

See CONTRIBUTING.md.