Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

merkle-open/nitro-component-handlebars

Repository files navigation

Nitro Component Handlebars Helper

npm version Build Status Coverage Status Codestyle

This helper allows to render a nitro component using handlebars

Installation

npm i --save-dev @namics/nitro-component-handlebars

Usage

const componentHandlebarsHelper = require('@namics/nitro-component-handlebars');
module.exports = componentHandlebarsHelper({
    rootDirectory: '/path/to/nitro/root'
})

Template usage

Default

The following code will render components/atoms/button/button.hbs:

{{component "components/atoms/button"}}

Child elements

The following code will set the value of {{children}} to 'Click me':

{{#component "components/atoms/button"}}
    Click me
{{/component}}

Attributes

The following code will set the value of {{size}} to 'xl':

{{component "components/atoms/button" size="xl"}}

Array attributes

The following code will set the value of {{sizes}} to ['xl', 'l']:

{{component "components/atoms/button" sizes="['xl', 'l']"}}

Data files

The following code will set the template variables to the content of components/atoms/button/_data/demo.json:

{{component "components/atoms/button" data-file="demo.json"}}

Rendering foreign modules

The following code will render a component from another node_module e.g. node_modules/base-pattern/components/atoms/button/button.json

{{component "~base-pattern/components/atoms/button"}}

Contribution

You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests. This project uses the Codestyle.

License

This project is licensed under MIT.