public override string ToCSS(Env env) { if (Variable) return ""; return Name + ": " + Value.ToCSS(env) + ";"; }
public override string ToCSS(List<IEnumerable<Selector>> context, Env env) { if (Css) return "@import " + OriginalPath.ToCSS(env) + ";\n"; return ""; }
public override Node Evaluate(Env env) { if (Values.Count == 1) return Values[0].Evaluate(env); return new Value(Values.Select(n => n.Evaluate(env)), Important); }
public override string ToCSS(List<IEnumerable<Selector>> context, Env env) { if (Rules != null) return Name + " {\n " + Rules.Select(r => r.ToCSS(env)).JoinStrings("\n ") + "\n}\n"; return Name + " " + Value.ToCSS(env) + ";\n"; }
public override Node Evaluate(Env env) { if (Value.Count > 1) return new Expression(new NodeList(Value.Select(e => e.Evaluate(env)))); return Value[0].Evaluate(env); }
public string GetUrl(Env env) { if (Value is Quoted) return ((Quoted) Value).Contents; return Value.ToCSS(env); }
public override Node Evaluate(Env env) { foreach (var frame in env.Frames) { NodeList mixins; if ((mixins = frame.Find(Selector, null)).Count == 0) continue; var rules = new NodeList(); foreach (var node in mixins) { if(!(node is Ruleset)) continue; var ruleset = node as Ruleset; if(!ruleset.MatchArguements(Arguments, env)) continue; if (node is Mixin.Definition) { var mixin = node as Mixin.Definition; rules.AddRange(mixin.Evaluate(Arguments, env).Rules); } else { if (ruleset.Rules != null) rules.AddRange(ruleset.Rules); } // todo fix for other Ruleset types? } return rules; } throw new ParsingException(Selector.ToCSS().Trim() + " is undefined"); }
public override string ToCSS(Env env) { if (!string.IsNullOrEmpty(_css)) return _css; return _css = Elements.Select(e => e.ToCSS(env)).JoinStrings(""); }
public override string ToCSS(Env env) { var evaled = Value .Select(e => e is IEvaluatable ? e.Evaluate(env) : e) .Select(e => e.ToCSS(env)); return evaled.JoinStrings(" "); }
public Ruleset Evaluate(NodeList<Expression> args, Env env) { if(args) Guard.ExpectMaxArguments(Params.Count, args.Count, string.Format("'{0}'", Name)); var frame = new Ruleset(null, new List<Node>()); for (var i = 0; i < Params.Count; i++) { if (!string.IsNullOrEmpty(Params[i].Name)) { Node val; if (args && i < args.Count) val = args[i]; else val = Params[i].Value; if (val) frame.Rules.Add(new Rule(Params[i].Name, val)); else throw new ParsingException("wrong number of arguments for " + Name); } } var frames = new[] {this, frame}.Concat(env.Frames).Reverse(); var context = new Env{ Frames = new Stack<Ruleset>(frames) }; var newRules = new List<Node>(); foreach (var rule in Rules) { if (rule is Mixin.Definition) { var mixin = rule as Mixin.Definition; var parameters = mixin.Params.Concat(frame.Rules.Cast<Rule>()); newRules.Add(new Mixin.Definition(mixin.Name, new NodeList<Rule>(parameters), mixin.Rules)); } else if (rule is Ruleset) { var ruleset = (rule as Ruleset); var rules = ruleset.Rules .Select(r => r.Evaluate(context)) .ToList(); newRules.Add(new Ruleset(ruleset.Selectors, rules)); } else if (rule is Mixin.Call) { newRules.AddRange((NodeList)rule.Evaluate(context)); } else { newRules.Add(rule.Evaluate(context)); } } return new Ruleset(null, newRules); }
public override Node Evaluate(Env env) { if (Css) return new NodeList(this); NodeHelper.ExpandNodes<Import>(env, InnerRoot); return new NodeList(InnerRoot.Rules); }
public override Node Evaluate(Env env) { if(Rules != null) Rules = new List<Node>(Rules.Select(r => r.Evaluate(env))); else Value = Value.Evaluate(env); return this; }
public override Node Evaluate(Env env) { var variable = env.Frames.SelectFirst(frame => frame.Variable(Name)); if (variable) return variable.Value.Evaluate(env); throw new ParsingException("variable " + Name + " is undefined"); }
public override Node Evaluate(Env env) { if (Css) return new NodeList(new TextNode("@import " + OriginalPath.ToCSS() + ";\n")); NodeHelper.ExpandNodes<Import>(env, InnerRoot); return new NodeList(InnerRoot.Rules); }
public override string ToCSS(Env env) { switch (Value) { case "": return ""; case " ": return " "; case "&": return ""; case ":": return " :"; case "::": return "::"; case "+": return " + "; case "~": return " ~ "; case ">": return " > "; } return ""; }
public override Node Evaluate(Env env) { if(Root) { env = env ?? new Env(); NodeHelper.ExpandNodes<Import>(env, this); } env.Frames.Push(this); NodeHelper.ExpandNodes<Mixin.Call>(env, this); for (var i = 0; i < Rules.Count; i++) { Rules[i] = Rules[i].Evaluate(env); } env.Frames.Pop(); return this; }
public override Node Evaluate(Env env) { var a = First.Evaluate(env); var b = Second.Evaluate(env); if (a is Number && b is Color) { if (Operator == "*" || Operator == "+") { var temp = b; b = a; a = temp; } else throw new InvalidOperationException("Can't substract or divide a color from a number"); } var operable = a as IOperable; if (operable != null) return operable.Operate(Operator, b); return null; }
public override Node Evaluate(Env env) { if (Evaluated != null) return Evaluated; var args = Arguments.Select(a => a.Evaluate(env)); if (env != null) { var function = env.GetFunction(Name); if (function != null) { function.Name = Name; Evaluated = function.Call(args); return Evaluated; } } Evaluated = new TextNode(Name + "(" + Arguments.Select(a => a.Evaluate(env).ToCSS()).JoinStrings(", ") + ")"); return Evaluated; }
public override string ToCSS(Env env) { return Combinator.ToCSS(env) + Value; }
public override Node Evaluate(Env env) { return (Node) Color.GetColorFromKeyword(Value) ?? this; }
public override string ToCSS(Env env) { var rgb = RGB .Select(d => (int) Math.Round(d, MidpointRounding.AwayFromZero)) .Select(i => i > 255 ? 255 : (i < 0 ? 0 : i)) .ToArray(); if (Alpha < 1.0) return string.Format("rgba({0}, {1}, {2}, {3})", rgb[0], rgb[1], rgb[2], Alpha); var keyword = GetKeyword(rgb); if (!string.IsNullOrEmpty(keyword)) return keyword; return '#' + rgb .Select(i => i.ToString("X2")) .JoinStrings("") .ToLowerInvariant(); }
public override string ToCSS(Env env) { return Evaluate(env).ToCSS(env); }
public override string ToCSS(Env env) { return "url(" + Value.ToCSS(env) + ")"; }
public override Node Evaluate(Env env) { Value = Value.Evaluate(env); return this; }
public override bool MatchArguements(NodeList<Expression> arguements, Env env) { var argsLength = arguements != null ? arguements.Count : 0; if (argsLength < _required || argsLength > _arity) return false; for (var i = 0; i < argsLength; i++) { if (string.IsNullOrEmpty(Params[i].Name)) { if (arguements[i].Evaluate(env).ToCSS() != Params[i].Value.Evaluate(env).ToCSS()) { return false; } } } return true; }
public override Node Evaluate(Env env) { return this; }
public override string ToCSS(Env env) { return string.Format("alpha(opacity={0})", Value.ToCSS(env)); }
public override string ToCSS(List<IEnumerable<Selector>> list, Env env) { return ""; }
public override string ToCSS(Env env) { return Value; }
public override Node Evaluate(Env env) { return new Rule(Name, Value.Evaluate(env)); }