An open API service indexing awesome lists of open source software.

https://github.com/baristalabs/baristalabs-handlebarrit

Simple Azure Functions based Handlebars Microservice
https://github.com/baristalabs/baristalabs-handlebarrit

Last synced: 8 months ago
JSON representation

Simple Azure Functions based Handlebars Microservice

Awesome Lists containing this project

README

          

handlebarrit
---

Azure Functions implementation that accepts a JSON request and transforms the template/data properties into a string result via Handlebars.

Ex:

POST https://handlebarrit.azurewebsites.net/api/process/

``` JSON
{
"template": "{{message}}",
"data": {
"message": "Hello, World!"
}
}
```

Response (text/html):
```
"Hello, World!"
```

It's also possible to change the response content-type via an aptly named contentType property

``` JSON
{
"template": "{{message}}",
"data": {
"message": "Hello, World!"
},
"contentType": "text/xml"
}
```

Response (text/xml):
```

Hello, World!
```
---

In addition to the Handlebars built-in helpers, the following helpers are available:

- eachBySort: Sorts the specified data by the specified property and applies the template for each.

``` JSON
[{
"template": "



    {{#eachBySort tasks 'orderHint' 'desc'}}
  • {{title}}

  • {{/eachBySort}}

",
"data": {
"tasks": [
{
"title": "something or other",
"orderHint": 12345
},
{
"title": "the first one",
"orderHint": 1000
}
]},
"contentType": "text/html"
}]
```

- currentTime: Writes the current time in the specified time zone and date/time format. Optionally: culture.

``` JSON
{
"template": "


{{currentTime 'Eastern Standard Time' 'MM-dd-yyyy h:m tt'}}
",
"data": {}
}
```

- addHours: Same as currentTime but adds the specified number of hours

``` JSON
{
"template": "


{{addHours 'Eastern Standard Time' '12' 'MM-dd-yyyy hh:mm tt'}}
",
"data": {}
}
```

- format: For the given string, attempts to parse as (1) a date time (2) a number and formats the result

``` JSON
{
"template": "


{{format startWorkTime 'h:mm tt'}}
",
"data": { "startWorkTime": "2009/03/01T10:00:00-3:00"}
}
```

- humanize - Turn an otherwise computerized string into a more readable human-friendly one.
- dehumanize - Dehumanize a human friendly string into a computer friendly one: