예제 #1
0
        public void Constructor_HtmlStyleAttribute_GeneratesHtmlAttributeCollectionTag()
        {
            const string templateLine = "p(a='b')";
            var tag = new HamlNodeTag(new HamlLine(templateLine));

            Assert.That(tag.Children[0], Is.InstanceOf<HamlNodeHtmlAttributeCollection>());
        }
예제 #2
0
        public void Constructor_HtmlStyleAttribute_AttributeCollectionContainsCorrectContent(
            string hamlLine, string expectedAttributeContent, int expectedaAttrCount)
        {
            var tag = new HamlNodeTag(new HamlLine(hamlLine));

            Assert.That(tag.Children[0].Content, Is.EqualTo(expectedAttributeContent));
            Assert.That(tag.Children.Count, Is.EqualTo(expectedaAttrCount));
        }
예제 #3
0
        public void Constructor_InlineContent_GeneratesCorrectChildTag()
        {
            const string templateLine = "p Hello world";
            var tag = new HamlNodeTag(new HamlLine(templateLine));

            Assert.That(tag.Children[0], Is.InstanceOf<HamlNodeText>());
            const string expectedText = "Hello world";
            Assert.That(((HamlNodeText)tag.Children[0]).Content, Is.EqualTo(expectedText));
        }
예제 #4
0
        public void Constructor_HtmlStyleAttributeWithContent_GeneratesCorrectChildren()
        {
            const string hamlLine = "p(a='b')Content";
            var tag = new HamlNodeTag(new HamlLine(hamlLine));

            const string expectedAttrContent = "(a='b')";
            Assert.That(tag.Children[0].Content, Is.EqualTo(expectedAttrContent));
            const string expectedStringContent = "Content";
            Assert.That(tag.Children[1].Content, Is.EqualTo(expectedStringContent));
        }
예제 #5
0
        public void Walk_AutoSelfClosingTag_AppendsCorrectTag(HtmlVersion htmlVersion, string expectedFormat)
        {
            // Arrange
            var tagNode = new HamlNodeTag(new HamlLine("br"));

            // Act
            _hamlOptions.HtmlVersion = htmlVersion;
            _tagWalker.Walk(tagNode);

            // Assert
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedFormat));
        }
예제 #6
0
        public void Walk_ClassHtmlAttribute_WritesCorrectIdAttribute()
        {
            // Arrange
            var tagNode = new HamlNodeTag(new HamlLine("p"))
                              {
                                  new HamlNodeHtmlAttributeCollection("(class='class')")
                              };

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            const string expectedIdAttr = @"class='class'";
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedIdAttr));
        }
예제 #7
0
        private string MakeClassAttribute(HamlNodeTag nodeTag)
        {
            var classes = (from collection in nodeTag.Children
                           from attr in collection.Children.OfType<HamlNodeHtmlAttribute>()
                           where ((HamlNodeHtmlAttribute)attr).Name == "class"
                           select ((HamlNodeHtmlAttribute)attr).ValueWithoutQuotes).ToList();

            var classNodes = nodeTag.Children.OfType<HamlNodeTagClass>()
                .Select(x => x.Content).ToList();

            classes.AddRange(classNodes);

            return (classNodes.Any())
                ? string.Format(" class='{0}'", string.Join(" ", classes.ToArray()))
                : "";
        }
예제 #8
0
        public void Walk_ClassFollowedByIdNodes_OrderedCorrectly()
        {
            // Arrange
            const string tagId = "id";
            const string tagClass = "class";
            var tagNode = new HamlNodeTag(new HamlLine("p"))
                              {
                                  new HamlNodeTagClass(tagClass),
                                  new HamlNodeTagId(tagId)
                              };

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            const string expectedTag = @"<p class='class' id='id'></p>";
            Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedTag));
        }
