Skip to content

Commit

Permalink
Merge pull request #130 from alallier/fixingOneLineIfSpacingProblem
Browse files Browse the repository at this point in the history
Fixing one line if spacing problem
  • Loading branch information
kethinov authored Apr 23, 2017
2 parents 24066e2 + bb3e54d commit 4b12bba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions teddy.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,10 @@
el = removeAttribute(el, 'false');

// Remove all if-conditionals and append condition eval value
el = el.replace(midIfBinaryConditionalRegexp, conditionContent ? ' ' + conditionContent : '');
el = el.replace(endIfBinaryConditionalRegexp, conditionContent ? ' ' + conditionContent : '');
el = el.replace(midIfUnaryConditionalRegexp, conditionContent ? ' ' + conditionContent : '');
el = el.replace(endIfUnaryConditionalRegexp, conditionContent ? ' ' + conditionContent : '');
el = el.replace(midIfBinaryConditionalRegexp, conditionContent ? ' ' + conditionContent + ' ' : ' ');
el = el.replace(endIfBinaryConditionalRegexp, conditionContent ? ' ' + conditionContent + ' ' : ' ');
el = el.replace(midIfUnaryConditionalRegexp, conditionContent ? ' ' + conditionContent + ' ' : ' ');
el = el.replace(endIfUnaryConditionalRegexp, conditionContent ? ' ' + conditionContent + ' ' : ' ');

// append additional one line content if any
el += extraString;
Expand Down
6 changes: 5 additions & 1 deletion test/conditionals.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ describe('Conditionals', function() {
});

it('should evaluate one line if "if-something=\'Some content\'" as true and still add the id attribute regardless of the if statement outcome (conditionals/oneLineValueWithAdditionalAttributesNotImpactedByIf.html)', function(done) {
assert.equalIgnoreSpaces(teddy.render('conditionals/oneLineValueWithAdditionalAttributesNotImpactedByIf.html', model), '<p class=\'something-is-present\' id=\'someId\'>One line if.</p> <p id=\'someId\'>One line if.</p>');
assert.equalIgnoreSpaces(teddy.render('conditionals/oneLineValueWithAdditionalAttributesNotImpactedByIf.html', model), '<p class=\'something-is-present\' id=\'someId\'>One line if.</p> \
<p id=\'someId\'>One line if.</p> \
<p disabled id=\'someId\'>One line if.</p> \
<option selected value=\'3\'>One line if.</option> \
<option value=\'3\' selected >One line if.</option>');
done();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
!}
<p if-something='Some content' true="class='something-is-present'" id='someId'>One line if.</p>
<p if-something='Some content1' true="class='something-is-present'" id='someId'>One line if.</p>
<p if-something='Some content' true='disabled' id='someId'>One line if.</p>
<option if-something='Some content' true='selected' value='3'>One line if.</option>
<option value='3' if-something='Some content' true='selected'>One line if.</option>

0 comments on commit 4b12bba

Please sign in to comment.