Example #1
0
        /// <summary>
        /// Define an image
        /// </summary>
        /// <param name="source">the url for the image</param>
        /// <param name="alt">alternate text for the image</param>
        /// <param name="imageType">type of image</param>
        public MvcHtmlString Image(string source, string alt, ImageType imageType)
        {
            var img = new TagBuilderExt("img");

            img.MergeAttribute("alt", alt);
            img.MergeAttribute("src", source);

            switch (imageType)
            {
            case ImageType.Rounded:
                img.AddCssClass("img-rounded");
                break;

            case ImageType.Circle:
                img.AddCssClass("img-circle");
                break;

            case ImageType.Polaroid:
                img.AddCssClass("img-polaroid");
                break;

            default:
                throw new ArgumentOutOfRangeException("imageType");
            }

            return(img.ToMvcHtmlString());
        }
Example #2
0
        /// <summary>
        /// Creates one breadcrumb link entry with the specified
        /// <paramref name="title"/> and link.
        /// </summary>
        /// <param name="title">The title of the breadcrumb link</param>
        /// <param name="url">The fully quallified URL</param>
        /// <param name="divider">
        /// Specify the divider created after the link. Set to "null" or empty
        /// for no divider.
        /// </param>
        public MvcHtmlString BreadcrumbLink(string title, string url, string divider)
        {
            var listItem = new TagBuilderExt("li");

            if (IsCurrentUrl(url))
            {
                listItem.AddCssClass("active");
                listItem.SetInnerText(title);
            }
            else
            {
                var link = new TagBuilderExt("a");
                link.MergeAttribute("href", url);
                link.SetInnerText(title);
                listItem.AddChildTag(link);
            }

            if (!string.IsNullOrEmpty(divider))
            {
                var dividerTag = new TagBuilderExt("span", divider);
                dividerTag.AddCssClass("divider");
                listItem.AddChildTag(dividerTag);
            }
            return(listItem.ToMvcHtmlString());
        }
Example #3
0
        /// <summary>
        /// Creates an emphasized paragraph
        /// </summary>
        /// <param name="text">Content of the emphasized paragraph</param>
        /// <param name="emphasisType">Type of the emphasis</param>
        public MvcHtmlString EmphasizedParagraph(string text, EmphasisType emphasisType)
        {
            var p = new TagBuilderExt("p");

            switch (emphasisType)
            {
            case EmphasisType.Muted:
                p.AddCssClass("muted");
                break;

            case EmphasisType.Warning:
                p.AddCssClass("text-warning");
                break;

            case EmphasisType.Error:
                p.AddCssClass("text-error");
                break;

            case EmphasisType.Info:
                p.AddCssClass("text-info");
                break;

            case EmphasisType.Success:
                p.AddCssClass("text-success");
                break;

            default:
                throw new ArgumentOutOfRangeException("emphasisType");
            }

            p.SetInnerText(text);
            return(p.ToMvcHtmlString());
        }
Example #4
0
        private TagBuilderExt CreateBaseButton(string tagName, ButtonStyle buttonStyle, ButtonSize buttonSize, bool isDisabled)
        {
            var tag = new TagBuilderExt(tagName);

            tag.AddCssClass("btn");

            switch (buttonStyle)
            {
            case ButtonStyle.Primary:
                tag.AddCssClass("btn-primary");
                break;

            case ButtonStyle.Info:
                tag.AddCssClass("btn-info");
                break;

            case ButtonStyle.Success:
                tag.AddCssClass("btn-success");
                break;

            case ButtonStyle.Warning:
                tag.AddCssClass("btn-warning");
                break;

            case ButtonStyle.Danger:
                tag.AddCssClass("btn-danger");
                break;

            case ButtonStyle.Inverse:
                tag.AddCssClass("btn-inverse");
                break;

            case ButtonStyle.Link:
                tag.AddCssClass("btn-link");
                break;
            }

            switch (buttonSize)
            {
            case ButtonSize.Large:
                tag.AddCssClass("btn-large");
                break;

            case ButtonSize.Small:
                tag.AddCssClass("btn-small");
                break;

            case ButtonSize.Mini:
                tag.AddCssClass("btn-mini");
                break;
            }

            if (isDisabled)
            {
                tag.AddCssClass("disabled");
            }

            return(tag);
        }
