public static object Truncate(IHtmlString htmlString, int length)
 {
     if (htmlString.ToHtmlString().Length <= length)
     {
         return htmlString.ToHtmlString();
     }
     return htmlString.ToHtmlString().Substring(0, length) + "...";
 }
Beispiel #2
0
 protected bool HasTag(IHtmlString html, string tag)
 {
     var doc = new HtmlDocument();
     doc.LoadHtml(html.ToHtmlString());
     var xpath = "//" + tag;
     return doc.DocumentNode.SelectSingleNode(xpath) != null;
 }
    /// <summary>
    /// Inserts the given attributes at the end of all opening tags in this HtmlString.
    /// </summary>
    /// <param name="htmlString">The HTML string.</param>
    /// <param name="attributeValues">The attribute values.</param>
    /// <exception cref="System.NullReferenceException"></exception>
    /// <exception cref="System.ArgumentException">No opening tag in IHtmlString: {0} + html;htmlString</exception>
    private static IHtmlString InsertAttributes(IHtmlString htmlString, IEnumerable<Tuple<string, object>> attributeValues)
    {
        if (htmlString == null) throw new NullReferenceException();

        var attributes = new StringBuilder();
        foreach (var t in attributeValues)
        {
            attributes.AppendFormat(" {0}=\"{1}\"",
                HttpUtility.HtmlEncode(t.Item1).ToLower(),
                HttpUtility.HtmlEncode((t.Item2 ?? String.Empty).ToString()));
        }

        var html = htmlString.ToHtmlString();

        var matches = GetOpeningTagMatches(html);
        if (matches.Count == 0)
            throw new ArgumentException("No opening tag in IHtmlString: {0}" + html, "htmlString");

        foreach (Match match in matches)
        {
            var endOfOpeningTag = match.Groups[3].Index;
            html = html.Insert(endOfOpeningTag, attributes.ToString());
        }

        return new HtmlString(html);
    }
        public FlowFormMessage(TextWriter writer, MessageType messageType, string heading, IHtmlString message = null)
        {
            _writer = writer;
            _writer.Write(HelperDefinitions.BeginMessage(messageType.ToDescription(), heading).ToHtmlString());

            if (message != null)
            {
                _writer.Write(message.ToHtmlString());
                _writer.Write(HelperDefinitions.EndMessage().ToHtmlString());
            }
        }
Beispiel #5
0
        private static HtmlString Render(IHtmlString html, string replaceTemplate)
        {
            var scriptsAsString = html.ToHtmlString();
            var bundleEntries = scriptsAsString.Split(new string[] { Environment.NewLine.ToString() },
                StringSplitOptions.RemoveEmptyEntries);

            string src = string.Format(replaceTemplate, string.Empty);

            string version = Assembly.GetExecutingAssembly().GetFormatedVersion("/v{0}_{1}_{2}_{3}");
            string markerWithVersion = string.Format(replaceTemplate, version);

            bundleEntries = bundleEntries.Select(x => { return x.Replace(src, markerWithVersion); }).ToArray();

            return new HtmlString(string.Join(Environment.NewLine, bundleEntries));
        }
Beispiel #6
0
        /// <summary>
        /// Creates the HTML for a submit &lt;button&gt;.
        /// </summary>
        /// <param name="content">The content to display for the button</param>
        /// <param name="type">The type of submit button; submit (default) or reset</param>
        /// <param name="value">The value to submit with the button</param>
        /// <param name="id">The id/name to use for the button</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the button</param>
        /// <returns>The HTML for the submit button</returns>
        public static IHtmlString BuildButton(IHtmlString content, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
        {
            var t = new TagBuilder("button") {InnerHtml = content.ToHtmlString()};
            if (value != null)
                t.Attributes.Add("value", value);
            if (type != null)
                t.Attributes.Add("type", type);
            if (id != null)
            {
                t.Attributes.Add("id", id);
                t.Attributes.Add("name", id);
            }
            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, true);

            return new HtmlString(t.ToString(TagRenderMode.Normal));
        }
