Skip to content

Commit e02df7f

Browse files
committed
add @document compilation. Closes #82
1 parent f274424 commit e02df7f

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

examples/document.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@-moz-document url-prefix() {
2+
.icon-spin {
3+
height: .9em
4+
}
5+
6+
.btn .icon-spin {
7+
height: auto
8+
}
9+
10+
.icon-spin.icon-large {
11+
height: 1.25em
12+
}
13+
14+
.btn .icon-spin.icon-large {
15+
height: .75em
16+
}
17+
}

examples/document.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/document.css', 'utf8');
11+
12+
console.log(stringify(parse(css), { compress: false }));

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Compiler.prototype.compile = function(node){
3636
*/
3737

3838
Compiler.prototype.visit = function(node){
39+
if (node.document) return this.document(node);
3940
if (node.comment) return this.comment(node);
4041
if (node.charset) return this.charset(node);
4142
if (node.keyframes) return this.keyframes(node);
@@ -83,6 +84,28 @@ Compiler.prototype.media = function(node){
8384
+ '\n}';
8485
};
8586

87+
/**
88+
* Visit document node.
89+
*/
90+
91+
Compiler.prototype.document = function(node){
92+
var doc = '@' + (node.vendor || '') + 'document ' + node.document;
93+
94+
if (this.compress) {
95+
return doc
96+
+ '{'
97+
+ node.rules.map(this.visit, this).join('')
98+
+ '}';
99+
}
100+
101+
return doc + ' '
102+
+ ' {\n'
103+
+ this.indent(1)
104+
+ node.rules.map(this.visit, this).join('\n\n')
105+
+ this.indent(-1)
106+
+ '\n}';
107+
};
108+
86109
/**
87110
* Visit charset node.
88111
*/

test/cases/document.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@-moz-document url-prefix() {
2+
.icon-spin {
3+
height: .9em
4+
}
5+
6+
.btn .icon-spin {
7+
height: auto
8+
}
9+
10+
.icon-spin.icon-large {
11+
height: 1.25em
12+
}
13+
14+
.btn .icon-spin.icon-large {
15+
height: .75em
16+
}
17+
}

0 commit comments

Comments
 (0)