Skip to content
This repository was archived by the owner on Jan 25, 2020. It is now read-only.

Commit bbcd258

Browse files
author
Poornima Venkat
committed
Merge pull request #30 from krakenjs/next
Changes to become v1.x
2 parents 7394cf8 + 0a7d7c2 commit bbcd258

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+547
-985
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
node_modules/
33
coverage/
44
npm-debug.log
5+
*.swp
6+
test/fixtures/tmp/
7+
.nyc_output/
8+
tags

README.md

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,93 @@
1-
engine-munger
1+
engine-munger
22
=============
33

4-
Lead Maintainer: [Aria Stewart](https://github.com/aredridel)
4+
A replacement Express view class that provides asynchronous resolution, allows
5+
engines to use the lookup method to locate partials, and extends the lookup
6+
method to be configurable based on i18n locale and a template specialization
7+
rule map.
8+
9+
This is a backport of [work for Express 5](https://github.com/strongloop/express/pull/2653)
10+
11+
Lead Maintainer: [Aria Stewart](https://github.com/aredridel)
512

613
[![Build Status](https://travis-ci.org/krakenjs/engine-munger.svg?branch=master)](https://travis-ci.org/krakenjs/engine-munger)
714

8-
A template engine munging library.
9-
It looks for appropriate template consolidation library for specified view engine and includes i18n and specialization in the workflow.
15+
What does i18n mean?
16+
--------------------
17+
18+
i18n means "internationalization". Given a `locale` property in the render options, `engine-munger` will look for content in a locale-specific directory (or in a fallback locale if that is not a match) for templates and partials. This is particularly useful with template engines that pre-localize their compiled forms, such as with [`localizr`](https://github.com/krakenjs/localizr) and [`dustjs-linkedin`](http://dustjs.com/) together.
1019

11-
Note: If you use specialization features, you must use dustjs before 2.6.0.
20+
What does specialization mean?
21+
------------------------------
1222

13-
###### What does i18n mean ?
14-
Localization of included content tags for a specified locale. Currently supported only for dust templating engine and internally uses the module [localizr](https://github.com/krakenjs/localizr) for translating content tags included in the templates
23+
Ability to switch a specific template with another based on a rule set specified in the app config. The actual rule parsing is done using the module [`karka`](https://github.com/krakenjs/karka).
1524

16-
###### What does specialization mean ?
17-
Ability to switch a specific template with another based on a rule set specified in the app config. The actual rule parsing is done using the module [karka](https://github.com/krakenjs/karka) and can be extended and used in any templating engine and not dust.
1825
All engine-munger does is includes a specialization map with the list of key value pairs using the karka module.
26+
1927
```javascript
2028
{
21-
_specialization : {
22-
...
23-
originalTemplate : <mappedTemplate>
24-
...
29+
specialization : {
30+
'jekyll': [
31+
{
32+
is: 'hyde',
33+
when: {
34+
'whoAmI': 'badGuy'
35+
}
36+
}
37+
]
2538
}
2639
}
2740
```
2841

29-
##### Currently supported template engines out of the box:
30-
31-
* Dust: Engine types 'js' and 'dust'
42+
The above will switch the template from `jekyll` to `hyde` if the render options contain `"whoAmI": "badGuy"`. Rules can be as complex as you need for your application and are particularly good for running A/B tests.
3243

44+
Using engine-munger in an application
45+
=====================================
3346

34-
Simple Usage:
47+
This example uses the [`adaro`](https://github.com/krakenjs/adaro) template engine, which wraps dust up as an express view engine, and uses engine-munger's more sophisticated lookup method to find partials, allowing them to be localized and specialized based on the render options.
3548

3649
```javascript
37-
var engine-munger = require('engine-munger'),
38-
app = require('express')();
50+
var munger = require('engine-munger');
51+
var adaro = require('adaro');
52+
var app = require('express')();
53+
54+
var specialization = {
55+
'jekyll': [
56+
{
57+
is: 'hyde',
58+
when: {
59+
'whoAmI': 'badGuy'
60+
}
61+
}
62+
]
63+
};
64+
app.set("view", munger.makeViewClass({
65+
"dust": {
66+
specialization: specialization
67+
},
68+
"js": {
69+
specialization: specialization,
70+
i18n: {
71+
fallback: 'en-US',
72+
contentPath: 'locales'
73+
}
74+
}
75+
});
3976

40-
app.engine('dust', engine-munger['dust'](settings, config));
41-
app.engine('js', engine-munger['js'](settings, config));
42-
```
77+
var engineConfig = {}; // Configuration for your view engine
4378

44-
* settings : [JSON] Arguments you want passed to the templating engine,
45-
* config: [JSON] used to specify whether you need i18n/specialization enabled. It also compulsarily requires the 'view' and 'view engine' settings passed into express app.
46-
47-
If you are using kraken-js 1.0 along with engine-munger, the kraken generator will automatically set this all up for you.
48-
But if you want to use this with a stand alone express app with dust as templating engine, you can specify as follows:
49-
50-
Example params:
51-
52-
```javascript
53-
var settings = {cache: false},
54-
config = {
55-
'views': 'public/templates',
56-
'view engine': 'dust',
57-
'i18n': {
58-
'fallback': 'en-US',
59-
'contentPath': 'locales'
60-
},
61-
specialization: {
62-
'jekyll': [
63-
{
64-
is: 'hyde',
65-
when: {
66-
'whoAmI': 'badGuy'
67-
}
68-
}
69-
]
70-
71-
}
72-
};
73-
```
79+
app.engine('dust', adaro.dust(engineConfig));
80+
app.engine('js', adaro.js(engineConfig));
81+
```
7482
7583
Running Tests:
7684
85+
```shell
86+
npm test
7787
```
78-
To run tests:
79-
$ npm test
8088
81-
To run coverage
82-
$ npm run-script cover
89+
To run coverage:
8390
84-
To run lint
85-
$ npm run-script lint
91+
```shell
92+
npm run cover
8693
```
87-
88-

0 commit comments

Comments
 (0)