mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
Used settingsCache.getPublic() in theme middleware
- Use the new getPublic function which does the same thing as this code - This removes the inclusion of the amp property, but this is undocumented and should not be there anyway! - This also adds the ghost_head and ghost_foot property, which are public settings
This commit is contained in:
parent
5d977f23d4
commit
652e818cae
@ -45,18 +45,7 @@ themeMiddleware.ensureActiveTheme = function ensureActiveTheme(req, res, next) {
|
||||
themeMiddleware.updateTemplateData = function updateTemplateData(req, res, next) {
|
||||
// Static information, same for every request unless the settings change
|
||||
// @TODO: bind this once and then update based on events?
|
||||
var blogData = {
|
||||
title: settingsCache.get('title'),
|
||||
description: settingsCache.get('description'),
|
||||
facebook: settingsCache.get('facebook'),
|
||||
twitter: settingsCache.get('twitter'),
|
||||
timezone: settingsCache.get('active_timezone'),
|
||||
navigation: settingsCache.get('navigation'),
|
||||
icon: settingsCache.get('icon'),
|
||||
cover_image: settingsCache.get('cover_image'),
|
||||
logo: settingsCache.get('logo'),
|
||||
amp: settingsCache.get('amp')
|
||||
},
|
||||
var blogData = settingsCache.getPublic(),
|
||||
labsData = _.cloneDeep(settingsCache.get('labs')),
|
||||
themeData = {};
|
||||
|
||||
|
@ -16,7 +16,7 @@ describe('Themes', function () {
|
||||
});
|
||||
|
||||
describe('Middleware', function () {
|
||||
var req, res, blogApp, getActiveThemeStub, settingsCacheStub;
|
||||
var req, res, blogApp, getActiveThemeStub, settingsCacheStub, settingPublicStub;
|
||||
|
||||
beforeEach(function () {
|
||||
req = sandbox.spy();
|
||||
@ -28,6 +28,7 @@ describe('Themes', function () {
|
||||
|
||||
getActiveThemeStub = sandbox.stub(activeTheme, 'get');
|
||||
settingsCacheStub = sandbox.stub(settingsCache, 'get');
|
||||
settingPublicStub = sandbox.stub(settingsCache, 'getPublic').returns({});
|
||||
});
|
||||
|
||||
describe('ensureActiveTheme', function () {
|
||||
@ -96,16 +97,11 @@ describe('Themes', function () {
|
||||
describe('updateTemplateData', function () {
|
||||
var updateTemplateData = middleware[1],
|
||||
themeDataExpectedProps = ['posts_per_page', 'image_sizes'],
|
||||
blogDataExpectedProps = [
|
||||
'url', 'title', 'description', 'logo', 'cover_image', 'icon', 'twitter', 'facebook', 'navigation',
|
||||
'timezone', 'amp'
|
||||
],
|
||||
updateOptionsStub;
|
||||
|
||||
beforeEach(function () {
|
||||
updateOptionsStub = sandbox.stub(hbs, 'updateTemplateOptions');
|
||||
|
||||
settingsCacheStub.withArgs('title').returns('Bloggy McBlogface');
|
||||
settingsCacheStub.withArgs('labs').returns({});
|
||||
|
||||
getActiveThemeStub.returns({
|
||||
@ -130,15 +126,11 @@ describe('Themes', function () {
|
||||
// posts per page should be set according to the stub
|
||||
templateOptions.data.config.posts_per_page.should.eql(2);
|
||||
|
||||
// Check blog config
|
||||
// blog should have all the right properties
|
||||
templateOptions.data.blog.should.be.an.Object()
|
||||
.with.properties(blogDataExpectedProps)
|
||||
.and.size(blogDataExpectedProps.length);
|
||||
// Check blog config tried to call public settings
|
||||
settingPublicStub.calledOnce.should.be.true();
|
||||
|
||||
// url should be correct
|
||||
templateOptions.data.blog.url.should.eql('http://127.0.0.1:2369');
|
||||
// should get the title
|
||||
templateOptions.data.blog.title.should.eql('Bloggy McBlogface');
|
||||
|
||||
// Check labs config
|
||||
templateOptions.data.labs.should.be.an.Object();
|
||||
@ -167,15 +159,11 @@ describe('Themes', function () {
|
||||
// posts per page should NOT be set as there's no active theme
|
||||
should.not.exist(templateOptions.data.config.posts_per_page);
|
||||
|
||||
// Check blog config
|
||||
// blog should have all the right properties
|
||||
templateOptions.data.blog.should.be.an.Object()
|
||||
.with.properties(blogDataExpectedProps)
|
||||
.and.size(blogDataExpectedProps.length);
|
||||
// Check blog config tried to call public settings
|
||||
settingPublicStub.calledOnce.should.be.true();
|
||||
|
||||
// url should be correct
|
||||
templateOptions.data.blog.url.should.eql('http://127.0.0.1:2369');
|
||||
// should get the title
|
||||
templateOptions.data.blog.title.should.eql('Bloggy McBlogface');
|
||||
|
||||
// Check labs config
|
||||
templateOptions.data.labs.should.be.an.Object();
|
||||
@ -203,15 +191,10 @@ describe('Themes', function () {
|
||||
// posts per page should be set according to the stub
|
||||
templateOptions.data.config.posts_per_page.should.eql(2);
|
||||
|
||||
// Check blog config
|
||||
// blog should have all the right properties
|
||||
templateOptions.data.blog.should.be.an.Object()
|
||||
.with.properties(blogDataExpectedProps)
|
||||
.and.size(blogDataExpectedProps.length);
|
||||
// Check blog config tried to call public settings
|
||||
settingPublicStub.calledOnce.should.be.true();
|
||||
// url should be correct HTTPS!
|
||||
templateOptions.data.blog.url.should.eql('https://127.0.0.1:2369');
|
||||
// should get the title
|
||||
templateOptions.data.blog.title.should.eql('Bloggy McBlogface');
|
||||
|
||||
// Check labs config
|
||||
templateOptions.data.labs.should.be.an.Object();
|
||||
|
Loading…
Reference in New Issue
Block a user