Esempio n. 1
0
            public void Visit(VElement vElement)
            {
                _textWriter.Write("<");
                _textWriter.Write(vElement.TagName);

                if (vElement.Properties.Count > 0)
                    _textWriter.Write(" ");

                foreach (var property in vElement.Properties)
                {
                    var stringValue = property.Value as StringVPropertyValue;
                    var value = stringValue?.Value;

                    if (string.IsNullOrEmpty(value))
                        continue;

                    _textWriter.Write(property.Name);
                    _textWriter.Write("=");
                    _textWriter.Write("\"");
                    _textWriter.Write(value);
                    _textWriter.Write("\"");
                    _textWriter.Write(" ");
                }
                _textWriter.Write(">");

                foreach (var child in vElement.Children)
                {
                    child.Accept(this);
                }

                _textWriter.Write("</");
                _textWriter.Write(vElement.TagName);
                _textWriter.Write(">");
            }
            public void Visit(VElement vElement)
            {
                _writer.Write("h('");
                _writer.Write(vElement.TagName);
                _writer.Write(Apostroph);

                RenderProperties(vElement);
                RenderChildren(vElement);

                _writer.Write(")");
            }
            private void RenderChildren(VElement vElement)
            {
                if (vElement.Children.Count > 0)
                {
                    var last = vElement.Children[vElement.Children.Count - 1];

                    _writer.Write(",[");
                    foreach (var child in vElement.Children)
                    {
                        child.Accept(this);
                        if (child != last)
                            _writer.Write(",");
                    }
                    _writer.Write("]");
                }
            }
            private void RenderProperties(VElement vElement)
            {
                if (vElement.Properties.Count > 0)
                {
                    var last = vElement.Properties[vElement.Properties.Count - 1];

                    _writer.Write(",{");
                    foreach (var property in vElement.Properties)
                    {
                        _writer.Write(property.Name);
                        _writer.Write(":");
                        property.Value.Accept(this);

                        if (property != last)
                            _writer.Write(",");
                    }
                    _writer.Write("}");
                }
            }