forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML helpers refactor - issue TryGhost#246 items 2 and 5.
- moved template logic out of individual helpers and into Ghost - simplified template-driven helpers into closures which maintain the context of handlebars - with handlebars context we have access to data, so don't need to pass data in - check data to test that it is a simple object and not a function - moved helpers back into index.js - provided tests for both template functions in ghost and the nav helper so we are back to where we were
- Loading branch information
Showing
8 changed files
with
162 additions
and
169 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
This file was deleted.
Oops, something went wrong.
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
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 @@ | ||
<h1>HelloWorld</h1> |
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,55 @@ | ||
/*globals describe, beforeEach, it*/ | ||
var should = require('should'), | ||
sinon = require('sinon'), | ||
when = require('when'), | ||
_ = require('underscore'), | ||
handlebars = require('express-hbs').handlebars, | ||
path = require('path'), | ||
helpers = require('../../frontend/helpers'), | ||
Ghost = require('../../ghost'); | ||
|
||
describe('Core Helpers', function () { | ||
|
||
var ghost; | ||
|
||
beforeEach(function () { | ||
ghost = new Ghost(); | ||
}); | ||
|
||
|
||
describe('Navigation Helper', function () { | ||
|
||
it('can render nav items', function (done) { | ||
var templateSpy = sinon.spy(function (data) { return "rendered " + data.links.length; }), | ||
compileSpy = sinon.stub(ghost, 'compileTemplate').returns(when.resolve(templateSpy)), | ||
fakeNavItems = [{ | ||
title: 'test1', | ||
url: '/test1' | ||
}, { | ||
title: 'test2', | ||
url: '/test2' | ||
}], | ||
rendered; | ||
|
||
helpers.loadCoreHelpers(ghost).then(function () { | ||
|
||
should.exist(handlebars.helpers.nav); | ||
|
||
rendered = handlebars.helpers.nav.call({navItems: fakeNavItems}); | ||
|
||
// Returns a string returned from navTemplateFunc | ||
should.exist(rendered); | ||
rendered.string.should.equal("rendered 2"); | ||
|
||
compileSpy.called.should.equal(true); | ||
templateSpy.called.should.equal(true); | ||
templateSpy.calledWith({ links: fakeNavItems }).should.equal(true); | ||
|
||
|
||
compileSpy.restore(); | ||
|
||
done(); | ||
}, done); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.