Skip to content

Commit

Permalink
When <menu> is wrapped in a <center> tag, properly apply align='cente…
Browse files Browse the repository at this point in the history
…r', and apply the class 'float-center' instead of 'text-center'
  • Loading branch information
gakimball committed Mar 21, 2016
1 parent 8fbff3a commit 97fde35
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/componentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ module.exports = function(element) {
if (element.attr('class')) {
classes = classes.concat(element.attr('class').split(' '));
}
return format('<table class="%s"><tr><td><table><tr>%s</tr></table></td></tr></table>', classes.join(' '), inner);
var centerAttr = element.attr('align') ? 'align="center"' : '';
return format('<table class="%s"%s><tr><td><table><tr>%s</tr></table></td></tr></table>', classes.join(' '), centerAttr, inner);

// <item>
case this.components.menuItem:
Expand All @@ -83,9 +84,10 @@ module.exports = function(element) {
// <center>
case this.components.center:
if (element.children().length > 0) {
element.children()
.attr('align', 'center')
.addClass('text-center');
element.children().each(function() {
$(this).attr('align', 'center');
$(this).addClass($(this).is('menu, .menu') ? 'float-center' : 'text-center');
});
}

element.attr('data-parsed', '');
Expand Down
24 changes: 24 additions & 0 deletions test/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ describe('Center', () => {

compare(input, expected);
});

it('applies the class float-center instead of text-center to <menu>', () => {
var input = `
<center>
<menu></menu>
</center>
`;

var expected = `
<center data-parsed="">
<table class="menu float-center" align="center">
<tr>
<td>
<table>
<tr></tr>
</table>
</td>
</tr>
</table>
</center>
`;

compare(input, expected);
});
});

describe('Button', () => {
Expand Down

0 comments on commit 97fde35

Please sign in to comment.