Exemplo n.º 1
0
 public string ToHtmlString(Interface.IHtmlElement htmlElement)
 {
     if (htmlElement is Interface.IHtmlControl)
     {
         var htmlControl = htmlElement as Interface.IHtmlControl;
         var html        = new StringBuilder("<");
         html.Append(htmlControl.Tag);
         if (htmlControl.Classes != null && htmlControl.Classes.Count > 0)
         {
             html.Append(" class=\"");
             html.Append(string.Join(" ", htmlControl.Classes.ToArray()));
             html.Append("\"");
         }
         if (htmlControl.Attributes != null && htmlControl.Attributes.Count > 0)
         {
             html.Append(" ");
             var attrHtml = new List <string>();
             foreach (var attr in htmlControl.Attributes)
             {
                 attrHtml.Add(string.Format("{0}=\"{1}\"", attr.Name, attr.Value));
             }
             html.Append(string.Join(" ", attrHtml.ToArray()));
         }
         if (htmlControl.Styles != null && htmlControl.Styles.Count > 0)
         {
             html.Append(" style=\"");
             var stylesString = new List <string>();
             foreach (var style in htmlControl.Styles)
             {
                 stylesString.Add(string.Format("{0}: {1}", style.Name, style.Value));
             }
             html.Append(string.Join("; ", stylesString.ToArray()));
             html.Append("\"");
         }
         if (htmlControl is Interface.IHtmlContainerControl)
         {
             var htmlContainerControl = htmlControl as Interface.IHtmlContainerControl;
             if (htmlContainerControl.Children != null && htmlContainerControl.Children.Count > 0)
             {
                 html.AppendLine(">");
                 html.Append(string.Join(System.Environment.NewLine, htmlContainerControl.Children.Select(ele => this.ToHtmlString(ele)).ToArray()));
                 html.AppendLine();
             }
             else
             {
                 html.Append(">");
             }
             html.AppendFormat("</{0}>", htmlContainerControl.Tag);
         }
         else
         {
             html.Append(" />");
         }
         return(html.ToString());
     }
     else
     {
         return(htmlElement.ToString());
     }
 }
Exemplo n.º 2
0
 protected HtmlTableCell(string tag, Interface.IHtmlElement innerControl)
     : base(tag)
 {
     if (innerControl != null)
     {
         if (!string.IsNullOrEmpty(innerControl.ToString()))
         {
             this.Children.Add(innerControl);
         }
     }
 }
Exemplo n.º 3
0
        public virtual string Render(Interface.IHtmlElement htmlElement)
        {
            var html = new StringBuilder();

            if (htmlElement is Interface.IHtmlControl)
            {
                var htmlControl = htmlElement as Interface.IHtmlControl;

                html.Append("<");
                html.Append(htmlControl.Tag);
                if (htmlControl.Classes != null && htmlControl.Classes.Count > 0)
                {
                    html.AppendFormat(" class=\"{0}\"", string.Join(" ", htmlControl.Classes.ToArray()));
                }
                if (htmlControl.Attributes != null && htmlControl.Attributes.Count > 0)
                {
                    html.Append(" ");
                    html.Append(string.Join(" ", htmlControl.Attributes.Select(
                                                attr => string.Format("{0}=\"{1}\"", attr.Name, attr.Value)).ToArray()));
                }
                if (htmlControl.Styles != null && htmlControl.Styles.Count > 0)
                {
                    html.AppendFormat(" style=\"{0}\"", string.Join(" ", htmlControl.Styles.Select(
                                                                        css => string.Format("{0}=\"{1}\";", css.Name, css.Value)).ToArray()));
                }
                if (htmlControl is Interface.IHtmlContainerControl)
                {
                    var children = (htmlControl as Interface.IHtmlContainerControl).Children;
                    if (children != null && children.Count > 0)
                    {
                        html.AppendLine(">");
                        html.Append(string.Join(System.Environment.NewLine, children.Select(ele => this.Render(ele)).ToArray()));
                        html.AppendLine();
                    }
                    else
                    {
                        html.Append(">");
                    }
                    html.AppendFormat("</{0}>", htmlControl.Tag);
                }
                else
                {
                    html.Append(" />");
                }
            }
            else
            {
                html.Append(htmlElement.ToString());
            }

            return(html.ToString());
        }