Beispiel #7
0
        /// <summary>
        /// Writes an opening <![CDATA[ <a> ]]> tag to the response if the shouldWriteLink argument is true.
        /// Returns a ConditionalLink object which when disposed will write a closing <![CDATA[ </a> ]]> tag
        /// to the response if the shouldWriteLink argument is true.
        /// </summary>
        public static ConditionalLink BeginConditionalLink(this HtmlHelper helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null)
        {
            if (shouldWriteLink)
            {
                var linkTag = new TagBuilder("a");
                linkTag.Attributes.Add("href", url.ToHtmlString());

                if (!string.IsNullOrWhiteSpace(title))
                {
                    linkTag.Attributes.Add("title", helper.Encode(title));
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    linkTag.Attributes.Add("class", cssClass);
                }

                helper.ViewContext.Writer.Write(linkTag.ToString(TagRenderMode.StartTag));
            }
            return(new ConditionalLink(helper.ViewContext, shouldWriteLink));
        }
        /// <summary>
        /// Writes an opening <![CDATA[ <a> ]]> tag to the response if the shouldWriteLink argument is true.
        /// Returns a ConditionalLink object which when disposed will write a closing <![CDATA[ </a> ]]> tag
        /// to the response if the shouldWriteLink argument is true.
        /// </summary>
        public static ConditionalLink BeginConditionalLink(this HtmlHelper helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null)
        {
            if(shouldWriteLink)
            {
                var linkTag = new TagBuilder("a");
                linkTag.Attributes.Add("href", url.ToHtmlString());

                if(!string.IsNullOrWhiteSpace(title))
                {
                    linkTag.Attributes.Add("title", helper.Encode(title));
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    linkTag.Attributes.Add("class", cssClass);
                }

                helper.ViewContext.Writer.Write(linkTag.ToString(TagRenderMode.StartTag));
            }
            return new ConditionalLink(helper.ViewContext, shouldWriteLink);
        }
Beispiel #9
0
        public static IHtmlString Toggleable(this HtmlHelper htmlHelper,
                                             IHtmlString first, string firstButton,
                                             IHtmlString second, string secondButton)
        {
            string random = Guid.NewGuid().ToString("N");
            var    sb     = new System.Text.StringBuilder();

            sb.Append($"<script>");
            sb.Append($"$(function () {{");
            sb.Append($"$('.{random}_first.btn').click(function () {{");
            sb.Append($"$('.{random}_first.content').show();");
            sb.Append($"$('.{random}_second.content').hide();");
            sb.Append($"$('.{random}_first.btn').addClass(\"active\");");
            sb.Append($"$('.{random}_second.btn').removeClass(\"active\");");
            sb.Append($"}});");
            sb.Append($"$('.{random}_second.btn').click(function () {{");
            sb.Append($"$('.{random}_first.content').hide();");
            sb.Append($"$('.{random}_second.content').show();");
            sb.Append($"$('.{random}_first.btn').removeClass(\"active\");");
            sb.Append($"$('.{random}_second.btn').addClass(\"active\");");
            sb.Append($"}});");
            sb.Append($"}});");
            sb.Append($"</script>");
            sb.Append($"<div class=\"btn btn-default {random}_first active\" style=\"border-top-right-radius: 0px;border-bottom-right-radius: 0px;\">{firstButton}</div>");
            sb.Append($"<div class=\"btn btn-default {random}_second\" style=\"border-top-left-radius: 0px;border-bottom-left-radius: 0px;\">{secondButton}</div>");
            sb.Append($"<div class=\"{random}_first content\">{first.ToHtmlString()}</div>");
            sb.Append($"<div class=\"{random}_second content\" style=\"display: none; \">{second.ToHtmlString()}</div>");

            //sb.Append("<script>");
            //sb.Append("$(function () {");
            //sb.Append($"$('.{random}.btn').click(function () {{");
            //sb.Append($"$('.{random}').toggle();}});}});");
            //sb.Append("</script>");
            //sb.Append($"<div class=\"btn btn-default {random}\"><span style=\"color:black;\">{firstButton}/</span><small>{secondButton}</small></div>");
            //sb.Append($"<div class=\"btn btn-default {random}\" style=\"display:none;\"><small>{firstButton}</small><span style=\"color:black;\">/{secondButton}</span></div>");
            //sb.Append($"<div class=\"{random}\">{first.ToHtmlString()}</div>");
            //sb.Append($"<div class=\"{random}\" style=\"display:none;\">{second.ToHtmlString()}</div>");

            return(htmlHelper.Raw(sb.ToString()));
        }
