App_Code.Controls.RelatedPosts.CreateList C# (CSharp) Method

CreateList() private method

Creates the list of related posts in HTML.
private CreateList ( IEnumerable relatedPosts ) : void
relatedPosts IEnumerable /// The related posts. ///
return void
        private void CreateList(IEnumerable<IPublishable> relatedPosts)
        {
            var sb = new StringBuilder();

            const string LinkFormat = "<a href=\"{0}\">{1}</a>";
            const string DescriptionFormat = "<span>{0}</span>";
            sb.Append("<div id=\"relatedPosts\">");
            sb.Append("<h3>+++</h3>");
            sb.Append("<div>");

            var count = 0;
            foreach (var post in relatedPosts)
            {
                if (post != this.Item)
                {
                    sb.Append(string.Format(LinkFormat, post.RelativeLink, HttpUtility.HtmlEncode(post.Title)));
                    if (this.ShowDescription)
                    {
                        var description = post.Description;
                        if (description != null && description.Length > this.DescriptionMaxLength)
                        {
                            description = string.Format("{0}...", description.Substring(0, this.DescriptionMaxLength));
                        }

                        if (String.IsNullOrEmpty(description))
                        {
                            var content = Utils.StripHtml(post.Content);
                            description = content.Length > this.DescriptionMaxLength
                                              ? string.Format("{0}...", content.Substring(0, this.DescriptionMaxLength))
                                              : content;
                        }

                        sb.Append(string.Format(DescriptionFormat, description));
                    }

                    count++;
                }

                if (count == this.MaxResults)
                {
                    break;
                }
            }

            sb.Append("</div>");
            sb.Append("</div>");
            RelatedPostsCache[this.Item.Id] = sb.ToString();
        }