Skip to content

Commit

Permalink
Merge pull request #1246 from WolfgangKluge/categories-show-children-…
Browse files Browse the repository at this point in the history
…indicator

Categories show children indicator
  • Loading branch information
tommy351 committed May 1, 2015
2 parents f2514cb + 9f6b850 commit 57596a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
23 changes: 15 additions & 8 deletions lib/plugins/helper/list_categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,7 +40,17 @@ function listCategoriesHelper(categories, options){
var result = '';

prepareQuery(parent).forEach(function(cat, i){
result += '<li class="' + className + '-list-item">';
var child;
if (!depth || level + 1 < depth){
child = hierarchicalList(level + 1, cat._id);
}

var additionalClassName = '';
if (child && childrenIndicator){
additionalClassName = ' ' + childrenIndicator;
}

result += '<li class="' + className + '-list-item' + additionalClassName + '">';

result += '<a class="' + className + '-list-link" href="' + self.url_for(cat.path) + '">';
result += transform ? transform(cat.name) : cat.name;
Expand All @@ -49,12 +60,8 @@ function listCategoriesHelper(categories, options){
result += '<span class="' + className + '-list-count">' + cat.length + '</span>';
}

if (!depth || level + 1 < depth){
var child = hierarchicalList(level + 1, cat._id);

if (child){
result += '<ul class="' + className + '-list-child">' + child + '</ul>';
}
if (child){
result += '<ul class="' + className + '-list-child">' + child + '</ul>';
}

result += '</li>';
Expand Down Expand Up @@ -95,4 +102,4 @@ function listCategoriesHelper(categories, options){
return result;
}

module.exports = listCategoriesHelper;
module.exports = listCategoriesHelper;
24 changes: 23 additions & 1 deletion test/scripts/helpers/list_categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,26 @@ describe('list_categories', function(){
'<a class="category-link" href="/categories/foo/">foo<span class="category-count">1</span></a>'
].join(''));
});
});

it('children-indicator', function(){
var result = listCategories({
children_indicator: 'has-children'
});

result.should.eql([
'<ul class="category-list">',
'<li class="category-list-item has-children">',
'<a class="category-list-link" href="/categories/baz/">baz</a><span class="category-list-count">3</span>',
'<ul class="category-list-child">',
'<li class="category-list-item">',
'<a class="category-list-link" href="/categories/baz/bar/">bar</a><span class="category-list-count">1</span>',
'</li>',
'</ul>',
'</li>',
'<li class="category-list-item">',
'<a class="category-list-link" href="/categories/foo/">foo</a><span class="category-list-count">1</span>',
'</li>',
'</ul>'
].join(''));
});
});

0 comments on commit 57596a9

Please sign in to comment.