Beispiel #10
0
        public void DisabledPagerItemTemplate_ShouldGenerateCorrectHtml()
        {
            const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
            IHtmlString  html       = _ajaxHelper.Pager(_testList,
                                                        new PagerOptions
            {
                PageIndexParameterName    = "id",
                DisabledPagerItemTemplate = "<span class=\"disabled\">{0}</span>"
            }, new MvcAjaxOptions {
                UpdateTargetId = "uptarget"
            });
            var sb    = new StringBuilder(TestHelper.CopyrightText);
            var attrs = new[]
            {
                "data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"",
                "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
                "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
                "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
                "data-urlformat=\"" + BaseLink + "/__id__\""
            };

            sb.Append("<div");
            foreach (var att in attrs.OrderBy(a => a))
            {
                sb.Append(" ").Append(att);
            }
            sb.Append(">");
            sb.Append("<span class=\"disabled\">First</span>")
            .Append("<span class=\"disabled\">Prev</span>")
            .Append("1");
            for (int i = 2; i <= 10; i++)
            {
                sb.AppendFormat(linkFormat, i, i);
            }
            sb.AppendFormat(linkFormat, 11, "...");
            sb.AppendFormat(linkFormat, 2, "Next");
            sb.AppendFormat(linkFormat, 11, "Last");
            sb.Append("</div>").Append(TestHelper.CopyrightText);
            Assert.AreEqual(html.ToHtmlString(), sb.ToString());
        }
        public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            var viewResult = _themeAwareViewEngine.FindPartialView(controllerContext, viewName, useCache, true);

            if (viewResult.View == null)
            {
                return(viewResult);
            }

            if (!ThemeFilter.IsApplied(controllerContext.RequestContext))
            {
                return(viewResult);
            }

            var layoutView = new LayoutView((viewContext, writer, viewDataContainer) =>
            {
                Logger.Information("Rendering layout view");

                var childContentWriter = new HtmlStringWriter();

                var childContentViewContext = new ViewContext(
                    viewContext,
                    viewContext.View,
                    viewContext.ViewData,
                    viewContext.TempData,
                    childContentWriter);

                viewResult.View.Render(childContentViewContext, childContentWriter);
                _workContext.Layout.Metadata.ChildContent = childContentWriter;

                var display        = _displayHelperFactory.CreateHelper(viewContext, viewDataContainer);
                IHtmlString result = display(_workContext.Layout);
                writer.Write(result.ToHtmlString());

                Logger.Information("Done rendering layout view");
            }, (context, view) => viewResult.ViewEngine.ReleaseView(context, viewResult.View));

            return(new ViewEngineResult(layoutView, this));
        }
        /// <summary>
        /// Formats an HTML fragment.
        /// </summary>
        /// <param name="html">The HTML .</param>
        private IHtmlString TransformHtml(IHtmlString html)
        {
            if (html == null)
            {
                return(html);
            }

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(html.ToHtmlString());

            foreach (var formatter in _formatters)
            {
                if (formatter == null)
                {
                    continue;
                }
                formatter.FormatHtml(htmlDocument);
            }

            return(new HtmlString(htmlDocument.DocumentNode.OuterHtml));
        }
Beispiel #13
0
        public void AjaxEvents_ShouldGenerateCorrectHtml()
        {
            _testList.CurrentPageIndex = 1;
            const string linkFormat = "<a data-pageindex=\"{0}\" href=\"" + BaseLink + "/{0}\">{1}</a>";
            IHtmlString  html       = _ajaxHelper.Pager(_testList, new PagerOptions {
                PageIndexParameterName = "id"
            }, new MvcAjaxOptions {
                UpdateTargetId = "uptarget", OnBegin = "function(data){alert(data);}", OnComplete = "alert(\"complete\")", OnFailure = "failureHandler", OnSuccess = "showSuccessMsg"
            });
            var sb    = new StringBuilder(TestHelper.CopyrightText);
            var attrs = new[]
            {
                "data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"",
                "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
                "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
                "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
                "data-urlformat=\"" + BaseLink + "/__id__\"", "data-ajax-begin=\"" + HttpUtility.HtmlEncode("function(data){alert(data);}") + "\"",
                "data-ajax-complete=\"" + HttpUtility.HtmlEncode("alert(\"complete\")") + "\"", "data-ajax-failure=\"failureHandler\"",
                "data-ajax-success=\"showSuccessMsg\""
            };

            sb.Append("<div");
            foreach (var att in attrs.OrderBy(a => a))
            {
                sb.Append(" ").Append(att);
            }
            sb.Append(">");
            sb.Append("First").Append("Prev").Append("1");
            for (int i = 2; i <= 10; i++)
            {
                sb.AppendFormat(linkFormat, i, i);
            }
            sb.AppendFormat(linkFormat, 11, "...");
            sb.AppendFormat(linkFormat, 2, "Next");
            sb.AppendFormat(linkFormat, 11, "Last");
            sb.Append("</div>").Append(TestHelper.CopyrightText);
            Assert.AreEqual(html.ToHtmlString(), sb.ToString());
        }
