@namics/nitro-component-handlebars
v0.0.8
Published
A handlebars helper to render a nitro component
Downloads
13
Readme
Nitro Component Handlebars Helper
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 .
License
This project is licensed under MIT.