Example #5
0
        /// <summary>
        /// Creates a child tag with the specified name and HTML Content.
        /// </summary>
        /// <param name="tagName">Name of the child tag</param>
        /// <param name="content">Content of the child tag</param>
        /// <returns>Returns the <see cref="TagBuilderExt"/> for the child tag</returns>
        public TagBuilderExt CreateChildTag(string tagName, string content)
        {
            var child = new TagBuilderExt(tagName, content);

            AddChildTag(child);

            return(child);
        }
Example #6
0
        /// <summary>
        /// Creates a vertical menu-item separator
        /// </summary>
        public MvcHtmlString MenuItemSeparator()
        {
            var tag = new TagBuilderExt("li");

            tag.AddCssClass("divider-vertical");

            return(tag.ToMvcHtmlString());
        }
Example #7
0
        /// <summary>
        /// Creates a menu <paramref name="title"/> (have to be used inside a
        /// navbar menu).
        /// </summary>
        /// <param name="title">Title of the menu</param>
        /// <param name="url">A Fully quallified URL</param>
        public MvcHtmlString MenuTitle(string title, string url)
        {
            var a = new TagBuilderExt("a", title);

            a.AddCssClass("brand");
            a.MergeAttribute("href", url);

            return(a.ToMvcHtmlString());
        }
Example #8
0
        /// <summary>
        /// Makes a paragraph using the lead class to make it stand out.
        /// </summary>
        /// <param name="text">Content of the paragraph</param>
        public MvcHtmlString LeadBody(string text)
        {
            var p = new TagBuilderExt("p");

            p.AddCssClass("lead");
            p.SetInnerText(text);

            return(p.ToMvcHtmlString());
        }
Example #9
0
        /// <summary>
        /// Creates an HTML abbreviation with it's corresponding definition.
        /// </summary>
        /// <param name="title">Definition of the abbreviation.</param>
        /// <param name="value">The abbreviation.</param>
        /// <param name="isReduced">
        /// Defines if the abbreviation uses the <c>initialism</c> class for a slightly
        /// smaller font-size.
        /// </param>
        public MvcHtmlString Abbreviation(string title, string value, bool isReduced)
        {
            var abbr = new TagBuilderExt("abbr", value);

            if (isReduced)
            {
                abbr.AddCssClass("initialism");
            }
            abbr.MergeAttribute("title", title);

            return(abbr.ToMvcHtmlString());
        }
Example #10
0
        /// <summary>
        /// Creates one menu link entry with the specified
        /// <paramref name="title"/> and link.
        /// </summary>
        /// <param name="title">The title of the menu link</param>
        /// <param name="url">The fully quallified URL</param>
        public MvcHtmlString MenuLink(string title, string url)
        {
            var listItem = new TagBuilderExt("li");

            if (IsCurrentUrl(url))
            {
                listItem.AddCssClass("active");
            }
            var link = new TagBuilderExt("a");

            link.MergeAttribute("href", url);
            link.SetInnerText(title);
            listItem.AddChildTag(link);

            return(listItem.ToMvcHtmlString());
        }
Example #11
0
        /// <summary>
        /// Creates an HTML block-quote.
        /// </summary>
        /// <param name="quote">The quote.</param>
        /// <param name="author">The author.</param>
        /// <param name="source">The source.</param>
        /// <param name="sourceTitle">
        /// The <paramref name="source"/> title.
        /// </param>
        /// <param name="isPulledRight">
        /// Set to <see langword="true"/> for a floated, right-aligned
        /// blockquote.
        /// </param>
        public MvcHtmlString BlockQuote(string quote, string author, string source, string sourceTitle, bool isPulledRight)
        {
            var blockquote = new TagBuilderExt("blockquote");

            if (isPulledRight)
            {
                blockquote.AddCssClass("pull-right");
            }

            var cite = new TagBuilderExt("cite", source);

            cite.MergeAttribute("title", sourceTitle);

            blockquote.CreateChildTag("p", quote);
            blockquote.CreateChildTag("small").InnerHtml = String.Concat(author, " ", cite.ToString());

            return(blockquote.ToMvcHtmlString());
        }
