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>()); }
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)); }
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)); }
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)); }
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)); }
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)); }
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())) : ""; }
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)); }
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); } } }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); } }
private void AppendTagStart(HamlNodeTag nodeTag) { _classBuilder.Append(nodeTag.Indent); _classBuilder.Append("<" + nodeTag.NamespaceQualifiedTagName); }
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)); }
public void Constructor_SimpleTags_GeneratesCorrectTagName(string templateLine, string expectedTagName) { var tag = new HamlNodeTag(new HamlLine(templateLine)); Assert.That(tag.TagName, Is.EqualTo(expectedTagName)); }
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)); }
public void Constructor_SimpleTags_DeterminesSelfClosingCorrectly(string templateLine, bool expectedSelfClosing) { var tag = new HamlNodeTag(new HamlLine(templateLine)); Assert.That(tag.IsSelfClosing, Is.EqualTo(expectedSelfClosing)); }
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)); }
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)); }
private void AppendAttributes(HamlNodeTag nodeTag) { _classBuilder.Append(MakeClassAttribute(nodeTag)); _classBuilder.Append(MakeIdAttribute(nodeTag)); WalkHtmlStyleAttributes(nodeTag); }
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)); }
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); } }
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()) + "'" : ""; }