bm-email-templatizer
v1.8.0
Published
create email templates through jade/pug, sass, and locale json files
Downloads
30
Maintainers
Readme
#bmEmailTemplatizer An email template engine that truely works.
- compile multiple emails templates with multiple locales.
- fully customizable pipeline.
- i18n and customizable locals
- consolidate.js for view engine.
##Usage ###Minimal
var bmEmailTemplatizer = require('bm-email-templatizer');
bmEmailTemplatizer
.allLocalesAllFiles()
.then(function(results) {
console.log('results', results);
})
.catch(function(err) {
console.log('error', err);
});
##API ###setOptions parameters: options object returns: bmEmailTemplatizer
###allLocalesAllFiles parameters: none. returns: Promise. resolves: pipeline resolves.
#Options
| Option | Type | Description | | ------------------- | :------: | -------------------------------------------: | | pipeline | Array | list of functions to be run by templatizer. | | paths | Object | See Paths section. | | consolidate | Object | See Consolidate section. | | i18nConfigurations | Object | See i18n configurations section. |
var defaulOptions = {
pipeline: ['compilePug', 'compileSass', 'juiceStyles', 'writeHtml'],
paths: {
base: process.cwd(),
scss: 'scss/index.scss',
locales: 'locales/',
views: 'views/**/*.pug',
compiled: 'compiled'
},
consolidate: {
viewEngine: 'pug',
locals: {},
options: {}
}
}
Consolidate
consolidate.js is used to support a HUGE list of view engines!
Supported template engines by consolidate:
- atpl
- doT.js (website)
- dust (unmaintained) (website)
- dustjs-linkedin (maintained fork of dust) (website)
- eco
- ect (website)
- ejs
- haml
- haml-coffee
- hamlet
- handlebars (website)
- hogan (website)
- htmling
- jade (website)
- jazz
- jqtpl
- JUST
- liquor
- lodash (website)
- mote (website)
- mustache
- nunjucks (website)
- pug (formerly jade) (website)
- QEJS
- ractive
- react
- slm
- swig (website)
- templayed
- twig
- liquid (website)
- toffee
- underscore (website)
- vash
- walrus (website)
- whiskers
consolidate.locals
Default: {}
view engine locals, can be used to add custom functions to be used while rendering the view. example(rendering handlebar templates through jade):
consolidate: {
locals: {
_raw: function(variableName) {
return String.raw`${variableName}`;
}
}
}
//- jade view
html
body
div
| #{ _raw("{{#if user_name}}") }
div=__('welcome-message')
| #{ _raw("{{/if}}") }
node-i18n is automatically embedded to the view engine.
consolidate.viewEngine
Default: pug
view engine, check
consolidate.options
Default: {}
options sent to view engine
Paths
###paths.base
Default: process.cwd()
base path of project. By default it is the current working directory, the directory path node is called from.
###paths.scss
Default: scss/index.scss
Entrance point for scss file. Currently accepts only one entrance point.
###paths.views
Default: views/**/*.pug
path.views
accept a glob pattern (relative or absolute).
###paths.locales
Default: locales/
path.locales
accept a directory path (relative or absolute).
locales Locale file name will be supplied as a directory name to the writeHTML pipeline command
###paths.compiled
Default: compiled
Accepts a string for a folder name relative to the base path.
Used by writeHtml
in the pipeline to write the compiled files into directory.
`{base}/{compiled}/{locale}/{fileName}.html
| Future: accepts an object, with absolute boolean, ext name, and folder path.
##Scss To get the active locale in the scss files, use getActiveLocale();
example:
// index.scss
$language: getActiveLocale();
$direction: if($language == 'ar', rtl, ltr);
html {
direction: $direction;
}
@if $language == 'du' {
.test-class {
color: blue;
}
}
##i18n config config options passed to node-i18n, check here
if i18nConfig.locales
is not passed, they are predicted based on json files in the paths.locales
directory.
i18nConfig.directory
and i18nConfig.register
properties are ignored.