Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sixertoy committed Aug 21, 2015
1 parent c536d83 commit 87b42ea
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion spec/src/conditions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Conditions = require(path.join(cwd, 'src/helpers/conditions.js'));

describe('conditions', function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/src/equal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Equal = require(path.join(cwd, 'src/helpers/equal.js'));

describe('equal', function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/src/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Image = require(path.join(cwd, 'src/helpers/image.js'));
describe('image', function () {
beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/src/literal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Literal = require(path.join(cwd, 'src/helpers/literal.js'));
describe('literal', function () {
beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/src/livereload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Livereload = require(path.join(cwd, 'src/helpers/livereload.js'));
describe('livereload', function () {
beforeEach(function () {
Expand Down
14 changes: 7 additions & 7 deletions spec/src/mustacher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
noop = require('noop'),
sinon = require('sinon'),
expect = require('chai').expect,
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
// helpers
conditions = require(path.join(cwd, 'src/helpers/conditions.js')),
equal = require(path.join(cwd, 'src/helpers/equal.js')),
Expand All @@ -34,29 +34,29 @@
describe('render', function () {
it('throw if no argument', function () {
expect(function () {
mustacher.render();
mustacher();
}).to.throw('missing arguments');
});
it('should return helloworld', function () {
result = mustacher.render('hello world!');
result = mustacher('hello world!');
expect(result).to.equal('hello world!');
});
it('should return \'\' no context', function () {
result = mustacher.render('{{content}}');
result = mustacher('{{content}}');
expect(result).to.equal('');
});
it('should return \'\' empty context', function () {
result = mustacher.render('{{content}}', {});
result = mustacher('{{content}}', {});
expect(result).to.equal('');
});
it('should return helloworld', function () {
result = mustacher.render('{{content}}', {
result = mustacher('{{content}}', {
content: 'hello world!'
});
expect(result).to.equal('hello world!');
});
it('should return <h1>helloworld</h1>', function () {
result = mustacher.render('<h1>{{content}}</h1>', {
result = mustacher('<h1>{{content}}</h1>', {
content: 'hello world!'
});
expect(result).to.equal('<h1>hello world!</h1>');
Expand Down
2 changes: 1 addition & 1 deletion spec/src/random.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Random = require(path.join(cwd, 'src/helpers/random.js'));
describe('random', function () {
beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/src/timestamp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
mustacher = require(path.join(cwd, 'src/mustacher.js')),
mustacher = require(path.join(cwd, 'src/index.js')),
Timestamp = require(path.join(cwd, 'src/helpers/timestamp.js'));
describe('timestamp', function () {
beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
var ConditionsHelper,
Handlebars = require('handlebars'),
compact = require('lodash.compact'),
mustacher = require('./../mustacher');
mustacher = require('./../index');

ConditionsHelper = function () {};

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
var EqualHelper,
Handlebars = require('handlebars'),
isequal = require('lodash.isequal'),
mustacher = require('./../mustacher');
mustacher = require('./../index');

EqualHelper = function () {};

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
var ImageHelper,
Handlebars = require('handlebars'),
isnumber = require('lodash.isnumber'),
mustacher = require('./../mustacher');
mustacher = require('./../index');

ImageHelper = function () {};

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/include.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
LF = '\n',
path = require('path'),
Handlebars = require('handlebars'),
mustacher = require('./../mustacher'),
mustacher = require('./../index'),
isstring = require('lodash.isstring');

IncludeHelper = function () {};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

var LiteralHelper,
Handlebars = require('handlebars'),
mustacher = require('./../mustacher');
mustacher = require('./../index');

LiteralHelper = function () {};

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
isboolean = require('lodash.isboolean'),
// requires
Handlebars = require('handlebars'),
mustacher = require('./../mustacher'),
mustacher = require('./../index'),
isplainobject = require('lodash.isplainobject');

LivereloadHelper = function () {};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Handlebars = require('handlebars'),
random = require('lodash.random'),
isnumber = require('lodash.isnumber'),
mustacher = require('./../mustacher'),
mustacher = require('./../index'),
isboolean = require('lodash.isboolean');

RandomHelper = function () {};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
var RepeatHelper,
isnan = require('lodash.isnan'),
Handlebars = require('handlebars'),
mustacher = require('./../mustacher');
mustacher = require('./../index');

RepeatHelper = function () {};

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

var TimestampHelper,
Handlebars = require('handlebars'),
mustacher = require('./../mustacher'),
mustacher = require('./../index'),
isnumber = require('lodash.isnumber');

TimestampHelper = function () {};
Expand Down
32 changes: 16 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,24 @@
isstring = require('lodash.isstring'),
isplainobject = require('lodash.isplainobject');

mustacher = function (str, context) {
if (arguments.length < 1 || !isstring(str) || isempty(str)) {
throw new Error('missing arguments');
}
if (!_isRegistered) {
mustacher.register();
}
context = context || {};
return handlebars.compile(str, {
trackIds: false
})(context, {
data: _defaults
}).trim();
};

mustacher.register = function (helpers) {
var helper, Proto;
helpers.forEach(function (name) {
(helpers || _helpers).forEach(function (name) {
Proto = require(path.join(__dirname, 'helpers', name));
helper = new Proto();
helper.register();
Expand All @@ -63,21 +78,6 @@
return isplainobject(args[args.length - 1]) && args[args.length - 1].hasOwnProperty('name') ? args : false;
};

mustacher = function (str, context) {
if (arguments.length < 1 || !isstring(str) || isempty(str)) {
throw new Error('missing arguments');
}
if (!_isRegistered) {
mustacher.register(_helpers);
}
context = context || {};
return handlebars.compile(str, {
trackIds: false
})(context, {
data: _defaults
}).trim();
};

module.exports = mustacher;

}());

0 comments on commit 87b42ea

Please sign in to comment.