Beispiel #14
0
        /// <summary>
        /// Checks for content
        /// </summary>
        /// <param name="HtmlString">String to test</param>
        /// <param name="EmptyParagraphsIsNull">Should a string made up of only empty &lt;p&gt; tags be considered null?</param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this IHtmlString HtmlString, bool EmptyParagraphsIsNull)
        {
            if (HtmlString == null)
            {
                return(true);
            }

            var testString = HtmlString.ToHtmlString();

            if (string.IsNullOrWhiteSpace(testString))
            {
                return(true);
            }

            if (EmptyParagraphsIsNull)
            {
                testString = testString.RemoveAllParagraphTags(false).Trim();
                return(string.IsNullOrWhiteSpace(testString));
            }

            //If we get here
            return(false);
        }
Beispiel #15
0
        public void CurrentPageIndexIs3_CustomErrorMessage_ShouldGenerateCorrectDataAttributes()
        {
            _testList.CurrentPageIndex = 3;
            IHtmlString html = _ajaxHelper.Pager(_testList, new PagerOptions {
                PageIndexParameterName = "id", PageIndexOutOfRangeErrorMessage = "out of range", InvalidPageIndexErrorMessage = "invalid page index"
            }, new MvcAjaxOptions {
                UpdateTargetId = "uptarget"
            });
            var attrs = new[]
            {
                "data-ajax=\"true\"", "data-ajax-update=\"#uptarget\"", "data-currentpage=\"3\"",
                "data-invalidpageerrmsg=\"invalid page index\"", "data-firstpage=\"" + BaseLink + "\"",
                "data-outrangeerrmsg=\"out of range\"",
                "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"", "data-urlformat=\"" + BaseLink + "/__id__\""
            };
            var sb = new StringBuilder("<div");

            foreach (var att in attrs.OrderBy(a => a))
            {
                sb.Append(" ").Append(att);
            }
            sb.Append(">");
            StringAssert.Contains(html.ToHtmlString(), sb.ToString());
        }
        public static TThis AddContent <THelper, TThis, TWrapper>(this Component <THelper, TThis, TWrapper> component, object content)
            where THelper : BootstrapHelper <THelper>
            where TThis : Tag <THelper, TThis, TWrapper>
            where TWrapper : TagWrapper <THelper>, new()
        {
            TThis tag = component.GetThis();

            if (content != null)
            {
                // Make sure that this isn't a component
                Component contentComponent = content as Component;
                if (contentComponent != null)
                {
                    return(AddChild(component, x => contentComponent));
                }

                // Now check if it's an IHtmlString
                string      str;
                IHtmlString htmlString = content as IHtmlString;
                if (htmlString != null)
                {
                    str = htmlString.ToHtmlString();
                }
                else
                {
                    // Just convert to a string using the standard conversion logic
                    str = Convert.ToString(content, CultureInfo.InvariantCulture);
                }

                if (!string.IsNullOrEmpty(str))
                {
                    tag.AddChild(new Content <THelper>(tag.Helper, str));
                }
            }
            return(tag);
        }
 public IHtmlString Truncate(IHtmlString html, int length, bool addElipsis)
 {
     return(Truncate(html.ToHtmlString(), length, addElipsis, false));
 }
Beispiel #18
0
 public static string ToStringOrNull(this IHtmlString html)
 {
     return(html == null ? null : html.ToHtmlString());
 }
