merge node->tree changes

This commit is contained in:
cloudhead 2010-03-01 19:47:32 -05:00
parent 29f3d926f7
commit f70f6a542c
7 changed files with 66 additions and 30 deletions

View File

@ -4,3 +4,8 @@ tree.Call = function Call(name, args) {
this.name = name;
this.args = args;
};
tree.Call.prototype = {
toCSS: function (context, env) {
return that.functions[this.name].apply(functions, this.args).toCSS();
}
};

View File

@ -19,7 +19,9 @@ tree.Color.prototype = {
eval: function () { return this },
toCSS: function () {
return '#' + this.value.map(function (i) {
return Math.round(i).toString(16);
i = Math.round(i);
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
return i.length === 1 ? '0' + i : i;
}).join('');
},
operate: function (op, other) {

View File

@ -13,12 +13,12 @@ tree.Combinator = function Combinator(value) {
};
tree.Combinator.prototype.toCSS = function () {
switch (this.value) {
case '&': return "";
case ':': return ' :';
case '&' : return '';
case ':' : return ' :';
case '::': return '::';
case '+': return ' + ';
case '~': return ' ~ ';
case '>': return ' > ';
default: return ' ' + this.value;
case '+' : return ' + ';
case '~' : return ' ~ ';
case '>' : return ' > ';
default : return ' ' + this.value;
}
};

View File

@ -10,12 +10,15 @@ tree.Ruleset.prototype = {
if (r instanceof tree.Rule && r.variable === true) { return r }
});
},
//
// Entry point for code generation
//
toCSS: function (context, env) {
var css = [],
rules = [],
rulesets = [],
paths = [],
selector;
var css = [], // The CSS output
rules = [], // node.Rule instances
rulesets = [], // node.Ruleset instances
paths = [], // Current selectors
selector; // The fully rendered selector
if (! this.root) {
if (context.length === 0) {
@ -43,7 +46,10 @@ tree.Ruleset.prototype = {
}
rulesets = rulesets.join('');
// If this is the root node, we don't render
// a selector, or {}.
// Otherwise, only output if this ruleset has rules.
if (this.root) {
css.push(rules.join('\n'));
} else {
@ -55,8 +61,9 @@ tree.Ruleset.prototype = {
}
}
css.push(rulesets);
env.frames.shift();
// Pop the stack
env.frames.shift();
for (var p = 0; p < paths.length; p++) { paths[p].pop() }
return css.join('');

View File

@ -269,14 +269,16 @@ less.parser = {
},
mixin: {
call: function mixinCall() {
var prefix, mixin;
var prefix, mixin, mixins = [];
if (input[i] !== '.') return;
i++;
mixin = $(this.entities.call);
if (mixin && $(';')) {
return ['MIXIN-CALL', mixin];
while ($('.') && (mixin = $(this.entities.call))) {
mixins.push(mixin);
if (! $(',')) break;
}
if (mixins.length > 0 && ($(';') || peek(/\}/g))) {
return new(tree.mixin.Call)(mixins);
}
},
definition: function mixinDefinition(root) {

View File

@ -4,7 +4,7 @@ var tree = exports;
['color', 'directive', 'operation', 'dimension',
'keyword', 'variable', 'ruleset', 'element',
'selector', 'quoted', 'expression', 'rule',
'call', 'url', 'alpha'
'call', 'url', 'alpha', 'mixin'
].forEach(function (n) {
process.mixin(tree, require(path.join('less', 'node', n)));
});

View File

@ -1,13 +1,33 @@
#yelow #short { color: #ffeeaa; }
#yelow #long { color: #ffeeaa; }
#yelow #rgba { color: rgba(255, 238, 170, 0.1); }
#blue #short { color: #0000ff; }
#blue #long { color: #0000ff; }
#blue #rgba { color: rgba(0, 0, 255, 0.1); }
#overflow .a { color: #000000; }
#overflow .b { color: #ffffff; }
#overflow .c { color: #ffffff; }
#overflow .d { color: #00ff00; }
#yelow #short {
color: #fea;
}
#yelow #long {
color: #ffeeaa;
}
#yelow #rgba {
color: rgba(255, 238, 170, 0.1);
}
#blue #short {
color: #00f;
}
#blue #long {
color: #0000ff;
}
#blue #rgba {
color: rgba(0, 0, 255, 0.1);
}
#overflow .a {
color: #000000;
}
#overflow .b {
color: #ffffff;
}
#overflow .c {
color: #ffffff;
}
#overflow .d {
color: #00ff00;
}
#grey {
color: #c8c8c8;
background-color: #323232;