Example #1
0
 public void AppendPostTagNewLine(HamlNode childNode, int lineNo)
 {
     if (childNode.IsContentGeneratingTag)
     {
         AddChild(new HamlNodeTextContainer(new HamlLine("\n", HamlRuleEnum.PlainText, "", lineNo, false)));
     }
 }
Example #2
0
        private void ParseNode(HamlNode node, HamlFile hamlFile)
        {
            //node.IsMultiLine = true;
            while ((!hamlFile.EndOfFile) && (hamlFile.CurrentLine.IndentCount > node.IndentCount))
            {
                var nodeLine  = hamlFile.CurrentLine;
                var childNode = HamlNodeFactory.GetHamlNode(nodeLine);
                node.AddChild(childNode);

                hamlFile.MoveNext();
                if (hamlFile.EndOfFile == false &&
                    hamlFile.CurrentLine.IndentCount > nodeLine.IndentCount)
                {
                    if (hamlFile.CurrentLine.IsInline == false)
                    {
                        childNode.AppendInnerTagNewLine();
                    }
                    ParseNode(childNode, hamlFile);
                }

                if (hamlFile.EndOfFile == false &&
                    hamlFile.CurrentLine.IndentCount >= nodeLine.IndentCount)
                {
                    node.AppendPostTagNewLine(childNode, hamlFile.CurrentLine.SourceFileLineNo);
                }
            }
        }
        private void RenderIndent(HamlNode node, HamlNodeTextContainer nodeText)
        {
            if (node.IsLeadingWhitespaceTrimmed) return;
            if (node.IsWhitespaceNode() && node.IsTrailingWhitespaceTrimmed) return;

            ClassBuilder.Append(nodeText.Indent);
        }
        public override void Walk(HamlNode node)
        {
            var nodeText = node as HamlNodeTextContainer;
            if (nodeText == null)
                throw new System.InvalidCastException("HamlNodeTextWalker requires that HamlNode object be of type HamlNodeText.");

            RenderIndent(node, nodeText);
            base.Walk(node);
        }
Example #5
0
        public override void Walk(HamlNode node)
        {
            var nodeTag = node as HamlNodeTag;
            if (nodeTag == null)
                throw new InvalidCastException("HamlNodeTagWalker requires that HamlNode object be of type HamlNodeTag.");

            AppendTagStart(nodeTag);
            AppendAttributes(nodeTag);
            AppendTagBodyAndClose(nodeTag);
        }
Example #6
0
        public override void Walk(HamlNode node)
        {
            var nodeEval = node as HamlNodeDocType;
            if (nodeEval == null)
                throw new System.InvalidCastException("HamlNodeDocTypeWalker requires that HamlNode object be of type HamlNodeDocType.");

            ClassBuilder.AppendDocType(node.Content.Trim());

            ValidateThereAreNoChildren(node);
        }
Example #7
0
        public void AddChild(HamlNode hamlNode)
        {
            hamlNode.Parent   = this;
            hamlNode.Previous = _children.LastOrDefault();
            if (hamlNode.Previous != null)
            {
                hamlNode.Previous.Next = hamlNode;
            }

            _children.Add(hamlNode);
        }
        private void MakeAttribute(HamlNode childNode)
        {
            var attributeNode = childNode as HamlNodeHtmlAttribute;
            if (attributeNode == null)
                throw new HamlMalformedTagException("Unexpected " + childNode.GetType().FullName + " tag in AttributeCollection node",
                    childNode.SourceFileLineNum);

            var valueFragments = attributeNode.Children.Any(ch => ch is HamlNodeTextContainer)
                                     ? attributeNode.Children.First().Children
                                     : attributeNode.Children;
            ClassBuilder.AppendAttributeNameValuePair(attributeNode.Name, valueFragments.ToList(), attributeNode.QuoteChar);
        }
        public override void Walk(HamlNode node)
        {
            var nodeText = node as HamlNodeTextLiteral;
            if (nodeText == null)
                throw new System.InvalidCastException("HamlNodeTextLiteralWalker requires that HamlNode object be of type HamlNodeTextLiteral.");

            string outputText = node.Content;
            outputText = HandleLeadingWhitespace(node, outputText);
            outputText = HandleTrailingWhitespace(node, outputText);

            if (outputText.Length > 0)
                ClassBuilder.Append(outputText);
        }