Beispiel #19
0
 public static IHtmlString TimeScript(this WebPageBase page, string name, IHtmlString html) =>
 new HtmlString(ClientTimingHelper.TimeScript(name, html.ToHtmlString()));
public static System.Web.WebPages.HelperResult BeginMessage(MessageType messageType, IHtmlString heading) {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 95 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                    


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "      <div class=\"");


#line 96 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, string.Format("{0}{1}", messageType.ToString().ToLower(), "_message"));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\">\r\n");


#line 97 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
            if (!string.IsNullOrEmpty(heading.ToHtmlString()))
            {


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "          <h3>");


#line 99 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, heading);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</h3>\r\n");


#line 100 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
            }


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "          <div class=\"message\">\r\n");


#line 102 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"


#line default
#line hidden
});

#line 102 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
}
 public void Write(IHtmlString htmlString)
 {
     Write(htmlString.ToHtmlString());
 }
Beispiel #22
0
 private void BuildEditor <TValue>(Expression <Func <TModel, TValue> > expression, bool requiredField, IHtmlString editorIHtmlString, IHtmlString validatorMessageIHtmlString)
 {
     BuildEditor(expression, requiredField, editorIHtmlString.ToHtmlString(), validatorMessageIHtmlString == null ? null : validatorMessageIHtmlString.ToHtmlString());
 }
 private IList<XElement> ExtractScriptTags(IHtmlString html)
 {
     // To help us inspect the HTML, we will parse as XML.
     var root = XDocument.Parse("<root>" + html.ToHtmlString() + "</root>").Root;
     var scripts = root.Elements().ToList();
     return scripts;
 }
 /// <summary>
 /// To be used inline in razor pages - times a script be sure to call <c>InitClientTimings</c> first
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="name">The name.</param>
 /// <param name="html">The html.</param>
 /// <returns>a string containing the time script</returns>
 public static IHtmlString TimeScript(this WebPageBase page, string name, IHtmlString html)
 {
     return new HtmlString(TimeScript(name, html.ToHtmlString()));
 }
Beispiel #25
0
 public HtmlString StripHtml(IHtmlString html, params string[] tags)
 {
     return(StripHtml(html.ToHtmlString(), tags));
 }
Beispiel #26
0
        public void AssertScriptDivIsCorrectWithCallbacksAndLanguage()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key");
            IHtmlString captcha = ReCaptcha.GetCaptcha(ReCaptchaLanguage.Spanish, "callback", "expiredCallback", "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-expired-callback='expiredCallback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js?hl=es'></script>", captcha.ToHtmlString());
        }
