Skip to content

Commit 75dc7ce

Browse files
committed
add media support
1 parent 1af0c00 commit 75dc7ce

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

examples/media.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@media screen, projection {
2+
html {
3+
background: #fffef0;
4+
color: #300;
5+
}
6+
body {
7+
max-width: 35em;
8+
margin: 0 auto;
9+
}
10+
}
11+
12+
@media print {
13+
html {
14+
background: #fff;
15+
color: #000;
16+
}
17+
body {
18+
padding: 1in;
19+
border: 0.5pt solid #666;
20+
}
21+
}

examples/media.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var parse = require('css-parse')
7+
, stringify = require('..')
8+
, fs = require('fs')
9+
, read = fs.readFileSync
10+
, css = read('examples/media.css', 'utf8');
11+
12+
console.log(stringify(parse(css), { compress: false }));

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ module.exports = function(node, options){
2222
function visit(options) {
2323
var _rule = rule(options);
2424
var _keyframes = keyframes(options);
25+
var _media = media(options);
2526
return function(node){
2627
if (node.keyframes) return _keyframes(node);
28+
if (node.media) return _media(node);
2729
if (node.import) return atimport(node);
2830
return _rule(node);
2931
}
@@ -37,6 +39,20 @@ function atimport(rule) {
3739
return '@import ' + rule.import + ';';
3840
}
3941

42+
/**
43+
* Compile media.
44+
*/
45+
46+
function media(options) {
47+
return function(media){
48+
return '@media '
49+
+ media.media
50+
+ ' {\n'
51+
+ media.rules.map(indent(visit(options))).join('\n\n')
52+
+ '\n}';
53+
}
54+
}
55+
4056
/**
4157
* Compile keyframes.
4258
*/

0 commit comments

Comments
 (0)