Example #10
0
        public override void Walk(HamlNode node)
        {
            var nodeEval = node as HamlNodeCode;
            if (nodeEval == null)
                throw new System.InvalidCastException("HamlNodeCode requires that HamlNode object be of type HamlNodeCode.");

            ClassBuilder.AppendCodeSnippet(node.Content, node.Children.Any());

            base.Walk(node);

            if (node.Children.Any())
                ClassBuilder.RenderEndBlock();
        }
        public override void Walk(HamlNode node)
        {
            var nodeText = node as HamlNodeTextVariable;
            if (nodeText == null)
                throw new InvalidCastException("HamlNodeTextVariableWalker requires that HamlNode object be of type HamlNodeTextVariable.");

            string variableName = nodeText.VariableName;

            if (nodeText.IsVariableViewDataKey())
                ClassBuilder.AppendVariable(variableName);
            else
                ClassBuilder.AppendCodeToString(variableName);
        }
        public override void Walk(HamlNode node)
        {
            var attributeCollectionNode = node as HamlNodeHtmlAttributeCollection;
            if (attributeCollectionNode == null)
                throw new System.InvalidCastException("HamlNodeHtmlAttributeCollectionWalker requires that HamlNode object be of type HamlNodeHtmlAttributeCollection.");

            foreach (HamlNodeHtmlAttribute childNode in attributeCollectionNode.Children)
            {
                if (childNode.Content.StartsWith("class=")
                    || childNode.Content.StartsWith("id=")) continue;
                MakeAttribute(childNode);
            }
        }
        private static void VerifyTokens(HamlNode node, ref int tokenIndex, IList<TestToken> tokenList)
        {
            foreach (var child in node.Children)
            {
                var token = tokenList[tokenIndex];
                Console.WriteLine("Verifying token " + token.Type + " [" + tokenIndex + "]");
                Assert.That(child.GetType().ToString(), Is.StringContaining(token.Type));
                Assert.That(child.Metrics.LineNo, Is.EqualTo(token.LineIndex));
                Assert.That(child.Metrics.ColNo, Is.EqualTo(token.StartIndex));
                Assert.That(child.Metrics.Length, Is.EqualTo(token.Length));
                Console.WriteLine("Pass token " + tokenIndex);
                tokenIndex++;

                VerifyTokens(child, ref tokenIndex, tokenList);
            }
        }
Example #14
0
        private void ParseNode(HamlNode node, HamlFile hamlFile)
        {
            //node.IsMultiLine = true;
            while ((!hamlFile.EndOfFile) && (hamlFile.CurrentLine.IndentCount > node.IndentCount))
            {
                var nodeLine  = hamlFile.CurrentLine;
                var childNode = HamlNodeFactory.GetHamlNode(nodeLine);
                node.AddChild(childNode);

                hamlFile.MoveNext();
                if (hamlFile.EndOfFile == false &&
                    hamlFile.CurrentLine.IndentCount > nodeLine.IndentCount)
                {
                    ParseNode(childNode, hamlFile);
                }
            }
        }
        public override void Walk(HamlNode node)
        {
            var commentNode = node as HamlNodeHtmlComment;
            if (commentNode == null)
                throw new System.InvalidCastException("HamlNodeHtmlCommentWalker requires that HamlNode object be of type HamlNodeHtmlComment.");

            ClassBuilder.Append(node.Indent);
            ClassBuilder.Append("<!--" + commentNode.Content);

            base.Walk(node);

            if (node.IsMultiLine)
            {
                ClassBuilder.AppendNewLine();
                ClassBuilder.Append(node.Indent + "-->");
            }
            else
            {
                ClassBuilder.Append(" -->");
            }
        }
Example #16
0
        private void ParseNode(HamlNode node, HamlFile hamlFile)
        {
            //node.IsMultiLine = true;
            while ((!hamlFile.EndOfFile) && (hamlFile.CurrentLine.IndentCount > node.IndentCount))
            {
                var nodeLine = hamlFile.CurrentLine;
                var childNode = HamlNodeFactory.GetHamlNode(nodeLine);
                node.AddChild(childNode);

                hamlFile.MoveNext();
                if (hamlFile.EndOfFile == false
                    && hamlFile.CurrentLine.IndentCount > nodeLine.IndentCount)
                {
                    if (hamlFile.CurrentLine.IsInline == false) childNode.AppendInnerTagNewLine();
                    ParseNode(childNode, hamlFile);
                }

                if (hamlFile.EndOfFile == false
                    && hamlFile.CurrentLine.IndentCount >= nodeLine.IndentCount)
                {
                    node.AppendPostTagNewLine(childNode, hamlFile.CurrentLine.Metrics.LineNo);
                }
            }
        }
 private static string HandleTrailingWhitespace(HamlNode node, string outputText)
 {
     if (node.Parent.IsTrailingWhitespaceTrimmed)
         outputText = outputText.TrimEnd(new[] { ' ', '\n', '\r', '\t' });
     return outputText;
 }
Example #18
0
 private void AddClassificationSpans(SnapshotSpan span, List<ClassificationSpan> spans, HamlNode node)
 {
     if (node.Metrics.Length > 0 && node.Metrics.ColNo >= 0)
     {
         var classifiedSpan = new SnapshotSpan(span.Snapshot, span.Start.Position + node.Metrics.ColNo, node.Metrics.Length);
         var type = GetClassificationTypeForMarkdownToken(node.GetType());
         spans.Add(new ClassificationSpan(classifiedSpan, type));
     }
     foreach (var childNode in node.Children)
         AddClassificationSpans(span, spans, childNode);
 }
Example #19
0
        public void AddChild(HamlNode hamlNode)
        {
            hamlNode.Parent = this;
            hamlNode.Previous = _children.LastOrDefault();
            if (hamlNode.Previous != null)
                hamlNode.Previous.Next = hamlNode;

            _children.Add(hamlNode);
        }
Example #20
0
 public void AppendPostTagNewLine(HamlNode childNode, int lineNo)
 {
     if (childNode.IsContentGeneratingTag)
         AddChild(new HamlNodeTextContainer(new HamlLine("\n", HamlRuleEnum.PlainText, "", lineNo, false)));
 }