-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting `preserve` to `true` will preserve `calc()` in the output, so that they can be used by supporting browsers. Useful now that browsers are starting to implement vars (eg Firefox 31+) & it’s even better for debug [to see real rules](http://cl.ly/image/3W3O0E41173X). I’ve refactored the code a little bit to make it easier to use the `options.preserve` in the main function (& also use rework-visit which is more bullet proof). This should be a major update since now calc need to be called as a function (like rework-vars for example) to be able to pass options. So this should be tagged as 0.3 (or maybe it’s time to ship 1.0 :) ?) I also quickly refactor tests to make it more understandable (plugins.js near preserve.css was confusing imo). I hope it’s ok. FWI, I did this since I’m more seeing rework-vars & rework-calc as fallback than replacement. See reworkcss/rework-vars#28 reworkcss/rework-vars#29 & segmentio/myth#64
- Loading branch information
Showing
15 changed files
with
105 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,8 @@ | |
"mocha": "~1.15.1", | ||
"rework": "~0.18.3", | ||
"chai": "~1.8.1" | ||
}, | ||
"dependencies": { | ||
"rework-visit": "^1.0.0" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
body { | ||
width: 100%; | ||
} | ||
|
||
body > header { | ||
height: calc(3em * 2); | ||
font-size: calc(6em / 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
body { | ||
width: 100%; | ||
} | ||
|
||
body > header { | ||
height: 6em; | ||
height: calc(3em * 2); | ||
font-size: 3em; | ||
font-size: calc(6em / 2); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var calc = require('../index'), | ||
rework = require('rework'), | ||
expect = require('chai').expect, | ||
read = require('fs').readFileSync; | ||
|
||
function fixture(name){ | ||
return read('test/fixtures/' + name + '.css', 'utf8').trim(); | ||
} | ||
|
||
function compareFixtures(name, options){ | ||
return expect( | ||
rework(fixture(name + '.in')) | ||
.use(calc(options)) | ||
.toString().trim() | ||
).to.equal(fixture(name + '.out')); | ||
} | ||
|
||
describe('rework-calc', function() { | ||
it('should calculate expressions with only one unit involved', function() { | ||
compareFixtures('calc'); | ||
}); | ||
|
||
it('should calculate expressions with percents correctly', function () { | ||
compareFixtures('calc-percent'); | ||
}); | ||
|
||
it('should use CSS3 Calc function as fallback for expressions with multiple units', function () { | ||
compareFixtures('calc-complex'); | ||
}); | ||
|
||
it('should handle vendor prefixed expressions', function () { | ||
compareFixtures('calc-prefix'); | ||
}); | ||
|
||
it('should preserves calc() when `preserve` is `true`', function() { | ||
compareFixtures('preserve', {preserve: true}); | ||
}); | ||
}); |