Example #12
0
        /// <summary>
        /// Creates a Bootstrap progress-bar with a defined
        /// <paramref name="style"/>, <paramref name="color"/> and
        /// <paramref name="progress"/>.
        /// </summary>
        /// <param name="style">The style of the progress bar</param>
        /// <param name="color">The color of the progress bar</param>
        /// <param name="progress">The current progress percentage</param>
        public MvcHtmlString ProgressBar(ProgressBarStyle style, ProgressBarColor color, double progress)
        {
            var progressTag = new TagBuilderExt("div");

            progressTag.AddCssClass("progress");

            switch (color)
            {
            case ProgressBarColor.Info:
                progressTag.AddCssClass("progress-info");
                break;

            case ProgressBarColor.Success:
                progressTag.AddCssClass("progress-success");
                break;

            case ProgressBarColor.Warning:
                progressTag.AddCssClass("progress-warning");
                break;

            case ProgressBarColor.Danger:
                progressTag.AddCssClass("progress-danger");
                break;
            }

            switch (style)
            {
            case ProgressBarStyle.Animated:
                progressTag.AddCssClass("active");
                break;

            case ProgressBarStyle.Striped:
                progressTag.AddCssClass("progress-striped");
                break;
            }

            var barTag = progressTag.CreateChildTag("div");

            barTag.AddCssClass("bar");
            barTag.MergeAttribute("style", string.Format("width: {0}%", progress));
            return(progressTag.ToMvcHtmlString());
        }
Example #13
0
        /// <summary>
        /// Creates an automatic breadcrumb based on the navigation history.
        /// </summary>
        /// <param name="maximumElements">
        /// The maximum number of breadcrumbs to be displayed.
        /// </param>
        /// <param name="divider">The divider used between breadcrumbs.</param>
        /// <returns>
        ///
        /// </returns>
        public MvcHtmlString Breadcrumb(int maximumElements, string divider)
        {
            var breadcrumbTag = new TagBuilderExt("ul");

            breadcrumbTag.AddCssClass("breadcrumb");
            var navHistory = Page.NavigationHistory.ToArray();

            var linksToDisplay = navHistory.Skip(Math.Max(0, navHistory.Count() - maximumElements)).Take(maximumElements);
            var visitedPages   = linksToDisplay as IList <VisitedPage> ?? linksToDisplay.ToList();
            var lastElement    = visitedPages.Last();

            foreach (var visitedPage in visitedPages)
            {
                if (visitedPage == lastElement)
                {
                    divider = null;
                }
                breadcrumbTag.InnerHtml += BreadcrumbLink(visitedPage.Title, visitedPage.Uri.AbsoluteUri, divider);
            }

            return(breadcrumbTag.ToMvcHtmlString());
        }
Example #14
0
        /// <summary>
        /// Creates a description list with the associated descriptions
        /// </summary>
        /// <param name="isHorizontal">
        /// Make terms and descriptions in line up side-by-side.
        /// </param>
        /// <param name="elements">
        /// The dictionary of descriptions by title (key) and description
        /// (value).
        /// </param>
        public MvcHtmlString DescriptionList(bool isHorizontal, IDictionary <string, string> elements)
        {
            if (elements == null)
            {
                return(null);
            }

            var root = new TagBuilderExt("dl");

            if (isHorizontal)
            {
                root.AddCssClass("dl-horizontal");
            }

            foreach (var element in elements)
            {
                root.CreateChildTag("dt", element.Key);
                root.CreateChildTag("dd", element.Value);
            }

            return(root.ToMvcHtmlString());
        }
Example #15
0
 /// <summary>
 /// Add a tag as an inner tag of the current instance.
 /// </summary>
 /// <param name="child">Child tag</param>
 public void AddChildTag(TagBuilderExt child)
 {
     ChildrenTags.Add(child);
 }