예제 #9
0
 private void AppendTagBodyAndClose(HamlNodeTag nodeTag)
 {
     if (nodeTag.IsSelfClosing || _options.IsAutoClosingTag(nodeTag.TagName))
         _classBuilder.Append(_options.HtmlVersion == HtmlVersion.XHtml ?
             " />"
             : ">");
     else
     {
         _classBuilder.Append(">");
         base.Walk(nodeTag);
         if (nodeTag.IsMultiLine)
         {
             _classBuilder.AppendNewLine();
             _classBuilder.AppendFormat(nodeTag.Indent + "</{0}>", nodeTag.NamespaceQualifiedTagName);
         }
         else
         {
             _classBuilder.AppendFormat("</{0}>", nodeTag.NamespaceQualifiedTagName);
         }
     }
 }
예제 #10
0
        public void Walk_MultipleIdNodes_WritesCorrectIdAttribute()
        {
            // Arrange
            var tagNode = new HamlNodeTag(new HamlLine("p"))
                              {
                                  new HamlNodeTagId("id1"),
                                  new HamlNodeTagId("id2")
                              };

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            const string expectedIdAttr = @"id='id2'";
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedIdAttr));
        }
예제 #11
0
        public void Walk_MultipleClassNodes_WritesCorrectClassAttribute()
        {
            // Arrange
            var tagNode = new HamlNodeTag(new HamlLine("p"))
                              {
                                  new HamlNodeTagClass("class1"),
                                  new HamlNodeTagClass("class2")
                              };

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            const string expectedClassAttr = @"class='class1 class2'";
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedClassAttr));
        }
예제 #12
0
        public void Walk_IndentedTag_AppendsIndent()
        {
            // Arrange
            const string indent = "  ";
            var tagNode = new HamlNodeTag(new HamlLine(indent + "p"));

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            Assert.That(_classBuilderMock.Build(""), Is.StringStarting(indent));
        }
예제 #13
0
        public void Walk_IdNoteAndIdHtmlAttribute_WritesCorrectIdAttribute()
        {
            // Arrange
            var tagNode = new HamlNodeTag(new HamlLine("p"))
                              {
                                  new HamlNodeTagId("id1"),
                                  new HamlNodeHtmlAttributeCollection("(id='id2')")
                              };

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            const string expectedIdAttr = "id='id1_id2'";
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedIdAttr));
        }
예제 #14
0
        public void Constructor_SimpleTags_GeneratesCorrectIdChildNodes(string templateLine, string expectedFirstTagId, int expectedCount)
        {
            var tag = new HamlNodeTag(new HamlLine(templateLine));

            var idTags = tag.Children.OfType<HamlNodeTagId>();

            Assert.That(idTags.Count(), Is.EqualTo(expectedCount));
            string att = idTags.FirstOrDefault() != null ? idTags.First().Content : "";
            Assert.That(att, Is.EqualTo(expectedFirstTagId));
        }
예제 #15
0
        public void Walk_SelfClosingTag_AppendsCorrectTag()
        {
            // Arrange
            const string tagName = "foo/";
            var tagNode = new HamlNodeTag(new HamlLine(tagName));

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            const string expectedTag = "<foo />";
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedTag));
        }
예제 #16
0
 private void WalkHtmlStyleAttributes(HamlNodeTag nodeTag)
 {
     var attributeTags = nodeTag.Children.Where(x => x.GetType() == typeof(HamlNodeHtmlAttributeCollection));
     foreach (var child in attributeTags)
     {
         new HamlNodeHtmlAttributeCollectionWalker(_classBuilder, _options)
             .Walk(child);
     }
 }
예제 #17
0
 private void AppendTagStart(HamlNodeTag nodeTag)
 {
     _classBuilder.Append(nodeTag.Indent);
     _classBuilder.Append("<" + nodeTag.NamespaceQualifiedTagName);
 }
예제 #18
0
 public void Constructor_TagWithNamespace_DeterminesTagAndNamespaceCorrectly(string templateLine,
     string expectedNamespace, string expectedTag)
 {
     var tag = new HamlNodeTag(new HamlLine(templateLine));
     Assert.That(tag.Namespace, Is.EqualTo(expectedNamespace));
     Assert.That(tag.TagName, Is.EqualTo(expectedTag));
 }
