private Template BuildTmpl(Token current, Queue<Token> remaining) { return new NestedTemplate { Data = new ExpressionParser().Parse(current.Parameters.ElementAtOrDefault(0) ?? "$data"), Options = new ExpressionParser().Parse(current.Parameters.ElementAtOrDefault(1) ?? "$options"), Template = new TemplateReference(current.Expression.Trim('"').Trim('\'')), }; }
private Template BuildEach(Token current, Queue<Token> remaining) { return new EachTemplate { IndexParameter = new Parameter(current.Parameters.ElementAtOrDefault(0) ?? "index"), ValueParameter = new Parameter(current.Parameters.ElementAtOrDefault(1) ?? "value"), Expression = new ExpressionParser().Parse(current.Expression), Content = Compile(remaining), }; }
private Template BuildEval(Token current, Queue<Token> remaining) { return new EvalTemplate { Expression = new ExpressionParser().Parse(current.Expression) }; }
private Template BuildWrap(Token current, Queue<Token> remaining) { return new WrapTemplate { Data = new ExpressionParser().Parse(current.Parameters.ElementAtOrDefault(0)), Options = new ExpressionParser().Parse(current.Parameters.ElementAtOrDefault(1)), Content = Compile(remaining), Template = new TemplateReference(current.Expression.Trim('"').Trim('\'')), }; }
private Template BuildElse(Token current, Queue<Token> remaining) { _index = current.Index + current.Length; return new ElseTemplate { Expression = new ExpressionParser().Parse(current.Expression), Content = Compile(remaining, t => t.Name == "else"), Else = remaining.Count > 0 && remaining.Peek().Name == "else" ? BuildElse(remaining.Dequeue(), remaining) : new LiteralTemplate(), }; }
private Template BuildIf(Token current, Queue<Token> remaining) { var elseFound = false; return new IfTemplate { Expression = new ExpressionParser().Parse(current.Expression), Content = Compile(remaining, t => elseFound = (t.Name == "else")), Else = elseFound && remaining.Count > 0 && remaining.Peek().Name == "else" ? BuildElse(remaining.Dequeue(), remaining) : new LiteralTemplate(), }; }