Ejemplo n.º 1
0
        /// <summary>
        /// Gets the jade template.
        /// </summary>
        /// <returns>A new jade template.</returns>
        public ITemplate Parse(string jade)
        {
            jade.CheckNull("jade");

            var lexer         = new JadeLexer(jade);
            var rawTokens     = new TokenStream(lexer.Tokenize());
            var elementParser = new ElementParser();

            var lines = rawTokens.GetLines();

            DocType docType  = null;
            var     elements = new List <JElement>();

            if (!lines.IsAtEnd())
            {
                var firstLine = lines.Current;
                if (firstLine.Is(JadeTokenType.Doctype))
                {
                    firstLine.Consume();
                    firstLine.GetAny(TokenType.WhiteSpace);
                    docType = new DocType(firstLine.GetAny(TokenType.Word));
                    lines.Consume();
                }

                while (!lines.IsAtEnd())
                {
                    elementParser.ParseNextElement(lines).Do(elements.Add);
                }
            }

            return(new Template(docType, elements));
        }
Ejemplo n.º 2
0
        public void ShouldNormalizeSourceWhenConstructingAJadeLexer()
        {
            var jadeLexerUnnomalized = new JadeLexer("A \r\n unnormalized \r\n string");
            var tokensUnnormalized   = jadeLexerUnnomalized.Tokenize().ToArray();
            var jadeLexerNomalized   = new JadeLexer("A \n unnormalized \n string");
            var tokensNormalized     = jadeLexerNomalized.Tokenize().ToArray();

            CollectionAssert.AreEqual(tokensNormalized, tokensUnnormalized);
        }