From 595a5fd52e1368eee6bbc1dfd7203bc89d5ec79b Mon Sep 17 00:00:00 2001 From: Wolfgang Kluge Date: Tue, 21 Apr 2015 09:06:34 +0200 Subject: [PATCH 1/2] list_categories: option to add a css-class that there are child-categories --- lib/plugins/helper/list_categories.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/plugins/helper/list_categories.js b/lib/plugins/helper/list_categories.js index ef951d7b5b..eac2476661 100644 --- a/lib/plugins/helper/list_categories.js +++ b/lib/plugins/helper/list_categories.js @@ -18,6 +18,7 @@ function listCategoriesHelper(categories, options){ var order = options.order || 1; var transform = options.transform; var separator = options.hasOwnProperty('separator') ? options.separator : ', '; + var childrenIndicator = options.hasOwnProperty('children_indicator') ? options.children_indicator : false; var result = ''; var self = this; @@ -39,7 +40,17 @@ function listCategoriesHelper(categories, options){ var result = ''; prepareQuery(parent).forEach(function(cat, i){ - result += '
  • '; + var child; + if (!depth || level + 1 < depth){ + child = hierarchicalList(level + 1, cat._id); + } + + var additionalClassName = ''; + if (child && childrenIndicator){ + additionalClassName = ' ' + childrenIndicator; + } + + result += '
  • '; result += ''; result += transform ? transform(cat.name) : cat.name; @@ -49,12 +60,8 @@ function listCategoriesHelper(categories, options){ result += '' + cat.length + ''; } - if (!depth || level + 1 < depth){ - var child = hierarchicalList(level + 1, cat._id); - - if (child){ - result += '
      ' + child + '
    '; - } + if (child){ + result += '
      ' + child + '
    '; } result += '
  • '; @@ -95,4 +102,4 @@ function listCategoriesHelper(categories, options){ return result; } -module.exports = listCategoriesHelper; \ No newline at end of file +module.exports = listCategoriesHelper; From 9f6b85086baace1975eadd7f9a1ac53c4efdf2e8 Mon Sep 17 00:00:00 2001 From: Wolfgang Kluge Date: Wed, 22 Apr 2015 18:06:45 +0200 Subject: [PATCH 2/2] list_categories: test for option `children_indicator` --- test/scripts/helpers/list_categories.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/scripts/helpers/list_categories.js b/test/scripts/helpers/list_categories.js index 0b5e882692..2a2dcb0820 100644 --- a/test/scripts/helpers/list_categories.js +++ b/test/scripts/helpers/list_categories.js @@ -228,4 +228,26 @@ describe('list_categories', function(){ 'foo1' ].join('')); }); -}); \ No newline at end of file + + it('children-indicator', function(){ + var result = listCategories({ + children_indicator: 'has-children' + }); + + result.should.eql([ + '' + ].join('')); + }); +});