-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f94cc3d
Showing
9 changed files
with
212 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# Packages # | ||
############ | ||
# it's better to unpack these files and commit the raw source | ||
# git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
|
||
# Logs and databases # | ||
###################### | ||
*.log | ||
*.sql | ||
*.sqlite | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
|
||
# Node.js # | ||
########### | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules | ||
npm-debug.log | ||
|
||
# Components # | ||
############## | ||
|
||
/build | ||
/components | ||
/vendors | ||
*.orig |
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 @@ | ||
test/ |
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 @@ | ||
test: | ||
@node test | ||
|
||
install: | ||
@npm install | ||
|
||
tests: test | ||
|
||
.PHONY: test |
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,30 @@ | ||
## Move Media | ||
|
||
Aggregate media queries and move it to the end of the file. | ||
|
||
### API | ||
|
||
var moveMedia = require('move-media') | ||
|
||
var css = rework(inputCSS) | ||
.use(moveMedia(sortFunction)) | ||
.toString() | ||
|
||
By default, `sortFunction` just sorts the queries alphabetically: | ||
|
||
function sortFunction(a, b) { | ||
if (a < b) return 1; | ||
if (a > b) return -1; | ||
return 0 | ||
} | ||
|
||
### Limitations | ||
|
||
- Assumes media query order does not matter. | ||
If it does, then use your own sort function. | ||
- Declarations within each media query preserves order. | ||
- In general, keep the order in mind! | ||
|
||
### License | ||
|
||
WTFPL |
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,28 @@ | ||
module.exports = function (sortFn) { | ||
if (!sortFn) { | ||
sortFn = function (a, b) { | ||
if (a < b) return 1; | ||
if (b > a) return -1; | ||
return 0 | ||
} | ||
} | ||
|
||
return function (style) { | ||
var rules = [] | ||
var media = {} | ||
|
||
style.rules.forEach(function (rule) { | ||
var query = rule.media | ||
if (!query) return rules.push(rule); | ||
|
||
;[].push.apply((media[query] || (media[query] = { | ||
media: query, | ||
rules: [] | ||
})).rules, rule.rules) | ||
}) | ||
|
||
style.rules = rules.concat(Object.keys(media).sort(sortFn).map(function (query) { | ||
return media[query] | ||
})) | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"name": "rework-move-media", | ||
"description": "Move media to the end of the CSS file", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"rework": "*" | ||
} | ||
} |
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,33 @@ | ||
@media (min-width: 100px) { | ||
body { | ||
color: black; | ||
} | ||
} | ||
|
||
body { | ||
color: yellow; | ||
} | ||
|
||
@media (min-width: 100px) { | ||
body { | ||
color: green; | ||
} | ||
} | ||
|
||
@media (min-width: 100px) { | ||
body { | ||
color: red; | ||
} | ||
} | ||
|
||
@media (max-width: 300px) { | ||
body { | ||
color: orange; | ||
} | ||
} | ||
|
||
@media (min-width: 100px) { | ||
body { | ||
color: purple; | ||
} | ||
} |
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,27 @@ | ||
body { | ||
color: yellow | ||
} | ||
|
||
@media (min-width: 100px) { | ||
body { | ||
color: black | ||
} | ||
|
||
body { | ||
color: green | ||
} | ||
|
||
body { | ||
color: red | ||
} | ||
|
||
body { | ||
color: purple | ||
} | ||
} | ||
|
||
@media (max-width: 300px) { | ||
body { | ||
color: orange | ||
} | ||
} |
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,16 @@ | ||
var fs = require('fs') | ||
var assert = require('assert') | ||
|
||
var rework = require('rework') | ||
var inherit = require('../') | ||
|
||
function read(file) { | ||
return fs.readFileSync('test/fixtures/' + file + '.css', 'utf8') | ||
} | ||
|
||
function test(file, msg) { | ||
var out = rework(read(file)).use(inherit()).toString() | ||
assert.equal(out, read(file + '.out'), msg + ': ' + out) | ||
} | ||
|
||
test('general', 'General failed') |