Skip to content

Commit

Permalink
Fixes pencilblue#690 to causes the wrong theme to be chosen when an a…
Browse files Browse the repository at this point in the history
…rticle has a non-default theme.
  • Loading branch information
brianhyder committed Jul 19, 2015
1 parent e6d88d7 commit 978c02a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
20 changes: 19 additions & 1 deletion include/service/entities/content/content_view_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ module.exports = function(pb) {
var Localization = pb.Localization;
var ClientJs = pb.ClientJs;

/**
* Renders a 1 or more pieces of content such as articles or pages
* @class ContentViewLoader
* @constructor
* @param {Object} context
* @param {TemplateService} context.ts
* @param {Localization} context.ls
* @param {Object} [context.contentSettings]
* @param {Object} context.session
* @param {ContentObjectService} context.service
* @param {String} context.activeTheme
*/
function ContentViewLoader(context) {

this.ts = context.ts;
Expand Down Expand Up @@ -63,6 +75,9 @@ module.exports = function(pb) {
* @method render
* @param {Array} contentArray
* @param {Object} options
* @param {Boolean} [options.useDefaultTemplate] Forces the default theme template to be selected
* @param {Object} [options.topic] The topic represented by the collection of content to be rendered
* @param {Object} [options.section] The section represented by the collection of content to be rendered
* @param {Function} cb
*/
ContentViewLoader.prototype.render = function(contentArray, options, cb) {
Expand Down Expand Up @@ -105,13 +120,16 @@ module.exports = function(pb) {
* @method getTemplate
* @param {Array|Object} content
* @param {Object} options
* @param {Boolean} [options.useDefaultTemplate] Forces the default theme template to be selected
* @param {Object} [options.topic] The topic represented by the collection of content to be rendered
* @param {Object} [options.section] The section represented by the collection of content to be rendered
* @param {Function} cb
*/
ContentViewLoader.prototype.getTemplate = function(content, options, cb) {

//check if we should just use whatever default there is.
//this could fall back to an active theme or the default pencilblue theme.
if (util.isObject(options.topic) || util.isObject(options.section)) {
if (options.useDefaultTemplate || util.isObject(options.topic) || util.isObject(options.section)) {
return cb(null, this.getDefaultTemplatePath());
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/pencilblue/controllers/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ module.exports = function(pb) {
}

//render
var options = {};
var options = {
useDefaultTemplate: true
};
self.contentViewLoader.render(articles, options, function(err, html) {
if (util.isError(err)) {
return cb(err);
Expand Down
26 changes: 14 additions & 12 deletions plugins/sample/controllers/random_text_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function RandomTextViewControllerModule(pb) {
//Templates can reference the "head" and "footer" templates inside of the
//loaded template to ensure that the view is wrapped by the navigation and
//footer.
this.getNavigation(function(err, navigation, accountButtons) {
this.getNavigation(function(err, navItems) {

//Create an instance of the text service. Then we call the service for
//random text
Expand Down Expand Up @@ -115,8 +115,8 @@ module.exports = function RandomTextViewControllerModule(pb) {
//Values provided to template service can be wrapped in an
//TemplateValue which contains an option to skip the encoding if the
//value itself is HTML.
self.ts.registerLocal('navigation', new pb.TemplateValue(navigation, false));
self.ts.registerLocal('account_buttons', accountButtons);
self.ts.registerLocal('navigation', new pb.TemplateValue(navItems.navigation, false));
self.ts.registerLocal('account_buttons', navItems.accountButtons);

//The template service is pretty simple. More complex features such as
//loops are handled by providing a function to the template service
Expand Down Expand Up @@ -191,18 +191,20 @@ module.exports = function RandomTextViewControllerModule(pb) {

/**
* Retrieves the navigation for the page.
* @param {function} cb Callback that provides three parameters: cb(Error, navigation, accountButtons);
* @param {function} cb Callback that provides two parameters:
* cb(Error, {navigation "", accountButtons: "", themeSettings: {}});
*/
RandomTextViewController.prototype.getNavigation = function(cb) {

var options = {
currUrl: this.req.url
};
TopMenuService.getTopMenu(this.session, this.localizationService, options, function(themeSettings, navigation, accountButtons) {
TopMenuService.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) {
cb(null, navigation, accountButtons);
});
});
//build out options starting with a service context object. It
//contains all the good stuff like localization, template service,
//activeTheme, and session.
var options = this.getServiceContext();
options.currUrl = this.req.url;

//create a new instance of the top menu service and request the navigation items
var service = new TopMenuService();
service.getNavItems(options, cb);
};

/**
Expand Down

0 comments on commit 978c02a

Please sign in to comment.