Beispiel #27
0
        public void AssertScriptDivIsCorrectWithCallbacks()
        {
            ReCaptcha.Configure("my-public-key", "my-secret-key");
            IHtmlString captcha1 = ReCaptcha.GetCaptcha(callback: "callback", expiredCallback: "expiredCallback", errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-expired-callback='expiredCallback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha1.ToHtmlString());

            IHtmlString captcha2 = ReCaptcha.GetCaptcha(callback: "callback", errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha2.ToHtmlString());

            IHtmlString captcha3 = ReCaptcha.GetCaptcha(callback: "callback", expiredCallback: "expiredCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback' data-expired-callback='expiredCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha3.ToHtmlString());

            IHtmlString captcha4 = ReCaptcha.GetCaptcha(callback: "callback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-callback='callback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha4.ToHtmlString());

            IHtmlString captcha5 = ReCaptcha.GetCaptcha(expiredCallback: "expiredCallback", errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-expired-callback='expiredCallback' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha5.ToHtmlString());

            IHtmlString captcha6 = ReCaptcha.GetCaptcha(expiredCallback: "expiredCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-expired-callback='expiredCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha6.ToHtmlString());

            IHtmlString captcha7 = ReCaptcha.GetCaptcha(errorCallback: "errorCallback");

            Assert.AreEqual("<div class='g-recaptcha' data-sitekey='my-public-key' data-error-callback='errorCallback'></div><script src='https://www.google.com/recaptcha/api.js'></script>", captcha7.ToHtmlString());
        }
Beispiel #28
0
 public static void AddModelError(this ModelStateDictionary dictionary, string key, IHtmlString errorMessage)
 {
     dictionary.AddModelError(key, errorMessage.ToHtmlString());
 }
Beispiel #29
0
 /// <summary>
 /// Truncates a string to a given length, can add a ellipsis at the end (...). Method checks for open HTML tags, and makes sure to close them
 /// </summary>
 public static IHtmlString Truncate(this HtmlHelper helper, IHtmlString html, int length, bool addElipsis, bool treatTagsAsContent)
 {
     return(helper.Truncate(html.ToHtmlString(), length, addElipsis, treatTagsAsContent));
 }
Beispiel #30
0
 /// <summary>
 /// Truncates a string to a given length, can add a ellipsis at the end (...). Method checks for open HTML tags, and makes sure to close them
 /// </summary>
 public static IHtmlString Truncate(this HtmlHelper helper, IHtmlString html, int length, bool addElipsis)
 {
     return(helper.Truncate(html.ToHtmlString(), length, addElipsis, false));
 }
Beispiel #31
0
 /// <summary>
 /// Truncates a string to a given length, can add a ellipsis at the end (...). Method checks for open HTML tags, and makes sure to close them
 /// </summary>
 public static IHtmlString Truncate(this HtmlHelper helper, IHtmlString html, int length)
 {
     return(helper.Truncate(html.ToHtmlString(), length, true, false));
 }
Beispiel #32
0
 /// <summary>
 /// The Text object represents the textual content of an element or attribute. <remarks> </remarks>
 /// 
 /// For more information see: <see cref="http://www.w3schools.com/xml/dom_text.asp"/>
 /// </summary>
 /// <param name="builder">Builder for the Html Component</param>
 /// <param name="text">The text to display as a comment (will be HTML Encoded)</param>
 /// <returns></returns>
 public static IHtmlElement Text(this IBuilder builder, IHtmlString text)
 {
     return builder.CreateElement(String.Empty).SetText(text.ToHtmlString());
 }
 public string RawClientTemplateFormat(IHtmlString name, int espace)
 {
     return RawClientTemplateFormat(name.ToHtmlString(), espace);
 }
Beispiel #34
0
        private void BuildEditor <TValue>(Expression <Func <TModel, TValue> > expression, bool requiredField, IHtmlString editorIHtmlString)
        {
            var validationMessageFor = GetValidationMessage(expression);

            BuildEditor(expression, requiredField, editorIHtmlString.ToHtmlString(), validationMessageFor);
        }
 public string CheckFormat(IHtmlString name, string trueValue, string falseValue, int escape)
 {
     return CheckFormat(name.ToHtmlString(), trueValue, falseValue, escape);
 }
Beispiel #36
0
 public string ToHtmlString()
 {
     return(_value.ToHtmlString());
 }
public static System.Web.WebPages.HelperResult BeginFieldInternal(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, IReadonlyFieldConfiguration fieldConfiguration, ModelMetadata fieldMetadata, IHtmlString requiredDesignator) {
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {



#line 61 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                                                                                                                                     

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "            <dt>");



#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, labelHtml);

#line default
#line hidden



#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, new HtmlString(fieldMetadata != null && fieldMetadata.IsRequired ? requiredDesignator.ToHtmlString() : ""));

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</dt>\r\n");



WebViewPage.WriteLiteralTo(@__razor_helper_writer, "            <dd");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, RenderIfNotEmpty(fieldConfiguration.FieldContainerClasses,item => new System.Web.WebPages.HelperResult(__razor_template_writer => {

#line default
#line hidden


WebViewPage.WriteLiteralTo(@__razor_template_writer, " class=\"");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                               WebViewPage.WriteTo(@__razor_template_writer, fieldConfiguration.FieldContainerClasses);

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_template_writer, "\"");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                                                           })));

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n");



WebViewPage.WriteLiteralTo(@__razor_helper_writer, "                ");



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, GetPrependedHtml(fieldConfiguration));

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
            WebViewPage.WriteTo(@__razor_helper_writer, elementHtml);

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                        WebViewPage.WriteTo(@__razor_helper_writer, GetAppendedHtml(fieldConfiguration));

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                            WebViewPage.WriteTo(@__razor_helper_writer, GetHint(fieldConfiguration));

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, " ");



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                         WebViewPage.WriteTo(@__razor_helper_writer, validationHtml);

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n");



#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"

#line default
#line hidden

});

}
public static System.Web.WebPages.HelperResult BeginFieldInternal(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, IReadonlyFieldConfiguration fieldConfiguration, ModelMetadata fieldMetadata, IHtmlString requiredDesignator) {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                                                                                                                                     


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "            <dt>");


