This repository was archived by the owner on Jan 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Changes to become v1.x #30
Merged
Merged
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c50c6f9
Directly depend on adaro, and let it bring in dustjs
aredridel 62624e3
Update built fixtures to use dust 2.7 format
aredridel 68aae66
Pass specialization via requestOptions
aredridel 0b18d7d
Fix specialization test and test both paths
aredridel 400efff
Simplify and make unconditional the onLoad wrappers
aredridel 1b92a95
Syntactic cleanups
aredridel 0f440b1
Use dustjs.loadSource and return template instead of source
aredridel efa64d0
Rework test suite
aredridel 71e879a
Check all i18n and specialization combinations in spclAndIntl-js test
aredridel e30dfea
Add option `enableMetadata` to allow hooking by in-place content edit…
aredridel 6a8d836
Appease the linter
aredridel a35d02b
Improve package.json metadata
aredridel 5e125f7
Rework expressView to mimic the original better and work independentl…
aredridel 312c099
Switch from tape to tap
aredridel 055be18
Add nyc for coverage tracking in tests
aredridel 8b666b5
Replace expressView with one with async lookup
aredridel 491847b
Make karka unconditional
aredridel c34d1d1
Rework to use permutron
aredridel fa385dd
Implement i18n lookups cleanly
aredridel 036e3b0
Remove dead code
aredridel c0ec0b6
Update tests to use expressView, rather than the engine directly
aredridel eb6b5cb
Make adaro a dev dependency
aredridel 11dc7f0
Update the README
aredridel 5657129
Remove dead code
aredridel 082ea49
Make error message for not found template slightly more useful
aredridel d41cfab
Stop checking for i18n on invalid parse check
aredridel 422073f
Check new, better error message
aredridel 5c5cb94
simplify lookupMain and test it
aredridel f224899
Test having multiple roots to search
aredridel a03afac
Rearrange what is exported by what
aredridel 985f297
1.0.0-2
aredridel 0d1f0a1
Improve package.json description
aredridel 528b2c1
Add myself as a contributor
aredridel 7c77448
Remove middleware, moved to makara
aredridel 206295a
Remove direct devDependency on istanbul, we have nyc for that
aredridel 7e8422c
Add reference to Express 5 change
aredridel c600fda
Expose regnerate-test-data script
aredridel 457e310
Improve .gitignore
aredridel 9c8b299
Move error handling into lookup rather than lookupMain to improve erg…
aredridel 5af265a
Bump adaro to get version that always passes the extension to lookup
aredridel 6f99310
1.0.0-3
aredridel 0a7d7c2
Remove useless freshy dependency
aredridel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,7 @@ | |
| node_modules/ | ||
| coverage/ | ||
| npm-debug.log | ||
| *.swp | ||
| test/fixtures/tmp/ | ||
| .nyc_output/ | ||
| tags | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,88 +1,93 @@ | ||
| engine-munger | ||
| engine-munger | ||
| ============= | ||
|
|
||
| Lead Maintainer: [Aria Stewart](https://github.com/aredridel) | ||
| A replacement Express view class that provides asynchronous resolution, allows | ||
| engines to use the lookup method to locate partials, and extends the lookup | ||
| method to be configurable based on i18n locale and a template specialization | ||
| rule map. | ||
|
|
||
| This is a backport of [work for Express 5](https://github.com/strongloop/express/pull/2653) | ||
|
|
||
| Lead Maintainer: [Aria Stewart](https://github.com/aredridel) | ||
|
|
||
| [](https://travis-ci.org/krakenjs/engine-munger) | ||
|
|
||
| A template engine munging library. | ||
| It looks for appropriate template consolidation library for specified view engine and includes i18n and specialization in the workflow. | ||
| What does i18n mean? | ||
| -------------------- | ||
|
|
||
| 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. | ||
|
|
||
| Note: If you use specialization features, you must use dustjs before 2.6.0. | ||
| What does specialization mean? | ||
| ------------------------------ | ||
|
|
||
| ###### What does i18n mean ? | ||
| 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 | ||
| 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). | ||
|
|
||
| ###### What does specialization mean ? | ||
| 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. | ||
| All engine-munger does is includes a specialization map with the list of key value pairs using the karka module. | ||
|
|
||
| ```javascript | ||
| { | ||
| _specialization : { | ||
| ... | ||
| originalTemplate : <mappedTemplate> | ||
| ... | ||
| specialization : { | ||
| 'jekyll': [ | ||
| { | ||
| is: 'hyde', | ||
| when: { | ||
| 'whoAmI': 'badGuy' | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ##### Currently supported template engines out of the box: | ||
|
|
||
| * Dust: Engine types 'js' and 'dust' | ||
| 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. | ||
|
|
||
| Using engine-munger in an application | ||
| ===================================== | ||
|
|
||
| Simple Usage: | ||
| 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. | ||
|
|
||
| ```javascript | ||
| var engine-munger = require('engine-munger'), | ||
| app = require('express')(); | ||
| var munger = require('engine-munger'); | ||
| var adaro = require('adaro'); | ||
| var app = require('express')(); | ||
|
|
||
| var specialization = { | ||
| 'jekyll': [ | ||
| { | ||
| is: 'hyde', | ||
| when: { | ||
| 'whoAmI': 'badGuy' | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| app.set("view", munger.makeViewClass({ | ||
| "dust": { | ||
| specialization: specialization | ||
| }, | ||
| "js": { | ||
| specialization: specialization, | ||
| i18n: { | ||
| fallback: 'en-US', | ||
| contentPath: 'locales' | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| app.engine('dust', engine-munger['dust'](settings, config)); | ||
| app.engine('js', engine-munger['js'](settings, config)); | ||
| ``` | ||
| var engineConfig = {}; // Configuration for your view engine | ||
|
|
||
| * settings : [JSON] Arguments you want passed to the templating engine, | ||
| * 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. | ||
|
|
||
| If you are using kraken-js 1.0 along with engine-munger, the kraken generator will automatically set this all up for you. | ||
| But if you want to use this with a stand alone express app with dust as templating engine, you can specify as follows: | ||
|
|
||
| Example params: | ||
|
|
||
| ```javascript | ||
| var settings = {cache: false}, | ||
| config = { | ||
| 'views': 'public/templates', | ||
| 'view engine': 'dust', | ||
| 'i18n': { | ||
| 'fallback': 'en-US', | ||
| 'contentPath': 'locales' | ||
| }, | ||
| specialization: { | ||
| 'jekyll': [ | ||
| { | ||
| is: 'hyde', | ||
| when: { | ||
| 'whoAmI': 'badGuy' | ||
| } | ||
| } | ||
| ] | ||
|
|
||
| } | ||
| }; | ||
| ``` | ||
| app.engine('dust', adaro.dust(engineConfig)); | ||
| app.engine('js', adaro.js(engineConfig)); | ||
| ``` | ||
|
|
||
| Running Tests: | ||
|
|
||
| ```shell | ||
| npm test | ||
| ``` | ||
| To run tests: | ||
| $ npm test | ||
|
|
||
| To run coverage | ||
| $ npm run-script cover | ||
| To run coverage: | ||
|
|
||
| To run lint | ||
| $ npm run-script lint | ||
| ```shell | ||
| npm run cover | ||
| ``` | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to run
npm run-script cover. Is this due to my npm version? (2.5.1)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, run has always been an alias for run-script. What happened when you did
npm run cover?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. sorry. i was simply using
npm coverand then straight tonpm run-script cover.. I didn't properly read the doc above and trynpm run. That works for me now that I've tried it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome coverage metrics btw!!