public override void Write(TemplateRewriterContext context)
        {
            if (IsElseIf)
            {
                context.Write("else ");
            }
            context.Write("if").ExpectSpace();
            if (InvertCondition)
            {
                context.Write("!(");
            }
            context.Write(Condition);
            if (InvertCondition)
            {
                context.Write(")");
            }
            context.ExpectEos();

            context.Write(Then);

            context.Write(Else);

            if (!IsElseIf)
            {
                context.ExpectEnd();
            }
        }
Esempio n. 2
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("case").ExpectSpace();
     context.Write(Value).ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
Esempio n. 3
0
 public override void Write(TemplateRewriterContext context)
 {
     foreach (var scriptStatement in Statements)
     {
         context.Write(scriptStatement);
     }
 }
        public override void Write(TemplateRewriterContext context)
        {
            if (Text == null)
            {
                return;
            }

            if (EscapeCount > 0)
            {
                context.WriteEnterCode(EscapeCount);
            }

            // TODO: handle escape
            var length = Span.End.Offset - Span.Start.Offset + 1;

            if (length > 0)
            {
                context.Write(Text.Substring(Span.Start.Offset, length));
            }

            if (EscapeCount > 0)
            {
                context.WriteExitCode(EscapeCount);
            }
        }
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("when").ExpectSpace();
     context.WriteListWithCommas(Values);
     context.ExpectEos();
     context.Write(Body);
     context.Write(Next);
 }
Esempio n. 6
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("wrap").ExpectSpace();
     context.Write(Target);
     context.ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
Esempio n. 7
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("with").ExpectSpace();
     context.Write(Name);
     context.ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
Esempio n. 8
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("while").ExpectSpace();
     context.Write(Condition);
     context.ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
Esempio n. 9
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write(Target);
     foreach (var scriptExpression in Arguments)
     {
         context.ExpectSpace();
         context.Write(scriptExpression);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Converts back this template to a textual representation. This is the inverse of <see cref="Parse"/>.
        /// </summary>
        /// <param name="options">The rendering options</param>
        /// <returns>The template converted back to a textual representation of the template</returns>
        public string ToText(TemplateRewriterOptions options = default(TemplateRewriterOptions))
        {
            CheckErrors();
            var writer        = new TextWriterOutput();
            var renderContext = new TemplateRewriterContext(writer, options);

            renderContext.Write(Page);

            return(writer.ToString());
        }
Esempio n. 11
0
 public override void Write(TemplateRewriterContext context)
 {
     if (Name != null)
     {
         context.Write("func").ExpectSpace();
         context.Write(Name);
     }
     context.ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("tablerow").ExpectSpace();
     context.Write(Variable).ExpectSpace();
     context.Write("in").ExpectSpace();
     context.Write(Iterator);
     context.Write(NamedArguments);
     context.ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
Esempio n. 13
0
 public override void Write(TemplateRewriterContext context)
 {
     if (context.IsInWhileLoop)
     {
         // TODO: Not efficient
         context.Write(ToString().Replace("for", "while"));
     }
     else
     {
         base.Write(context);
     }
 }
Esempio n. 14
0
 public static void Write(this TemplateRewriterContext context, List <ScriptNamedArgument> parameters)
 {
     if (parameters == null)
     {
         return;
     }
     for (var i = 0; i < parameters.Count; i++)
     {
         var option = parameters[i];
         context.ExpectSpace();
         context.Write(option);
     }
 }
Esempio n. 15
0
        public override void Write(TemplateRewriterContext context)
        {
            if (Name == null)
            {
                return;
            }
            context.Write(Name);

            if (Value != null)
            {
                context.Write(":");
                context.Write(Value);
            }
        }
Esempio n. 16
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("for").ExpectSpace();
     context.Write(Variable).ExpectSpace();
     if (!context.PreviousHasSpace)
     {
         context.Write(" ");
     }
     context.Write("in").ExpectSpace();
     context.Write(Iterator);
     context.Write(NamedArguments);
     context.ExpectEos();
     context.Write(Body);
     context.ExpectEnd();
 }
Esempio n. 17
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write(Left);
     // Because a-b is a variable name, we need to transform binary op a-b to a - b
     if (Operator == ScriptBinaryOperator.Substract && !context.PreviousHasSpace)
     {
         context.Write(" ");
     }
     context.Write(Operator.ToText());
     if (Operator == ScriptBinaryOperator.Substract)
     {
         context.ExpectSpace();
     }
     context.Write(Right);
 }
Esempio n. 18
0
        public override void Write(TemplateRewriterContext context)
        {
            context.Write(Target);
            var isSpecialArgumentsArray = Equals(Target, ScriptVariable.Arguments) && Index is ScriptLiteral &&
                                          ((ScriptLiteral)Index).IsPositiveInteger();

            if (!isSpecialArgumentsArray)
            {
                context.Write("[");
            }
            context.Write(Index);
            if (!isSpecialArgumentsArray)
            {
                context.Write("]");
            }
        }
        public override void Write(TemplateRewriterContext context)
        {
            context.Write("{");
            bool isAfterFirst = false;

            foreach (var member in Members)
            {
                if (isAfterFirst)
                {
                    context.Write(",");
                }

                context.Write(member.Key);
                context.Write(":");
                context.Write(member.Value);

                // If the value didn't have any Comma Trivia, we can emit it
                isAfterFirst = !member.Value.HasTrivia(ScriptTriviaType.Comma, false);
            }
            context.Write("}");
        }
Esempio n. 20
0
        public void Write(TemplateRewriterContext context)
        {
            var rawText = ToString();

            bool isRawComment = Type == ScriptTriviaType.CommentMulti && !rawText.StartsWith("##");

            if (isRawComment)
            {
                // Escape any # by \#
                rawText = rawText.Replace("#", "\\#");
                // Escape any }}
                rawText = rawText.Replace("}", "\\}");
                context.Write("## ");
            }

            context.Write(rawText);

            if (isRawComment)
            {
                context.Write(" ##");
            }
        }
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("continue").ExpectEos();
 }
Esempio n. 22
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("do").ExpectSpace();
     context.Write(Function);
 }
Esempio n. 23
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write(Body);
 }
Esempio n. 24
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write(Target);
     context.Write(".empty?");
 }
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("import").ExpectSpace();
     context.Write(Expression);
     context.ExpectEos();
 }
Esempio n. 26
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write(ToString());
 }
Esempio n. 27
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("this");
 }
Esempio n. 28
0
 public override void Write(TemplateRewriterContext context)
 {
 }
Esempio n. 29
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("readonly").ExpectSpace();
     context.Write(Variable);
     context.ExpectEos();
 }
Esempio n. 30
0
 public override void Write(TemplateRewriterContext context)
 {
     context.Write("else").ExpectEos();
     context.Write(Body);
     context.Write(Else);
 }