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());
     }
 }
Exemple #2
0
 protected HtmlTableCell(string tag, Interface.IHtmlElement innerControl)
     : base(tag)
 {
     if (innerControl != null)
     {
         if (!string.IsNullOrEmpty(innerControl.ToString()))
         {
             this.Children.Add(innerControl);
         }
     }
 }
Exemple #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());
        }
Exemple #4
0
 public bool Remove(Interface.IHtmlElement document)
 {
     if (this.ReadOnly)
     {
         throw new HtmlElementCollectionReadOnlyException();
     }
     if (document == null)
     {
         throw new ArgumentNullException("Unable to remove a Null-Refrence object from the collection");
     }
     document.Parent = null;
     return(this.elements.Remove(document));
 }
Exemple #5
0
 public void Add(Interface.IHtmlElement element)
 {
     if (this.ReadOnly)
     {
         throw new HtmlElementCollectionReadOnlyException();
     }
     if (element == null)
     {
         throw new ArgumentNullException("element", "Unable to append a Null-Refrence object into the collection");
     }
     if (!this.CheckLoop(this.Container, element))
     {
         throw new ArgumentException("Cannot append a parent element", "element");
     }
     element.Parent = this.Container;
     this.elements.Add(element);
 }
Exemple #6
0
 private bool CheckLoop(Interface.IHtmlContainerControl container, Interface.IHtmlElement element)
 {
     if (container == null)
     {
         return(true);
     }
     if (object.ReferenceEquals(container, element))
     {
         return(false);
     }
     if (container.Parent == null)
     {
         return(true);
     }
     if (container.Parent is Interface.IHtmlContainerControl)
     {
         return(this.CheckLoop(container.Parent as Interface.IHtmlContainerControl, element));
     }
     return(true);
 }
Exemple #7
0
 public HtmlTableCell(Interface.IHtmlElement innerControl) : this(Controls.Attributes.TagNames.TD, innerControl)
 {
 }
Exemple #8
0
 public static TControl Wrap <TControl>(this Interface.IHtmlElement control, TControl wrapper) where TControl : Interface.IHtmlContainerControl
 {
     return(wrapper.Append(control));
 }