# Staples
Staples is a minimal library that provides the power to allow you to create simple semantic templates and customize them with the addition of custom helpers. Staples is widely compatible with the basic Mustache and Handlebars models.
## Installation
```bash
npm i @dslak/staples
```
or, using YARN
```bash
yarn add @dslak/staples
```
## Usage
Once installed, the library must be included as well
```javascript
const staples = require('@dslak/staples')
staples.printVersion()
```
Example of use with a basic template and a test input
```javascript
const staples = require('@dslak/staples');
const input = {
"sections": [
{
"name": "section1",
"elements": {
"val1": "value 1",
"val2": "value 2",
"val_html": "HTML"
}
},
{
"name": "section2",
"elements": {
"if": true,
"unless": false
}
}
]
};
const template = `{{sections.0.elements.val1}}
{{sections.0.elements.val2}}
{{sections.0.elements.val_html}}
{{sections.0.elements.val2}}
{{#if sections.1.elements.if}}
{{sections.0.elements.val1}}
{{/if}}
{{#unless sections.1.elements.unless}}
{{sections.0.elements.val2}}
{{/unless}}`;
const compiled = staples.compile(template, input);
```
## Custom helpers
Creating custom helpers
```javascript
staples.addHelper('ellipsis', (string, words = 10) => {
return `${string.split(' ').slice(0, words).join(' ')}...`
})
```
Usage:
```javascript
const staples = require('@dslak/staples');
staples.addHelper('ellipsis', (string, words = 10) => {
return `${string.split(' ').slice(0, words).join(' ')}...`
});
const input = {
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
};
const template = `{{ellipsis value 5}}`;
const compiled = staples.compile(template, input);
```