From 2800671bbdf89c6691f15866ff87602d0173c10b Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 22 Aug 2014 09:48:42 +0100 Subject: [PATCH] Add the new body classes closes #1967 - adds paged to eventually replace archive-template - adds page-template to eventually replace page - changes custom page template class to be page-slug instead of page-template-slug --- core/server/helpers/index.js | 33 +++++++++++++-------- core/test/unit/server_helpers_index_spec.js | 10 +++---- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index b7294b17e3..86608fb16c 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -408,13 +408,6 @@ coreHelpers.body_class = function (options) { tags = this.post && this.post.tags ? this.post.tags : this.tags || [], page = this.post && this.post.page ? this.post.page : this.page || false; - if (_.isString(this.relativeUrl) && this.relativeUrl.match(/\/(page\/\d)/)) { - classes.push('archive-template'); - } else if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '') { - classes.push('home-template'); - } else if (post) { - classes.push('post-template'); - } if (this.tag !== undefined) { classes.push('tag-template'); @@ -426,26 +419,40 @@ coreHelpers.body_class = function (options) { classes.push('author-' + this.author.slug); } - if (tags) { - classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; })); + if (_.isString(this.relativeUrl) && this.relativeUrl.match(/\/(page\/\d)/)) { + classes.push('paged'); + // To be removed from pages by #2597 when we're ready to deprecate this + classes.push('archive-template'); + + } else if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '') { + classes.push('home-template'); + } else if (post) { + // To be removed from pages by #2597 when we're ready to deprecate this + // i.e. this should be if (post && !page) { ... } + classes.push('post-template'); } if (page) { + classes.push('page-template'); + // To be removed by #2597 when we're ready to deprecate this classes.push('page'); } + if (tags) { + classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; })); + } + return api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function (response) { var activeTheme = response.settings[0], paths = config.paths.availableThemes[activeTheme.value], view; - if (post) { + if (post && page) { view = template.getThemeViewForPost(paths, post).split('-'); - // If this is a page and we have a custom page template - // then we need to modify the class name we inject - // e.g. 'page-contact' is outputted as 'page-template-contact' if (view[0] === 'page' && view.length > 1) { + classes.push(view.join('-')); + // To be removed by #2597 when we're ready to deprecate this view.splice(1, 0, 'template'); classes.push(view.join('-')); } diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 36b66d0fc4..d5725bedd7 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -414,11 +414,11 @@ describe('Core Helpers', function () { rendered[0].string.should.equal('home-template'); rendered[1].string.should.equal('post-template'); - rendered[2].string.should.equal('archive-template'); + rendered[2].string.should.equal('paged archive-template'); rendered[3].string.should.equal('tag-template tag-foo'); - rendered[4].string.should.equal('archive-template tag-template tag-foo'); + rendered[4].string.should.equal('tag-template tag-foo paged archive-template'); rendered[5].string.should.equal('author-template author-bar'); - rendered[6].string.should.equal('archive-template author-template author-bar'); + rendered[6].string.should.equal('author-template author-bar paged archive-template'); done(); }).catch(done); @@ -432,7 +432,7 @@ describe('Core Helpers', function () { } }).then(function (rendered) { should.exist(rendered); - rendered.string.should.equal('home-template page'); + rendered.string.should.equal('home-template page-template page'); done(); }).catch(done); @@ -448,7 +448,7 @@ describe('Core Helpers', function () { } }).then(function (rendered) { should.exist(rendered); - rendered.string.should.equal('post-template page page-template-about'); + rendered.string.should.equal('post-template page-template page page-about page-template-about'); done(); }).catch(done);