#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, labelHtml);


#line default
#line hidden

#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, new HtmlString(fieldMetadata != null && fieldMetadata.IsRequired ? requiredDesignator.ToHtmlString() : ""));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</dt>\r\n");

WriteLiteralTo(__razor_helper_writer, "            <dd>\r\n");

WriteLiteralTo(__razor_helper_writer, "                ");


#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, GetPrependedHtml(fieldConfiguration));


#line default
#line hidden

#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                         WriteTo(__razor_helper_writer, elementHtml);


#line default
#line hidden

#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                     WriteTo(__razor_helper_writer, GetAppendedHtml(fieldConfiguration));


#line default
#line hidden

#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                         WriteTo(__razor_helper_writer, GetHint(fieldConfiguration));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, " ");


#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                      WriteTo(__razor_helper_writer, validationHtml);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\r\n");


#line 66 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"


#line default
#line hidden
});

#line 66 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
}
Beispiel #39
0
 protected HtmlNode ToIframeHtml(IHtmlString html)
 {
     var doc = new HtmlDocument();
     doc.LoadHtml(html.ToHtmlString());
     return doc.DocumentNode.SelectSingleNode("//iframe");
 }
Beispiel #40
0
 /// <summary>
 /// To be used inline in razor pages - times a script be sure to call <c>InitClientTimings</c> first
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="name">The name.</param>
 /// <param name="html">The html.</param>
 /// <returns>a string containing the time script</returns>
 public static IHtmlString TimeScript(this WebPageBase page, string name, IHtmlString html)
 {
     return(new HtmlString(TimeScript(name, html.ToHtmlString())));
 }
Beispiel #41
0
        public void CustomRouteValuesWithControllerNameAndActionName_ShouldGenerateCorrectLink()
        {
            IHtmlString html = _ajaxHelper.Pager(_testList).Options(o => o.SetPageIndexParameterName("id").AddRouteValue("Controller", "MyController").AddRouteValue("Action", "MyAction")).AjaxOptions(a => a.SetUpdateTargetId("uptarget"));

            StringAssert.Contains(html.ToHtmlString(), "<a data-pageindex=\"3\" href=\"" + TestHelper.AppPathModifier + AppPath + "/MyController/MyAction/3\">3</a>");
        }
Beispiel #42
0
 public static bool HasValue(this IHtmlString html)
 {
     return(html != null && !string.IsNullOrEmpty(html.ToHtmlString()));
 }
Beispiel #43
0
        public void PagerOptionsWithCustomRouteValues_ShouldGenerateGenerateCorrectUrl()
        {
            IHtmlString html = _ajaxHelper.Pager(_testList).AjaxOptions(a => a.SetUpdateTargetId("uptarget")).Options(o => o.SetPageIndexParameterName("id").AddRouteValue("Controller", "MyController").AddRouteValue("Action", "MyAction").AddRouteValue("city", "Wuqi").AddRouteValue("nick", "Webdiyer"));

            StringAssert.Contains(html.ToHtmlString(), "<a data-pageindex=\"3\" href=\"" + TestHelper.AppPathModifier + AppPath + "/MyController/MyAction/3?city=Wuqi&amp;nick=Webdiyer\">3</a>");
        }
 public IHtmlString Truncate(IHtmlString html, int length)
 {
     return(Truncate(html.ToHtmlString(), length, true, false));
 }
Beispiel #45
0
        public void PagerOptionsWithCustomHtmlAttributesValue_ShouldGenerateCorrectAttributes()
        {
            IHtmlString html = _ajaxHelper.Pager(_testList).AjaxOptions(a => a.SetUpdateTargetId("uptarget")).Options(o => o.SetPageIndexParameterName("id").AddHtmlAttribute("aaa", "98%").AddHtmlAttribute("bbb", "28px").AddHtmlAttribute("ccc", "both"));

            StringAssert.Contains(html.ToHtmlString(), "<div aaa=\"98%\" bbb=\"28px\" ccc=\"both\" data-ajax=\"true\" ");
        }
 public IHtmlString Truncate(IHtmlString html, int length, bool addElipsis, bool treatTagsAsContent)
 {
     return(Truncate(html.ToHtmlString(), length, addElipsis, treatTagsAsContent));
 }
