Skip to content

Commit

Permalink
Merge pull request #52 from ingiulio/decoupleFromHandlebars
Browse files Browse the repository at this point in the history
remove handlebars as a dependency, let the app the inject it
  • Loading branch information
saponifi3d committed Jul 11, 2015
2 parents e9e75ac + bf8b39e commit 3108484
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ rendr-handlebars
================

[Handlebars](http://handlebarsjs.com/) template adapter for [Rendr](https://github.com/rendrjs/rendr) apps.
This library has been tested using [Handlebars 2.0.0](https://github.com/wycats/handlebars.js/tree/v2.0.0).

If you'd like to use a more recent version number of `Handlebars` for your app, just specify it in the [package.json](https://github.com/rendrjs/rendr/blame/master/README.md#L315) of your app and start testing it.


## Configuration options

Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var Handlebars = require('handlebars');
module.exports = function(options, Handlebars) {

if (Handlebars['default']) {
// If we only have the Handlebars runtime available, use that here.
// Until Handlebars 3, we have to use 'default' instead of just requiring 'handlebars'.
Handlebars = Handlebars['default'];
}
if (Handlebars['default']) {
// If we only have the Handlebars runtime available, use that here.
// Until Handlebars 3, we have to use 'default' instead of just requiring 'handlebars'.
Handlebars = Handlebars['default'];
}

module.exports = function(options){
var localExports = {},
templateFinder = options.templateFinder || require('./shared/templateFinder')(Handlebars);
templateFinder = options.templateFinder || require('./shared/templateFinder')(Handlebars);

/**
* Export the `Handlebars` object, so other modules can add helpers, partials, etc.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"url": "http://github.com/rendrjs/rendr-handlebars.git"
},
"dependencies": {
"handlebars": "^2.0.0",
"underscore": "^1.8.2"
},
"peerDependencies": {
Expand All @@ -30,6 +29,7 @@
"devDependencies": {
"backbone": "~1.1.2",
"chai": "^2.1.0",
"handlebars": "^2.0.0",
"memo-is": "0.0.2",
"mocha": "~2.1.0",
"sinon": "~1.12.2",
Expand Down
11 changes: 6 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
var assert = require('assert');
var assert = require('assert'),
Handlebars = require('handlebars');

describe("require('rendr-handlebars')", function() {
it('returns a new templateAdapter', function() {
var templateAdapter, firstPatternSrc;
templateAdapter = require('../index')({entryPath: '/some/place/'})
templateAdapter = require('../index')({entryPath: '/some/place/'}, Handlebars);
assert.equal(templateAdapter.templatePatterns.length, 1);
firstPatternSrc = templateAdapter.templatePatterns[0].src;
assert.equal(firstPatternSrc, '/some/place/app/templates/compiledTemplates');
});

it('does not squash an old templateAdapter', function() {
var templateAdapter1, templateAdapter2, firstPatternSrc, secondPatternSrc;
templateAdapter1 = require('../index')({entryPath: '/some/place/'})
templateAdapter2 = require('../index')({entryPath: '/some/other/place/'})
templateAdapter1 = require('../index')({entryPath: '/some/place/'}, Handlebars);
templateAdapter2 = require('../index')({entryPath: '/some/other/place/'}, Handlebars);
assert.equal(templateAdapter1.templatePatterns.length, 1);
assert.equal(templateAdapter2.templatePatterns.length, 1);
firstPatternSrc = templateAdapter1.templatePatterns[0].src;
secondPatternSrc = templateAdapter2.templatePatterns[0].src;
assert.equal(firstPatternSrc, '/some/place/app/templates/compiledTemplates');
assert.equal(secondPatternSrc, '/some/other/place/app/templates/compiledTemplates');
});
});
});
3 changes: 2 additions & 1 deletion test/shared/templateFinder.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var assert = require('assert'),
entryPath = process.cwd() + '/test/fixtures/',
templateAdapter = require('../../index')({entryPath: entryPath});
Handlebars = require('handlebars'),
templateAdapter = require('../../index')({entryPath: entryPath}, Handlebars);

describe('templateFinder', function() {
describe('getTemplate', function() {
Expand Down

0 comments on commit 3108484

Please sign in to comment.