예제 #19
0
 public void Constructor_SimpleTags_GeneratesCorrectTagName(string templateLine, string expectedTagName)
 {
     var tag = new HamlNodeTag(new HamlLine(templateLine));
     Assert.That(tag.TagName, Is.EqualTo(expectedTagName));
 }
예제 #20
0
        public void Walk_NestedTags_AppendsCorrectTags()
        {
            // Arrange
            const string tagName = "p";
            const string nestedText = "Hello world";
            var tagNode = new HamlNodeTag(new HamlLine(tagName))
                              {
                                  new HamlNodeText(new HamlLine(nestedText))
                              };
            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            string expectedTag = string.Format("<{0}>{1}</{0}>", tagName, nestedText);
            Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedTag));
        }
예제 #21
0
 public void Constructor_SimpleTags_DeterminesSelfClosingCorrectly(string templateLine, bool expectedSelfClosing)
 {
     var tag = new HamlNodeTag(new HamlLine(templateLine));
     Assert.That(tag.IsSelfClosing, Is.EqualTo(expectedSelfClosing));
 }
예제 #22
0
        public void Walk_NonSelfClosingTags_AppendsCorrectTag(string templateLine, string expectedOutput)
        {
            // Arrange
            var tagNode = new HamlNodeTag(new HamlLine(templateLine));

            // Act
            _tagWalker.Walk(tagNode);

            // Assert
            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedOutput));
        }
예제 #23
0
        public void Constructor_SimpleTags_GeneratesCorrectClassChildNodes(string templateLine, string expectedFirstClass, int expectedCount)
        {
            var tag = new HamlNodeTag(new HamlLine(templateLine));

            var classChildren = tag.Children.OfType<HamlNodeTagClass>();

            Assert.That(classChildren.Count(), Is.EqualTo(expectedCount));
            string att = classChildren.FirstOrDefault() != null ? classChildren.First().Content : "";
            Assert.That(att, Is.EqualTo(expectedFirstClass));
        }
예제 #24
0
 private void AppendAttributes(HamlNodeTag nodeTag)
 {
     _classBuilder.Append(MakeClassAttribute(nodeTag));
     _classBuilder.Append(MakeIdAttribute(nodeTag));
     WalkHtmlStyleAttributes(nodeTag);
 }
예제 #25
0
        public void Walk_EmptyAttributeCollectionNode_WritesCorrectAttributes(string tag, string attributes, string expectedOutput)
        {
            var tagNode = new HamlNodeTag(new HamlLine(tag))
            {
                new HamlNodeHtmlAttributeCollection(attributes)
            };

            _tagWalker.Walk(tagNode);

            Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedOutput));
        }
예제 #26
0
        private void RenderStandardTag(HamlNodeTag nodeTag, string attributesMarkup)
        {
            _classBuilder.AppendFormat("<{0}{1}>", nodeTag.NamespaceQualifiedTagName, attributesMarkup);
            base.Walk(nodeTag);

            if (nodeTag.IsMultiLine)
            {
                _classBuilder.AppendNewLine();
                _classBuilder.AppendFormat(nodeTag.Indent + "</{0}>", nodeTag.NamespaceQualifiedTagName);
            }
            else
            {
                _classBuilder.AppendFormat("</{0}>", nodeTag.NamespaceQualifiedTagName);
            }
        }
예제 #27
0
        private string MakeIdAttribute(HamlNodeTag nodeTag)
        {
            var idAttributes = (from collection in nodeTag.Children
                                from attr in collection.Children.OfType<HamlNodeHtmlAttribute>()
                                where ((HamlNodeHtmlAttribute)attr).Name == "id"
                                select ((HamlNodeHtmlAttribute)attr).ValueWithoutQuotes).ToList();

            var idTag = nodeTag.Children.LastOrDefault(x => x.GetType() == typeof(HamlNodeTagId));
            if (idTag != null) idAttributes.Insert(0, idTag.Content);

            return idAttributes.Any() ? " id='" + string.Join("_", idAttributes.ToArray()) + "'" : "";
        }