Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refresh tests for lib/utils. Add test .jshintrc file. Switch tests to Mocha.
- Loading branch information
Showing
17 changed files
with
288 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
var index = require('./index'), | ||
compile = require('./utils/compile'), | ||
render = require('./utils/render'); | ||
|
||
module.exports = function (config) { | ||
var template, | ||
fileName, | ||
compiled = compile.call(this, config); | ||
|
||
render.call(this, config, compiled); | ||
|
||
if (config.index) { | ||
template = compiled['index.' + config.schemas.suffix]; | ||
fileName = 'index.' + config.target.suffix; | ||
|
||
this.clipboard.files[fileName] = template(index.call(this, config)); | ||
} | ||
|
||
delete this.clipboard.files.templates; | ||
|
||
}; |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
var _ = require('underscore'); | ||
|
||
module.exports = function (config) { | ||
var engine = require(config.templates.lib), | ||
templateMatcher = new RegExp(config.templates.suffix + '$'), | ||
compiled = {}; | ||
|
||
_.each(this.clipboard.files.templates, function (template, name) { | ||
if (name.match(templateMatcher)) { | ||
name = name.replace(templateMatcher, config.schemas.suffix); | ||
compiled[name] = engine.compile(template, { | ||
filename: config.templates.path | ||
}); | ||
} | ||
}); | ||
|
||
return compiled; | ||
}; |
File renamed without changes.
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var _ = require('underscore'); | ||
|
||
module.exports = function (config, compiled) { | ||
var template, | ||
fileName, | ||
schemaMatcher = new RegExp(config.schemas.suffix + '$'), | ||
defaultTemplate = config.templates.file + '.' + config.schemas.suffix; | ||
|
||
_.each(this.clipboard.files.schemas, function (schema, name) { | ||
if (typeof schema === 'string') { | ||
template = compiled[name] || compiled[defaultTemplate]; | ||
fileName = name.replace(schemaMatcher, config.target.suffix); | ||
schema = JSON.parse(schema); | ||
schema.config = config; | ||
this.clipboard.files[fileName] = template(schema); | ||
} | ||
}.bind(this)); | ||
|
||
}; |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"predef": [ | ||
"beforeEach", | ||
"afterEach", | ||
"before", | ||
"after", | ||
"describe", | ||
"it", | ||
"sandbox", | ||
"expect" | ||
], | ||
|
||
"node": true, | ||
|
||
"bitwise" : true, | ||
"camelcase" : true, | ||
"curly" : true, | ||
"eqeqeq" : true, | ||
"immed" : true, | ||
"indent" : 2, | ||
"latedef" : "nofunc", | ||
"newcap" : true, | ||
"noarg" : true, | ||
"noempty" : true, | ||
"nonew" : true, | ||
"quotmark" : "single", | ||
"undef" : true, | ||
"unused" : true, | ||
"strict" : true, | ||
"trailing" : true, | ||
"maxdepth" : 3, | ||
"maxstatements" : 10, | ||
"maxcomplexity" : 5, | ||
"expr" : true, | ||
|
||
"boss" : true | ||
|
||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
global.sinon = require('sinon'); | ||
global.should = require('chai') | ||
.use(require('sinon-chai')) | ||
.should(); | ||
|
||
(function () { | ||
global.sandbox = function (fn) { | ||
|
||
beforeEach(function () { | ||
global.sandbox = global.sinon.sandbox.create({ | ||
injectInto: null, | ||
properties: ['spy', 'stub', 'mock'] | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
global.sandbox.restore(); | ||
}); | ||
|
||
return fn; | ||
}; | ||
})(); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--require test/common.js | ||
--recursive | ||
--reporter spec |
This file contains 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
var compile = require('../../../../lib/utils/compile'); | ||
|
||
describe('lib/utils/compile', sandbox(function () { | ||
var config, | ||
compiled; | ||
|
||
beforeEach(function () { | ||
config = { | ||
templates: { | ||
lib: 'jade', | ||
suffix: 'jade' | ||
}, | ||
schemas: { | ||
suffix: 'json' | ||
} | ||
}; | ||
|
||
this.clipboard = { | ||
files: { | ||
templates: { | ||
'foo.jade': 'h1 foo', | ||
'bar.jade': 'h1 bar' | ||
} | ||
} | ||
}; | ||
|
||
compiled = compile.call(this, config); | ||
}); | ||
|
||
it('compiles templates with the schema suffix', function () { | ||
(typeof compiled['foo.json']).should.equal('function'); | ||
(typeof compiled['bar.json']).should.equal('function'); | ||
}); | ||
|
||
})); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
var map = require('../../../../lib/utils/map-parents'), | ||
_ = require('underscore'); | ||
|
||
describe('lib/utils/map-parents', sandbox(function () { | ||
var object, mapping; | ||
|
||
beforeEach(function () { | ||
object = { | ||
foo: { id: 'foobar', nested: { id: 'xxx' } }, | ||
bar: { id: 'qwerty' }, | ||
baz: { notId: 'bar' } | ||
}; | ||
|
||
mapping = map(object, 'id'); | ||
}); | ||
|
||
it('returns a flat object keyed by the requested inner key', function () { | ||
mapping.foobar.should.deep.equal(object.foo); | ||
mapping.xxx.should.deep.equal(object.foo.nested); | ||
mapping.qwerty.should.deep.equal(object.bar); | ||
}); | ||
|
||
it('only maps the child objects containing the requested keys', function () { | ||
_.keys(mapping).should.deep.equal([ 'foobar', 'xxx', 'qwerty' ]); | ||
}); | ||
|
||
})); |
Oops, something went wrong.