Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anytv/anytv-templater
https://github.com/anytv/anytv-templater
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/anytv/anytv-templater
- Owner: anyTV
- Created: 2017-06-07T07:41:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-01T02:48:12.000Z (almost 6 years ago)
- Last Synced: 2024-11-12T00:42:17.654Z (about 2 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 27
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# anytv-templater
[![Build Status](https://travis-ci.org/anyTV/anytv-templater.svg?branch=master)](https://travis-ci.org/anyTV/anytv-templater)A module for building content string from templates
## Install
```sh
npm i anytv-templater@latest --save
```## Introduction
Simple example:
```js
'use strict';const templater = require('anytv-templater');
const i18n = require('anytv-i18n');// make sure i18n is loaded before passing it on templater
// it will use a default `trans` function if i18n is not passed// on server.js
templater.configure({i18n: i18n,
templates_dir: 'directory/of/templates'
});// call to build
templater.make// specify language explicitly
.language('en')// or derive using country/country code
.derive_language(row.user_country, row.channel_country).template('my_template')
.content({
/**
* the keys are the template variables, values can be string/number/object
* object value will be used to call i18n.trans
*/
email_body: { trans: 'monetization-suspended-email', data: {channel_name: row.channel_name}},
email_greetings: { trans: 'email-greetings'},
thank_you: { trans: 'thank-you'},
the_freedom_team: { trans: 'the-freedom-team'},
our_mailing_address: { trans: 'our-mailing-address'},
year: (new Date()).getFullYear()
})// will just build the whole string plus metadata
.build(function (err, html) {});
```
# Todo
- [ ] Complete test cases# Contributing
Install the tools needed:
```sh
sudo npm i grunt -g
npm i
```To compile the ES6 source code to ES5:
```sh
npm start
```# Running test
```sh
sudo npm i serve_me -g
serve_me test/locales 8081
npm test
```# License
MIT
# Author
[Freedom! Labs, any.TV Limited DBA Freedom!](https://www.freedom.tm)