public override CssValue Evaluate(ScssEnvironment env) { var l = Left.Evaluate(env); var r = Right.Evaluate(env); if (l.Type == CssValueType.Number) { var t = l; l = r; r = t; } if (r.Type == CssValueType.Number) { switch (l.Type) { case CssValueType.Number: case CssValueType.Percentage: case CssValueType.Pixel: case CssValueType.Em: case CssValueType.Rem: case CssValueType.ViewportWidth: case CssValueType.ViewportHeight: case CssValueType.Inch: case CssValueType.Centimeter: return new CssValue { Type = l.Type, Number = l.Number * r.Number }; } } throw new Exception("unit mismatch"); }
public override CssValue Evaluate(ScssEnvironment env) { return new CssValue { Color = Color, Type = CssValueType.Color }; }
public override CssValue Evaluate(ScssEnvironment env) { return new CssValue { Number = Value, Type = CssValueType.Number }; }
public override CssValue Evaluate(ScssEnvironment env) { return new CssValue { Type = CssValueType.String, String = Value }; }
public void ParserTest() { var parser = new ScssParser(); var doc = parser.Parse("p { width: 20px; }"); var env = new ScssEnvironment(); doc.Compile(env); Assert.AreEqual("p{width:20px;}", env.Document.ToString()); }
public override string Evaluate(ScssEnvironment env) { var sb = new StringBuilder(); foreach (var expr in Expressions) { sb.Append(expr.Evaluate(env)); } return sb.ToString(); }
public override CssValue Evaluate(ScssEnvironment env) { var val = Inner.Evaluate(env); return new CssValue { Number = val.Number, Type = Type }; }
public void NestedRuleParserTest() { var parser = new ScssParser(); var doc = parser.Parse(@" div { p { width: 20px; } span { color: red; &:hover { color: green; &:after { display: none; } span { color: blue; } } } }"); var env = new ScssEnvironment(); doc.Compile(env); AssertExt.AreEqual(new CssDocument { Rules = { new CssQualifiedRule ("div"), new CssQualifiedRule ("div p") { Declarations = { new CssDeclaration("width", "20px") } }, new CssQualifiedRule ("div span") { Declarations = { new CssDeclaration("color", "red") } }, new CssQualifiedRule ("div span:hover") { Declarations = { new CssDeclaration("color", "green"), } }, new CssQualifiedRule ("div span:hover:after") { Declarations = { new CssDeclaration("display", "none") } }, new CssQualifiedRule ("div span:hover span") { Declarations = { new CssDeclaration("color", "blue"), } }, } }, env.Document); }
public override CssValue Evaluate(ScssEnvironment env) { var sb = new StringBuilder(); foreach (var expr in Expressions) { if (sb.Length != 0) sb.Append(' '); sb.Append(expr.Evaluate(env)); } return new CssValue { String = sb.ToString(), Type = CssValueType.String }; }
public override void Compile(ScssEnvironment env) { env.PushRule(Selector); foreach (var node in Rules.Nodes) { node.Compile(env); } env.Document.Rules.Add(env.CssRule); foreach (var subRule in RuleSets.Nodes) { subRule.Compile(env); } env.PopRule(); }
public override CssValue Evaluate(ScssEnvironment env) { var l = Inner.Evaluate(env); switch (l.Type) { case CssValueType.Number: case CssValueType.Percentage: case CssValueType.Pixel: case CssValueType.Em: case CssValueType.Rem: case CssValueType.ViewportWidth: case CssValueType.ViewportHeight: case CssValueType.Inch: return new CssValue { Type = l.Type, Number = -l.Number }; default: throw new Exception("unit mismatch"); } }
public override void Compile(ScssEnvironment env) { foreach (var rule in Rules) { rule.Compile(env); } }
public abstract CssValue Evaluate(ScssEnvironment env);
public abstract void Compile(ScssEnvironment env);
public override void Compile(ScssEnvironment env) { foreach (var node in Nodes) { node.Compile(env); } }
public override void Compile(ScssEnvironment env) { env.CssRule.Declarations.Add(new CssDeclaration { Name = env.FormatProperty(), Value = Value.Evaluate(env).ToString() }); }
public abstract string Evaluate(ScssEnvironment env);
public void SimpleParseTest() { const string input = @" #main p { color: #eeffdd; width: 97%; .redbox { background-color: #ffbca8; color: #bfadef; } }"; var doc = new ScssParser().Parse(input); var env = new ScssEnvironment(); doc.Compile(env); var css = env.Document.ToString(); }
public override string Evaluate(ScssEnvironment env) { return Inner.Evaluate(env); }
public override string Evaluate(ScssEnvironment env) { return Left.Evaluate(env) + "+" + Right.Evaluate(env); }
public override string Evaluate(ScssEnvironment env) { return "." + ClassName; }
public override string Evaluate(ScssEnvironment env) { return $"[{AttributeName}]"; }
public override string Evaluate(ScssEnvironment env) { return "#" + Id; }
public override void Compile(ScssEnvironment env) { //TODO: throw new System.NotImplementedException(); }
public override string Evaluate(ScssEnvironment env) { return TypeName; }
public override string Evaluate(ScssEnvironment env) { return $":not({Inner.Evaluate(env)})"; }
public override void Compile(ScssEnvironment env) { env.PushProperty(Property); Value.Compile(env); env.PopProperty(); }