Ejemplo n.º 1
0
        private void Walk(HamlNodeCode node)
        {
            var content = node.Content.Trim();

            // Conditionals require special logic since the parser doesn't yet extract it for us
            if (content.StartsWith("if"))
            {
                int    start      = content.IndexOf('(') + 1;
                string expression = content.Substring(start, content.Length - start - 1);

                _templateILStream.ConditionalBegin();
                Walk(node.Children);
                _templateILStream.ConditionalEnd(expression);
            }
            else if (content == "else")
            {
                _templateILStream.ConditionalElseBegin();
                Walk(node.Children);
                _templateILStream.ConditionalElseEnd();
            }
            else
            {
                _templateILStream.InlineCodeExpression(content);
            }
        }
Ejemplo n.º 2
0
        public void Walk_ChildNode_DoesNotThrowInvalidChildNodeException()
        {
            var node = new HamlNodeCode(new HamlLine("1+1", HamlRuleEnum.Code, "", -1));

            node.AddChild(new HamlNodeTextContainer(0, ""));

            Assert.DoesNotThrow(() => _walker.Walk(node));
        }
Ejemplo n.º 3
0
        public void AppendInnerTagNewLine_ValidNode_DoesNotAppendNewLine()
        {
            var node = new HamlNodeCode(new HamlLine("1+1", HamlRuleEnum.Code, "", -1));

            node.AppendInnerTagNewLine();

            Assert.That(node.Children.Any(), Is.False);
        }
Ejemplo n.º 4
0
        public void Walk_ValidNodeWithNoChildren_CallsAppendCodeSnippetMethodWithFalse()
        {
            string codeSnippet = "int c = 1";
            var    node        = new HamlNodeCode(new HamlLine(codeSnippet, HamlRuleEnum.Code, "", -1));

            _walker.Walk(node);

            _classBuilderMock.Verify(x => x.AppendCodeSnippet(codeSnippet, false));
        }
Ejemplo n.º 5
0
        public void Walk_ValidNode_DoesNotGenerateContent()
        {
            var node         = new HamlNodeCode(new HamlLine("1+1", HamlRuleEnum.Code, "", -1));
            var classBuilder = new ClassBuilderMock();
            var walker       = new HamlNodeCodeWalker(classBuilder, new HamlHtmlOptions());

            walker.Walk(node);

            Assert.That(classBuilder.Build(""), Is.EqualTo(""));
        }
Ejemplo n.º 6
0
        public void Walk_ValidNodeWithChildren_CallsRenderEndBlock()
        {
            string codeSnippet = "int c = 1";
            var    node        = new HamlNodeCode(new HamlLine(codeSnippet, HamlRuleEnum.Code, "", -1));

            node.AddChild(new HamlNodeTextContainer(-1, ""));

            _walker.Walk(node);

            _classBuilderMock.Verify(x => x.RenderEndBlock());
        }
Ejemplo n.º 7
0
        public void Walk_ConditionalWithChildNode_RendersChildNode()
        {
            const string dummyText = "Hello";
            var          node      = new HamlNodeCode(new HamlLine("if (true)", HamlRuleEnum.Code, "", -1));

            node.AddChild(new HamlNodeTextContainer(0, dummyText));
            var classBuilder = new ClassBuilderMock();

            var walker = new HamlNodeCodeWalker(classBuilder, new HamlHtmlOptions());

            walker.Walk(node);

            Assert.That(classBuilder.Build(""), Is.EqualTo(dummyText));
        }