private void RenderIndent(HamlNode node, HamlNodeTextContainer nodeText)
        {
            if (node.IsLeadingWhitespaceTrimmed) return;
            if (node.IsWhitespaceNode() && node.IsTrailingWhitespaceTrimmed) return;

            ClassBuilder.Append(nodeText.Indent);
        }
示例#2
0
        public HamlNodeHtmlAttribute(int lineNumber, string name, string value)
            : base(lineNumber, string.Format("{0}: {1}", name, value))
        {
            _name = name;

            Child = new HamlNodeTextContainer(SourceFileLineNum, GetValue(value)).Children[0];
        }
        public void Walk_IndentedNode_WritesIndent()
        {
            const string indent = "  ";
            var node = new HamlNodeTextContainer(new HamlLine("Content", HamlRuleEnum.PlainText, indent, 0));

            _walker.Walk(node);

            Assert.That(_mockClassBuilder.Build(""), Is.StringStarting(indent));
        }
示例#4
0
        public void GetNextUnresolvedPartial_PartialIsAGrandchildNode_ReturnsPartial()
        {
            var textContainerNode = new HamlNodeTextContainer(0, "Test content");
            var partial = new HamlNodePartial(new HamlLine("", HamlRuleEnum.Partial, "", -1));
            textContainerNode.AddChild(partial);

            var rootNode = new HamlNodeDummy();
            rootNode.AddChild(textContainerNode);

            var result = rootNode.GetNextUnresolvedPartial();
            Assert.That(result, Is.EqualTo(partial));
        }
示例#5
0
        private void ParseValue(int index)
        {
            if (index >= Content.Length) return;

            string value = Content.Substring(index + 1);
            HamlNode childNode = null;
            if (IsQuoted(value))
                childNode = new HamlNodeTextContainer(Metrics.SubSpan(index + 2, value.Length-2),
                    RemoveQuotes(value));
            else
                childNode = new HamlNodeTextVariable(Metrics.SubSpan(index + 1, value.Length),
                    RemoveQuotes(value));

            AddChild(childNode);
        }
示例#6
0
        private HamlNodeHtmlAttribute(int sourceFileLineNo, string nameValuePair)
            : base(sourceFileLineNo, nameValuePair)
        {
            int index = 0;

            _name = ParseName(ref index, nameValuePair, sourceFileLineNo);
            var value = ParseValue(index, nameValuePair);

            if (value.StartsWith("\"") || value.StartsWith("\'"))
            {
                Child = new HamlNodeTextContainer(sourceFileLineNo, value).Children[0];
            }
            else
            {
                Child = new HamlNodeEval(sourceFileLineNo, value);
            }
        }
        public void Walk_InvalidNodeType_ThrowsInvalidCastException()
        {
            var node = new HamlNodeTextContainer(new HamlSourceFileMetrics(0, 0, 0, 0), "");

            Assert.Throws<InvalidCastException>(() => _walker.Walk(node));
        }
 public void IsWhitespace_ReturnsCorrectResult(string whiteSpace, bool expectedResult)
 {
     var node = new HamlNodeTextContainer(new HamlLine(whiteSpace, HamlRuleEnum.PlainText, indent: ""));
     Assert.That(node.IsWhitespace(), Is.EqualTo(expectedResult));
 }
 public void Children_MultipleFragments_ChildrenAreOfCorrectType(string line, Type node1Type, Type node2Type)
 {
     var node = new HamlNodeTextContainer(new HamlSourceFileMetrics(0, 0, 0, 0), line);
     Assert.That(node.Children.First(), Is.InstanceOf(node1Type));
     Assert.That(new List<HamlNode>(node.Children)[1], Is.InstanceOf(node2Type));
 }
 public void Children_FirstChildIsOfCorrectType(string line, Type expectedType)
 {
     var node = new HamlNodeTextContainer(new HamlSourceFileMetrics(0, 0, 0, 0), line);
     Assert.That(node.Children.First(), Is.InstanceOf(expectedType));
     Assert.That(node.Children.Count(), Is.EqualTo(1));
 }
 public void Children_EscapedContent_RemovesEscapeCharacter()
 {
     var node = new HamlNodeTextContainer(new HamlLine("\\#{variable}", HamlRuleEnum.PlainText, indent: ""));
     Assert.That(node.Children.First().Content, Is.EqualTo("#{variable}"));
 }
 public void Children_EmptyString_NoChildren()
 {
     var node = new HamlNodeTextContainer(new HamlLine("", HamlRuleEnum.PlainText, indent: ""));
     Assert.That(node.Children.Count(), Is.EqualTo(0));
 }