Skip to content

Commit 509c05f

Browse files
committed
fix @fontface support
1 parent 3615214 commit 509c05f

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

lib/compiler.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = function(node){
5959
function block(node) {
6060
var buf = [];
6161
var nodes = node[1];
62-
62+
6363
for (var i = 0; i < nodes.length; ++i) {
6464
buf.push(visit(nodes[i]));
6565
}
@@ -82,21 +82,22 @@ module.exports = function(node){
8282
*/
8383

8484
function rule(node) {
85+
var font = '@font-face' == node[1][0].trim();
8586
var rule = node[1];
8687
var block = node[2];
8788
var buf = '';
88-
89+
8990
if (!block) return rule.join('') + ';';
9091

9192
rules.push(node);
9293

93-
if ('@' == rule[0][0]) {
94+
if ('@' == rule[0][0] && !font) {
9495
buf = join(rules) + ' {\n';
9596
visit(block);
9697
buf += stash.join('\n');
9798
buf += '\n}';
9899
stash = [];
99-
} else if (nest) {
100+
} else if (nest && !font) {
100101
indents = 1;
101102
buf = join(rules, 1) + ' {\n';
102103
indents = 2;
@@ -117,9 +118,9 @@ module.exports = function(node){
117118
if (hasProperties(block)) stash.push(buf);
118119
buf = '';
119120
}
120-
121+
121122
rules.pop();
122-
123+
123124
return buf;
124125
}
125126

@@ -147,14 +148,14 @@ module.exports = function(node){
147148
* @return {String}
148149
* @api private
149150
*/
150-
151+
151152
function join(rules, offset) {
152153
offset = offset || 0;
153154
var selectors = [];
154155
var buf = [];
155156
var curr;
156157
var next;
157-
158+
158159
function compile(rules, i) {
159160
if (offset != i) {
160161
var parent = rules[i].parent;
@@ -170,16 +171,16 @@ module.exports = function(node){
170171
});
171172
}
172173
}
173-
174+
174175
compile(rules, rules.length - 1);
175-
176+
176177
return selectors.join(',\n');
177178
}
178179

179180
/**
180181
* Return indent.
181182
*/
182-
183+
183184
function indent() {
184185
return Array(indents + 1).join(' ');
185186
}
@@ -209,4 +210,4 @@ function hasProperties(block) {
209210

210211
function blank(str) {
211212
return '' != str;
212-
}
213+
}

test/cases/fontface.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
@font-face
3+
font-family: 'icons'
4+
src: url("/icons/font/icons.eot")
5+
src: url("/icons/font/icons.eot?#iefix") format('embedded-opentype'), url("/icons/font/icons.woff") format('woff'), url("/icons/font/icons.ttf") format('truetype'), url("/icons/font/icons.svg#icons") format('svg')
6+
font-weight: normal
7+
font-style: normal

test/cases/fontface.out.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@font-face {
2+
font-family: 'icons';
3+
src: url("/icons/font/icons.eot");
4+
src: url("/icons/font/icons.eot?#iefix") format('embedded-opentype'), url("/icons/font/icons.woff") format('woff'), url("/icons/font/icons.ttf") format('truetype'), url("/icons/font/icons.svg#icons") format('svg');
5+
font-weight: normal;
6+
font-style: normal;
7+
}

test/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ describe('should support', function(){
1111
var base = path.basename(file, '.css');
1212
var input = read('test/cases/' + file, 'utf8');
1313
var output = read('test/cases/' + base + '.out.css', 'utf8');
14-
14+
1515
it(base, function(){
16-
var out = compile(input);
17-
out.should.equal(output);
16+
var out = compile(input).trim();
17+
out.should.equal(output.trim());
1818
})
19-
});
20-
})
19+
});
20+
})

0 commit comments

Comments
 (0)