Skip to content

Commit

Permalink
Add separator option to tag cloud helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed May 15, 2015
1 parent e07b59d commit a3c624e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
13 changes: 8 additions & 5 deletions lib/plugins/helper/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ function tagcloudHelper(tags, options){
var unit = options.unit || 'px';
var color = options.color;
var transform = options.transform;
var result = '';
var separator = options.separator || ' ';
var result = [];
var self = this;
var startColor, endColor;

Expand Down Expand Up @@ -223,12 +224,14 @@ function tagcloudHelper(tags, options){
style += ' color: ' + midColor.toString();
}

result += '<a href="' + self.url_for(tag.path) + '" style="' + style + '">';
result += transform ? transform(tag.name) : tag.name;
result +='</a> ';
result.push(
'<a href="' + self.url_for(tag.path) + '" style="' + style + '">' +
(transform ? transform(tag.name) : tag.name) +
'</a>'
);
});

return result;
return result.join(separator);
}

function Color(color){
Expand Down
40 changes: 26 additions & 14 deletions test/scripts/helpers/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20px;">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67px;">cde</a>',
'<a href="/tags/def/" style="font-size: 10px;">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('specified collection', function(){
Expand All @@ -58,7 +58,7 @@ describe('tagcloud', function(){
result.should.eql([
'<a href="/tags/abc/" style="font-size: 10px;">abc</a>',
'<a href="/tags/bcd/" style="font-size: 20px;">bcd</a>'
].join(' ') + ' ');
].join(' '));
});

it('font size', function(){
Expand All @@ -72,7 +72,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 30px;">bcd</a>',
'<a href="/tags/cde/" style="font-size: 25px;">cde</a>',
'<a href="/tags/def/" style="font-size: 15px;">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('font size - when every tag has the same number of posts, font-size should be minimum.', function() {
Expand All @@ -85,7 +85,7 @@ describe('tagcloud', function(){

result.should.eql([
'<a href="/tags/abc/" style="font-size: 15px;">abc</a>'
].join(' ') + ' ');
].join(' '));
});

it('font unit', function(){
Expand All @@ -98,7 +98,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20em;">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67em;">cde</a>',
'<a href="/tags/def/" style="font-size: 10em;">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('orderby', function(){
Expand All @@ -111,7 +111,7 @@ describe('tagcloud', function(){
'<a href="/tags/abc/" style="font-size: 13.33px;">abc</a>',
'<a href="/tags/cde/" style="font-size: 16.67px;">cde</a>',
'<a href="/tags/bcd/" style="font-size: 20px;">bcd</a>'
].join(' ') + ' ');
].join(' '));
});

it('order', function(){
Expand All @@ -124,7 +124,7 @@ describe('tagcloud', function(){
'<a href="/tags/cde/" style="font-size: 16.67px;">cde</a>',
'<a href="/tags/bcd/" style="font-size: 20px;">bcd</a>',
'<a href="/tags/abc/" style="font-size: 13.33px;">abc</a>'
].join(' ') + ' ');
].join(' '));
});

it('amount', function(){
Expand All @@ -135,7 +135,7 @@ describe('tagcloud', function(){
result.should.eql([
'<a href="/tags/abc/" style="font-size: 10px;">abc</a>',
'<a href="/tags/bcd/" style="font-size: 20px;">bcd</a>'
].join(' ') + ' ');
].join(' '));
});

it('transform', function(){
Expand All @@ -150,7 +150,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20px;">BCD</a>',
'<a href="/tags/cde/" style="font-size: 16.67px;">CDE</a>',
'<a href="/tags/def/" style="font-size: 10px;">DEF</a>'
].join(' ') + ' ');
].join(' '));
});

it('color: name', function(){
Expand All @@ -165,7 +165,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20px; color: #ffc0cb">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67px; color: #ff8087">cde</a>',
'<a href="/tags/def/" style="font-size: 10px; color: #f00">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('color: hex', function(){
Expand All @@ -180,7 +180,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20px; color: #ffc0cb">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67px; color: #ff8087">cde</a>',
'<a href="/tags/def/" style="font-size: 10px; color: #f00">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('color: RGBA', function(){
Expand All @@ -195,7 +195,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20px; color: #4682b4">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67px; color: rgba(70, 130, 180, 0.77)">cde</a>',
'<a href="/tags/def/" style="font-size: 10px; color: rgba(70, 130, 180, 0.3)">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('color: HSLA', function(){
Expand All @@ -210,7 +210,7 @@ describe('tagcloud', function(){
'<a href="/tags/bcd/" style="font-size: 20px; color: #4682b4">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67px; color: rgba(70, 130, 180, 0.77)">cde</a>',
'<a href="/tags/def/" style="font-size: 10px; color: rgba(70, 130, 180, 0.3)">def</a>'
].join(' ') + ' ');
].join(' '));
});

it('color - when every tag has the same number of posts, start_color should be used.', function() {
Expand All @@ -224,7 +224,19 @@ describe('tagcloud', function(){

result.should.eql([
'<a href="/tags/abc/" style="font-size: 10px; color: #f00">abc</a>'
].join(' ') + ' ');
].join(' '));
});

it('separator', function(){
var result = tagcloud({
separator: ', '
});

result.should.eql([
'<a href="/tags/abc/" style="font-size: 13.33px;">abc</a>',
'<a href="/tags/bcd/" style="font-size: 20px;">bcd</a>',
'<a href="/tags/cde/" style="font-size: 16.67px;">cde</a>',
'<a href="/tags/def/" style="font-size: 10px;">def</a>'
].join(', '));
});
});

0 comments on commit a3c624e

Please sign in to comment.