public void Constructor_HtmlStyleAttribute_GeneratesHtmlAttributeCollectionTag() { const string templateLine = "p(a='b')"; var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); Assert.That(tag.Children.First(), Is.InstanceOf <HamlNodeHtmlAttributeCollection>()); }
public void Constructor_TagWithNamespace_DeterminesTagAndNamespaceCorrectly(string templateLine, string expectedNamespace, string expectedTag) { var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); Assert.That(tag.Namespace, Is.EqualTo(expectedNamespace)); Assert.That(tag.TagName, Is.EqualTo(expectedTag)); }
public void Constructor_HtmlStyleAttribute_AttributeCollectionContainsCorrectContent( string templateLine, string expectedAttributeContent, int expectedaAttrCount) { var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); Assert.That(tag.Children.First().Content, Is.EqualTo(expectedAttributeContent)); Assert.That(tag.Children.Count(), Is.EqualTo(expectedaAttrCount)); }
private void AppendTagStart(HamlNodeTag nodeTag) { if (nodeTag.IsLeadingWhitespaceTrimmed == false) { ClassBuilder.Append(nodeTag.Indent); } ClassBuilder.Append("<" + nodeTag.NamespaceQualifiedTagName); }
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); } }
public void Constructor_InlineContent_GeneratesCorrectChildTag() { const string templateLine = "p Hello world"; var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); Assert.That(tag.Children.First(), Is.InstanceOf <HamlNodeTextContainer>()); const string expectedText = "Hello world"; Assert.That(((HamlNodeTextContainer)tag.Children.First()).Content, Is.EqualTo(expectedText)); }
public void Walk_EmptyAttributeCollectionNode_WritesCorrectAttributes(string tag, string attributes, string expectedOutput) { var tagNode = new HamlNodeTag(new HamlLine(tag, HamlRuleEnum.Tag, "", 0)); tagNode.AddChild(new HamlNodeHtmlAttributeCollection(0, attributes)); _tagWalker.Walk(tagNode); Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedOutput)); }
public void Walk_WhitespaceRemoval_GeneratesCorrectOutput(string line1, string line2, string line3, string expectedOutput) { var tagNode = new HamlNodeTag(new HamlLine(line1, HamlRuleEnum.Tag, "", 0)); tagNode.AddChild(new HamlNodeTag(new HamlLine(line2, HamlRuleEnum.Tag, " ", 0))); _tagWalker.Walk(tagNode); Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedOutput)); }
public void Constructor_SimpleTags_GeneratesCorrectClassChildNodes(string templateLine, string expectedFirstClass, int expectedCount) { var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); 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 static IList <HamlNodeTextContainer> GetClassValues(HamlNodeTag nodeTag) { var classValues = (from collection in nodeTag.Children.OfType <HamlNodeHtmlAttributeCollection>() from attr in collection.Children.OfType <HamlNodeHtmlAttribute>() where attr.Name == "class" from attrFragment in attr.Children select(HamlNodeTextContainer) attrFragment).ToList(); classValues.AddRange(nodeTag.Children.OfType <HamlNodeTagClass>().Select(x => new HamlNodeTextContainer(x.SourceFileLineNum, x.Content))); return(classValues); }
public void Walk_NonSelfClosingTags_AppendsCorrectTag(string templateLine, string expectedOutput) { // Arrange var tagNode = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); // Act _tagWalker.Walk(tagNode); // Assert Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedOutput)); }
private void Walk(HamlNodeTag node) { _templateILStream.Write('<'); _templateILStream.Write(node.NamespaceQualifiedTagName); var attributes = node.Attributes.OrderBy(a => a.Name).GroupBy(a => a.Name); foreach (var attrGroup in attributes) { _templateILStream.Write(" {0}=\"", attrGroup.Key); bool leadingSpace = false; var values = attrGroup.Select(n => n.Child).OfType <HamlNodeTextLiteral>().OrderBy(n => n.Content).Select(n => n.Content); if (values.Any()) { leadingSpace = true; _templateILStream.Write(values.Aggregate((accum, val) => string.Format("{0} {1}", accum, val))); } var thunkValues = attrGroup.Select(n => n.Child).OfType <HamlNodeEval>(); if (thunkValues.Any()) { if (leadingSpace) { _templateILStream.Write(' '); leadingSpace = false; } foreach (var value in thunkValues) { if (leadingSpace) { _templateILStream.Write(' '); } _codeClassBuilder.PrintExpressionResult(value.Content); leadingSpace = true; } } _templateILStream.Write('"'); } if (node.Children.Count > 0) { _templateILStream.Write('>'); this.Walk(node.Children); _templateILStream.Write("</"); _templateILStream.Write(node.NamespaceQualifiedTagName); } else if (!node.IsSelfClosing) { _templateILStream.Write('/'); } _templateILStream.Write('>'); }
public void Walk_InlineContent_GeneratesCorrectOutput() { var tagNode = new HamlNodeTag(new HamlLine("p", HamlRuleEnum.Tag)); tagNode.AddChild(new HamlNodeTextContainer(new HamlLine("Content", HamlRuleEnum.PlainText, "\t", 0, true))); _tagWalker.Walk(tagNode); const string expectedOutput = "<p>Content</p>"; Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedOutput)); }
public void Constructor_HtmlStyleAttributeWithContent_GeneratesCorrectChildren() { const string templateLine = "p(a='b')Content"; var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); const string expectedAttrContent = "(a='b')"; Assert.That(tag.Children.First().Content, Is.EqualTo(expectedAttrContent)); const string expectedStringContent = "Content"; Assert.That(tag.Children.ToList()[1].Content, Is.EqualTo(expectedStringContent)); }
public void Walk_IndentedTag_AppendsIndent() { // Arrange const string indent = " "; var tagNode = new HamlNodeTag(new HamlLine("p", HamlRuleEnum.Tag, indent, 0)); // Act _tagWalker.Walk(tagNode); // Assert Assert.That(_classBuilderMock.Build(""), Is.StringStarting(indent)); }
public void Walk_SelfClosingTag_AppendsCorrectTag() { // Arrange const string tagName = "foo/"; var tagNode = new HamlNodeTag(new HamlLine(tagName, HamlRuleEnum.Tag, "", 0)); // Act _tagWalker.Walk(tagNode); // Assert const string expectedTag = "<foo />"; Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedTag)); }
public void Walk_InternalWhitespaceRemoval_GeneratesCorrectOutput() { var tagNode = new HamlNodeTag(new HamlLine("p<", HamlRuleEnum.Tag, "", 0)); //tagNode.IsMultiLine = true; tagNode.AddChild(new HamlNodeTextContainer(new HamlLine("\n", HamlRuleEnum.PlainText, "", 0))); tagNode.AddChild(new HamlNodeTextContainer(new HamlLine(" Hello", HamlRuleEnum.PlainText, "", 0))); _tagWalker.Walk(tagNode); const string expectedOutput = "<p>Hello</p>"; Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedOutput)); }
public void Walk_ClassHtmlAttribute_WritesCorrectClassAttribute() { // Arrange var tagNode = new HamlNodeTag(new HamlLine("p", HamlRuleEnum.Tag, "", 0)); tagNode.AddChild(new HamlNodeHtmlAttributeCollection(0, "(class='class')")); // Act _tagWalker.Walk(tagNode); // Assert const string expectedIdAttr = @"class='class'"; Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedIdAttr)); }
public void Walk_MultipleIdNodes_WritesCorrectIdAttribute() { // Arrange var tagNode = new HamlNodeTag(new HamlLine("p", HamlRuleEnum.Tag, "", 0)); tagNode.AddChild(new HamlNodeTagId(0, "id1")); tagNode.AddChild(new HamlNodeTagId(0, "id2")); // Act _tagWalker.Walk(tagNode); // Assert const string expectedIdAttr = @"id='id2'"; Assert.That(_classBuilderMock.Build(""), Is.StringContaining(expectedIdAttr)); }
private static IList <HamlNodeTextContainer> GetIdValues(HamlNodeTag nodeTag) { var idValues = (from collection in nodeTag.Children.OfType <HamlNodeHtmlAttributeCollection>() from attr in collection.Children.OfType <HamlNodeHtmlAttribute>() where attr.Name == "id" from attrFragment in attr.Children select(HamlNodeTextContainer) attrFragment).ToList(); var idTag = nodeTag.Children.LastOrDefault(x => x.GetType() == typeof(HamlNodeTagId)); if (idTag != null) { idValues.Insert(0, new HamlNodeTextContainer(idTag.SourceFileLineNum, idTag.Content)); } return(idValues); }
private bool IsPreCloseTagWhitespaceTrimmed(HamlNodeTag nodeTag) { if (nodeTag.IsMultiLine == false || nodeTag.WhitespaceRemoval == WhitespaceRemoval.Internal) { return(true); } var lastNonWhitespaceChild = GetLastNonWhitespaceChild(nodeTag) as HamlNodeTag; if (lastNonWhitespaceChild == null) { return(false); } return((lastNonWhitespaceChild).WhitespaceRemoval == WhitespaceRemoval.Surrounding); }
public void Walk_NestedTags_AppendsCorrectTags() { // Arrange const string tagName = "p"; const string nestedText = "Hello world"; var tagNode = new HamlNodeTag(new HamlLine(tagName, HamlRuleEnum.Tag, "", 0)); tagNode.AddChild(new HamlNodeTextContainer(new HamlLine(nestedText, HamlRuleEnum.PlainText, "", 1, true))); // Act _tagWalker.Walk(tagNode); // Assert string expectedTag = string.Format("<{0}>{1}</{0}>", tagName, nestedText); Assert.That(_classBuilderMock.Build(""), Is.EqualTo(expectedTag)); }
public void Walk_IdFollowedByClassNodes_OrderedCorrectly() { // Arrange const string tagId = "id"; const string tagClass = "class"; var tagNode = new HamlNodeTag(new HamlLine("p", HamlRuleEnum.Tag, "", 0)); tagNode.AddChild(new HamlNodeTagId(0, tagId)); tagNode.AddChild(new HamlNodeTagClass(0, tagClass)); // 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.AppendSelfClosingTagSuffix(); } else { ClassBuilder.Append(">"); base.Walk(nodeTag); if (IsPreCloseTagWhitespaceTrimmed(nodeTag)) { ClassBuilder.AppendFormat("</{0}>", nodeTag.NamespaceQualifiedTagName); } else { ClassBuilder.AppendNewLine(); ClassBuilder.AppendFormat(nodeTag.Indent + "</{0}>", nodeTag.NamespaceQualifiedTagName); } } }
private void AppendAttributes(HamlNodeTag nodeTag) { MakeClassAttribute(nodeTag); MakeIdAttribute(nodeTag); WalkHtmlStyleAttributes(nodeTag); }
private void MakeClassAttribute(HamlNodeTag nodeTag) { var classValues = GetClassValues(nodeTag); AppendClassAttribute(classValues); }
private void MakeIdAttribute(HamlNodeTag nodeTag) { var idValues = GetIdValues(nodeTag); AppendIdAttribute(idValues); }
private HamlNode GetLastNonWhitespaceChild(HamlNodeTag nodeTag) { return(nodeTag.Children.LastOrDefault(x => x.IsWhitespaceNode() == false)); }
public void Constructor_SimpleTags_GeneratesCorrectTagName(string templateLine, string expectedTagName) { var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); Assert.That(tag.TagName, Is.EqualTo(expectedTagName)); }
public void Constructor_SimpleTags_DeterminesSelfClosingCorrectly(string templateLine, bool expectedSelfClosing) { var tag = new HamlNodeTag(new HamlLine(templateLine, HamlRuleEnum.Tag, "", 0)); Assert.That(tag.IsSelfClosing, Is.EqualTo(expectedSelfClosing)); }