bm-email-templatizer
Advanced tools
Comparing version 1.6.7 to 1.7.8
@@ -7,6 +7,12 @@ var bmEmailTemplatizer = require('../lib'), | ||
paths: { | ||
base : path.join(process.cwd(), 'example') | ||
base: path.join(process.cwd(), 'example') | ||
}, | ||
consolidate: { | ||
locals: { | ||
_raw: function(variableName) { | ||
return String.raw`${variableName}`; | ||
} | ||
} | ||
} | ||
}; | ||
console.log('base path: ', path.join(process.cwd(), 'example')) | ||
@@ -13,0 +19,0 @@ bmEmailTemplatizer. |
{ | ||
"item": "6es6", | ||
"firstName": "bamieh" | ||
"full-name": "احمد باميه" | ||
} |
{ | ||
"item": "test", | ||
"firstName": "ahmadbamieh" | ||
"full-name": "Ahmad Bamieh" | ||
} |
var pug = require('pug'), | ||
fileUtls = require('./file-utls'), | ||
path = require('path'); | ||
@@ -9,16 +8,13 @@ | ||
return new Promise(function (resolve, reject) { | ||
var options = {}; | ||
var activeFile = settings.activeFile; | ||
if(!activeFile) return reject(new Error('activeFile undefined')) | ||
// var fullPath = path.join(settings.paths.base, activeFile); | ||
settings.consolidate.locals.setLocale(settings.activeLocale); | ||
var fn = pug.compileFile(activeFile, settings.consolidate.options); | ||
fileUtls.readActiveLocale(settings).then(function(localeObj) { | ||
if(!activeFile) return reject(new Error('activeFile undefined')) | ||
var fn = pug.compileFile(activeFile, options); | ||
var html = fn( localeObj ); | ||
resolve({ | ||
"html": html | ||
}); | ||
}) | ||
.catch(function(err) {reject(err)}); | ||
resolve({ | ||
"html": fn( settings.consolidate.locals ) | ||
}); | ||
}); | ||
@@ -25,0 +21,0 @@ } |
@@ -6,6 +6,14 @@ var sass = require('node-sass'), | ||
module.exports = function compileSass() { | ||
var fullPath = path.join(this.paths.base, this.paths.scss); | ||
var settings = this; | ||
var fullPath = path.join(settings.paths.base, settings.paths.scss); | ||
var sassOptions = { | ||
file: fullPath, | ||
outputStyle: 'compressed' | ||
outputStyle: 'compressed', | ||
functions: { | ||
'getActiveLocale()': function() { | ||
var activeLocale = new sass.types.String(settings.activeLocale) | ||
return activeLocale; | ||
} | ||
} | ||
}; | ||
@@ -12,0 +20,0 @@ |
@@ -6,24 +6,4 @@ var path = require('path'), | ||
module.exports = { | ||
readActiveLocale: function readActiveLocale(settings) { | ||
settings = settings || this; | ||
var activeLocale = settings.activeLocale, | ||
paths = settings.paths; | ||
// fullPath = path.join( paths.base, activeLocale ); | ||
return new Promise(function(resolve, reject) { | ||
if(!activeLocale) return reject( new Error('activeLocale undefined') ); | ||
fs.readFile(activeLocale, 'utf8', function(err, file) { | ||
if(err) return reject(err); | ||
var parsedObj = JSON.parse( file ); | ||
parsedObj.__ = function(variableName) { return '#{'+ variableName + '}'; }; | ||
parsedObj._r = function(variableName) { | ||
return String.raw`${variableName}`; | ||
}; | ||
return resolve(parsedObj); | ||
}) | ||
}); | ||
}, | ||
glob: function glob(pathKey, settings) { | ||
@@ -30,0 +10,0 @@ var paths = settings? settings.paths : this.paths; |
var extend = require('./extend-mixin'), | ||
fileUtls = require('./file-utls'); | ||
fileUtls = require('./file-utls'), | ||
i18nSetup = require('./i18n-setup'); | ||
@@ -16,6 +17,12 @@ var pipelineFn = { | ||
scss: 'scss/index.scss', | ||
locales: 'locales/*.json', | ||
locales: 'locales/', | ||
views: 'views/**/*.pug', | ||
compiled: 'compiled/' | ||
} | ||
}, | ||
consolidate: { | ||
viewEngine: 'pug', | ||
locals: {}, | ||
options: {} | ||
}, | ||
locales: [] | ||
} | ||
@@ -44,15 +51,21 @@ | ||
function setup() { | ||
} | ||
function allLocalesOneFile(filename) { | ||
return fileUtls.glob('locales', settings) | ||
.then(function(localesArray) { | ||
return localesArray.reduce(function (acc, locale) { | ||
return acc.then(function (res) { | ||
return oneLocaleOneFile(filename, locale) | ||
.then(function (result) { | ||
res.push(result); | ||
return res; | ||
}) | ||
}) | ||
}, Promise.resolve([])) | ||
}) | ||
i18nSetup.i18nSetup(settings); | ||
console.log('settings.locales', settings.locales) | ||
return settings.locales.reduce(function (acc, locale) { | ||
return acc.then(function (res) { | ||
return oneLocaleOneFile(filename, locale) | ||
.then(function (result) { | ||
res.push(result); | ||
return res; | ||
}) | ||
}) | ||
}, Promise.resolve([])) | ||
.catch( function(err) { | ||
@@ -63,2 +76,3 @@ Promise.reject( new Error('Error in pipeline method', {activeJob:activeJob, 'details': err}) ); | ||
function allLocalesAllFiles() { | ||
@@ -65,0 +79,0 @@ return fileUtls.glob('views', settings) |
{ | ||
"name": "bm-email-templatizer", | ||
"version": "1.6.7", | ||
"version": "1.7.8", | ||
"description": "create email templates through jade/pug, sass, and locale json files", | ||
@@ -22,2 +22,5 @@ "main": "lib/index.js", | ||
"sass", | ||
"i18n", | ||
"view engine", | ||
"consolidate.js", | ||
"i18n" | ||
@@ -33,6 +36,7 @@ ], | ||
"dependencies": { | ||
"glob": "^7.0.5", | ||
"i18n": "^0.8.3", | ||
"juice": "^1.10.0", | ||
"mkdirp": "^0.5.1", | ||
"node-sass": "^3.7.0", | ||
"glob": "^7.0.5", | ||
"pug": "^2.0.0-alpha6" | ||
@@ -39,0 +43,0 @@ }, |
157
README.md
#bmEmailTemplatizer | ||
Fully working email templatizer. | ||
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 | ||
##API | ||
###setOptions | ||
parameters: options object | ||
returns: bmEmailTemplatizer | ||
<!-- | ||
###oneLocaleOneFile | ||
parameters: | ||
returns: Promise | ||
resolves: | ||
###allLocalesOneFile | ||
parameters: | ||
returns: Promise | ||
resolves: | ||
--> | ||
###allLocalesAllFiles | ||
parameters: none. | ||
returns: Promise. | ||
resolves: pipeline resolves. | ||
###Minimal | ||
@@ -24,6 +49,8 @@ ```javascript | ||
| Option | Type | Description | | ||
| -------- | :------: | -----------------------------------------: | | ||
| pipeline | Array | list of functions to be run by templatizer | | ||
| paths | Object | See Paths section for more info. | | ||
| Option | Type | Description | | ||
| ------------ | :------: | -----------------------------------------: | | ||
| pipeline | Array | list of functions to be run by templatizer | | ||
| paths | Object | See Paths section. | | ||
| locales | Array | array of locales | | ||
| consolidate | Object | See Consolidate section. | | ||
@@ -36,5 +63,10 @@ ```javascript | ||
scss: 'scss/index.scss', | ||
locales: 'locales/**/*.json', | ||
locales: 'locales/', | ||
views: 'views/**/*.pug', | ||
compiled: 'compiled' | ||
}, | ||
consolidate: { | ||
viewEngine: 'pug', | ||
locals: {}, | ||
options: {} | ||
} | ||
@@ -44,4 +76,80 @@ } | ||
## Consolidate | ||
[consolidate.js](https://github.com/tj/consolidate.js) is used to support a HUGE list of view engines! | ||
### Supported template engines by consolidate: | ||
- [atpl](https://github.com/soywiz/atpl.js) | ||
- [doT.js](https://github.com/olado/doT) [(website)](http://olado.github.io/doT/) | ||
- [dust (unmaintained)](https://github.com/akdubya/dustjs) [(website)](http://akdubya.github.com/dustjs/) | ||
- [dustjs-linkedin (maintained fork of dust)](https://github.com/linkedin/dustjs) [(website)](http://linkedin.github.io/dustjs/) | ||
- [eco](https://github.com/sstephenson/eco) | ||
- [ect](https://github.com/baryshev/ect) [(website)](http://ectjs.com/) | ||
- [ejs](https://github.com/visionmedia/ejs) | ||
- [haml](https://github.com/visionmedia/haml.js) | ||
- [haml-coffee](https://github.com/9elements/haml-coffee) | ||
- [hamlet](https://github.com/gregwebs/hamlet.js) | ||
- [handlebars](https://github.com/wycats/handlebars.js/) [(website)](http://handlebarsjs.com/) | ||
- [hogan](https://github.com/twitter/hogan.js) [(website)](http://twitter.github.com/hogan.js/) | ||
- [htmling](https://github.com/codemix/htmling) | ||
- [jade](https://github.com/visionmedia/jade) [(website)](http://jade-lang.com/) | ||
- [jazz](https://github.com/shinetech/jazz) | ||
- [jqtpl](https://github.com/kof/jqtpl) | ||
- [JUST](https://github.com/baryshev/just) | ||
- [liquor](https://github.com/chjj/liquor) | ||
- [lodash](https://github.com/bestiejs/lodash) [(website)](http://lodash.com/) | ||
- [mote](https://github.com/satchmorun/mote) [(website)](http://satchmorun.github.io/mote/) | ||
- [mustache](https://github.com/janl/mustache.js) | ||
- [nunjucks](https://github.com/mozilla/nunjucks) [(website)](https://mozilla.github.io/nunjucks) | ||
- [pug (formerly jade)](https://github.com/pugjs/pug) [(website)](http://jade-lang.com/) | ||
- [QEJS](https://github.com/jepso/QEJS) | ||
- [ractive](https://github.com/Rich-Harris/Ractive) | ||
- [react](https://github.com/facebook/react) | ||
- [slm](https://github.com/slm-lang/slm) | ||
- [swig](https://github.com/paularmstrong/swig) [(website)](http://paularmstrong.github.com/swig/) | ||
- [templayed](http://archan937.github.com/templayed.js/) | ||
- [twig](https://github.com/justjohn/twig.js) | ||
- [liquid](https://github.com/leizongmin/tinyliquid) [(website)](http://liquidmarkup.org/) | ||
- [toffee](https://github.com/malgorithms/toffee) | ||
- [underscore](https://github.com/documentcloud/underscore) [(website)](http://underscorejs.org/#template) | ||
- [vash](https://github.com/kirbysayshi/vash) | ||
- [walrus](https://github.com/jeremyruppel/walrus) [(website)](http://documentup.com/jeremyruppel/walrus/) | ||
- [whiskers](https://github.com/gsf/whiskers.js) | ||
### 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): | ||
```javascript | ||
consolidate: { | ||
locals: { | ||
_raw: function(variableName) { | ||
return String.raw`${variableName}`; | ||
} | ||
} | ||
} | ||
``` | ||
```jade | ||
//- jade view | ||
html | ||
body | ||
div | ||
| #{ _raw("{{#if user_name}}") } | ||
div=__('welcome-message') | ||
| #{ _raw("{{/if}}") } | ||
``` | ||
[node-i18n](https://github.com/mashpie/i18n-node) is automatically embedded to the view engine. | ||
### consolidate.viewEngine | ||
Default: `pug` | ||
view engine, check | ||
### consolidate.options | ||
Default: `{}` | ||
options sent to view engine | ||
## Paths | ||
###base | ||
###paths.base | ||
Default: `process.cwd()` | ||
@@ -52,3 +160,3 @@ | ||
###scss | ||
###paths.scss | ||
Default: `scss/index.scss` | ||
@@ -58,14 +166,16 @@ | ||
###views | ||
###paths.views | ||
Default: `views/**/*.pug` | ||
views glob pattern relative to root. | ||
`path.views` accept a glob pattern (relative or absolute). | ||
###locales | ||
Default: `locales/**/*.json` | ||
###paths.locales | ||
Default: `locales/` | ||
locales glob pattern relative to root. | ||
`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* | ||
###compiled | ||
###paths.compiled | ||
Default: `compiled` | ||
@@ -79,3 +189,22 @@ | ||
##Scss | ||
To get the active locale in the scss files, use getActiveLocale(); | ||
example: | ||
```sass | ||
// index.scss | ||
$language: getActiveLocale(); | ||
$direction: if($language == 'ar', rtl, ltr); | ||
html { | ||
direction: $direction; | ||
} | ||
@if $language == 'du' { | ||
.test-class { | ||
color: blue; | ||
} | ||
} | ||
``` | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26028
33
471
205
6
+ Addedi18n@^0.8.3
+ Addeddebug@4.3.4(transitive)
+ Addedi18n@0.8.6(transitive)
+ Addedmake-plural@4.3.06.2.2(transitive)
+ Addedmath-interval-parser@2.0.1(transitive)
+ Addedmessageformat@2.3.0(transitive)
+ Addedmessageformat-formatters@2.0.1(transitive)
+ Addedmessageformat-parser@4.1.3(transitive)
+ Addedms@2.1.2(transitive)
+ Addedmustache@4.2.0(transitive)
+ Addedsprintf-js@1.1.3(transitive)