public static System.Web.WebPages.HelperResult BeginMessage(EmphasisStyle messageType, IHtmlString heading) {
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {



#line 131 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml"
                                                                      

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "      <div class=\"panel ");



#line 132 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, string.Format("panel-{0}", messageType.ToString().ToLower()));

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n");



#line 133 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml"
            if (!string.IsNullOrEmpty(heading.ToHtmlString()))
            {

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "          <div class=\"panel-heading\"><h4 class=\"panel-title\">");



#line 135 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml"
                    WebViewPage.WriteTo(@__razor_helper_writer, heading);

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</h4></div>\r\n");



#line 136 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml"
            }

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "          <div class=\"panel-body\">\r\n");



#line 138 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml"

#line default
#line hidden

});

}
        public static System.Web.WebPages.HelperResult BeginFieldInternal(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, IReadonlyFieldConfiguration fieldConfiguration, ModelMetadata fieldMetadata, IHtmlString requiredDesignator)
        {
            return(new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 61 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"


#line default
#line hidden

                WebViewPage.WriteLiteralTo(@__razor_helper_writer, "            <dt>");



#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, labelHtml);

#line default
#line hidden



#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, new HtmlString(fieldMetadata != null && fieldMetadata.IsRequired ? requiredDesignator.ToHtmlString() : ""));

#line default
#line hidden

                WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</dt>\r\n");



                WebViewPage.WriteLiteralTo(@__razor_helper_writer, "            <dd");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, RenderIfNotEmpty(fieldConfiguration.FieldContainerClasses, item => new System.Web.WebPages.HelperResult(__razor_template_writer => {
#line default
#line hidden


                    WebViewPage.WriteLiteralTo(@__razor_template_writer, " class=\"");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                    WebViewPage.WriteTo(@__razor_template_writer, fieldConfiguration.FieldContainerClasses);

#line default
#line hidden

                    WebViewPage.WriteLiteralTo(@__razor_template_writer, "\"");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                })));

#line default
#line hidden

                WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n");



                WebViewPage.WriteLiteralTo(@__razor_helper_writer, "                ");



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, GetPrependedHtml(fieldConfiguration));

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, elementHtml);

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, GetAppendedHtml(fieldConfiguration));

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, GetHint(fieldConfiguration));

#line default
#line hidden

                WebViewPage.WriteLiteralTo(@__razor_helper_writer, " ");



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                WebViewPage.WriteTo(@__razor_helper_writer, validationHtml);

#line default
#line hidden

                WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n");



#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"

#line default
#line hidden
            }));
        }
 public HtmlListItem(IHtmlString contents)
 {
     _contents = contents.ToHtmlString();
 }
 public string CheckedFormat(IHtmlString name, int escape)
 {
     return CheckedFormat(name.ToHtmlString(), escape);
 }
 public static ComponentBuilder <TConfig, Content> Content <TConfig, TComponent>(this BootstrapHelper <TConfig, TComponent> helper, IHtmlString content)
     where TConfig : BootstrapConfig
     where TComponent : Component, ICanCreate <Content>
 {
     return(new ComponentBuilder <TConfig, Content>(helper.Config, new Content(helper, content.ToHtmlString())));
 }
 public string ClientTemplateFormat(IHtmlString name, int escape)
 {
     return ClientTemplateFormat(name.ToHtmlString(), escape);
 }
Beispiel #53
0
        /// <summary>
        /// Creates the HTML for a label.
        /// </summary>
        /// <param name="for">The name/id for the checkbox</param>
        /// <param name="labelText">The text inside the label</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the checkbox</param>
        /// <returns>The HTML for the checkbox</returns>
        public static IHtmlString BuildLabel(string @for, IHtmlString labelText, HtmlAttributes htmlAttributes)
        {
            var t = new TagBuilder("label");
            t.Attributes.Add("for", TagBuilder.CreateSanitizedId(@for));
            t.InnerHtml = labelText.ToHtmlString();

            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, false);

            return new HtmlString(t.ToString(TagRenderMode.Normal));
        }