Skip to content

Commit

Permalink
#382 Adds the ability to have 'important' added to the end of calcValue
Browse files Browse the repository at this point in the history
  • Loading branch information
peterramsing committed Apr 7, 2018
1 parent 797df92 commit 70378b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/_lg-logic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module.exports = {

calcValue: function(fraction, gutter, rounder, unit) {
/**
* Generates the calc value for LostGrid
* @param {string} fraction
* @param {string} gutter
* @param {number} rounder
* @param {string} unit
* @param {boolean} [important=false] - Whether "!important" should be added to the end
* @returns {string}
*/
calcValue: function(fraction, gutter, rounder, unit, important=false) {
var calcValue = '';
var gutterLogic = '';

Expand All @@ -17,6 +26,10 @@ module.exports = {
}

calcValue = `calc(${rounder}${unit} * ${fraction}${gutterLogic})`;

if (important) {
calcValue = calcValue + '!important';
}
return calcValue;
},
validateUnit: function(value, validUnits) {
Expand Down
14 changes: 14 additions & 0 deletions test/lg-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ describe('calcValue works as it should', () => {

var expectedResult = 'calc(99.9% * 1/3)';

expect(testCase).to.equal(expectedResult);
});
it('should add !important to the end if told to', () => {
var testCase = lgLogic.calcValue('1/3', '0', 99.9, '%', true);

var expectedResult = 'calc(99.9% * 1/3)!important';

expect(testCase).to.equal(expectedResult);
});
it('should not add !important to the end if told to', () => {
var testCase = lgLogic.calcValue('1/3', '0', 99.9, '%', false);

var expectedResult = 'calc(99.9% * 1/3)';

expect(testCase).to.equal(expectedResult);
});
});
Expand Down

0 comments on commit 70378b4

Please sign in to comment.