/// <summary>
 /// Splits the content to list DOM.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="mvcHtmlHelper">The MVC HTML helper.</param>
 /// <param name="text">The text.</param>
 /// <param name="seperators">The seperators.</param>
 /// <param name="ulClass">The ul class.</param>
 /// <param name="liClass">The li class.</param>
 /// <returns></returns>
 public static IHtmlString SplitContentToListDom <TModel>(this HtmlHelper <TModel> mvcHtmlHelper, string text, string[] seperators, string ulClass = null, string liClass = null)
 {
     return(mvcHtmlHelper?.Raw(HtmlViewHelper.SplitToListRaw(HtmlViewHelper.TryStructurizeListContent(text), seperators, ulClass, liClass)));
 }
 /// <summary>
 /// Renders the selected attribute.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="mvcHtmlHelper">The MVC HTML helper.</param>
 /// <param name="isSelected">The is selected.</param>
 /// <returns></returns>
 public static IHtmlString RenderSelectedAttribute <TModel>(this HtmlHelper <TModel> mvcHtmlHelper, bool?isSelected)
 {
     return(mvcHtmlHelper?.Raw((isSelected ?? false) ? " selected" : string.Empty));
 }
Example #3
0
 public static IHtmlString ByCondition(this HtmlHelper helper, bool condition, string value)
 {
     return(helper.Raw(condition ? value : string.Empty));
 }
 /// <summary>
 /// Renders the determinable icon DOM.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="mvcHtmlHelper">The MVC HTML helper.</param>
 /// <param name="needShow">The need show.</param>
 /// <param name="classNames">The class names.</param>
 /// <returns></returns>
 public static IHtmlString RenderDeterminableIconDom <TModel>(this HtmlHelper <TModel> mvcHtmlHelper, bool?needShow, string classNames)
 {
     return(mvcHtmlHelper?.Raw((needShow ?? false) ? string.Format("<i class=\"{0}\"></i>", classNames) : string.Empty));
 }
Example #5
0
 public static IHtmlString PreFormattedText(this HtmlHelper self, string text)
 {
     return(self.Raw(HttpUtility.HtmlEncode(text).Replace("\n", "<br />").Replace("  ", "&nbsp; ")));
 }
 /// <summary>
 /// 插入脚本扩展
 /// </summary>
 /// <param name="html">Reference to the HtmlHelper object</param>
 /// <param name="url">URL of the script file</param>
 public static IHtmlString IncludeScript(this HtmlHelper html, string url)
 {
     return(html.Raw("<script src=\"" + GetPathWithVersioning(url) + "\" type=\"text/javascript\"></script>"));
 }
Example #7
0
 public IHtmlString Raw(string value) => HtmlHelper.Raw(value);
 public static IHtmlString IsChecked(this HtmlHelper helper, bool isChecked)
 {
     return(helper.Raw(isChecked ? "checked=\"checked\"" : string.Empty));
 }
 public static IHtmlString RenderMarkdown(this HtmlHelper htmlHelper, string markdown)
 {
     return(htmlHelper.Raw(new Markdown().Transform(markdown)));
 }
Example #10
0
        /// <summary>
        /// Provides server-side include functionality
        /// </summary>
        /// <param name="html"></param>
        /// <param name="fileAndPath"></param>
        /// <returns>The contents of the file(s) that are requested</returns>
        /// <remarks>
        /// MVC does not support server-side includes on its own, so this method provides that functionality. It will include
        /// the file specified - including any nested server-side includes that are present in that file (and so on, etc.)
        /// </remarks>
        public static IHtmlString Include(this HtmlHelper html, string fileAndPath)
        {
            string fileContents = ProcessIncludeFile(fileAndPath, html.ViewContext.HttpContext.Server);

            return(html.Raw(fileContents));
        }
Example #11
0
        public static IHtmlString CheckboxListItem(this HtmlHelper helper, string name, string value)
        {
            string html = @"<a href=""#"" class=""list-group-item""><div class=""checkbox""><label><input type=""checkbox"" name=""{0}"" id=""{0}.{1}"" value=""{1}"" />{1}</label></div></a>";

            return(helper.Raw(string.Format(html, name, value)));
        }
Example #12
0
 public static IHtmlString EndBsGroup(this HtmlHelper html, string tagName = DefaultTagName)
 {
     return(html.Raw(new TagBuilder(tagName).ToString(TagRenderMode.EndTag)));
 }
Example #13
0
        public override void Execute()
        {
            WriteLiteral("\r\n");



            #line 9 "..\..\Dashboard\Pages\ServersPage.cshtml"

            Layout = new LayoutPage {
                Title = "Servers"
            };

            var monitor = JobStorage.Current.GetMonitoringApi();
            IList <ServerDto> servers = monitor.Servers();



            #line default
            #line hidden
            WriteLiteral("\r\n");



            #line 16 "..\..\Dashboard\Pages\ServersPage.cshtml"
            if (servers.Count == 0)
            {
            #line default
            #line hidden
                WriteLiteral("    <div class=\"alert alert-warning\">\r\n        There are no active servers. Backg" +
                             "round tasks will not be processed.\r\n    </div>\r\n");



            #line 21 "..\..\Dashboard\Pages\ServersPage.cshtml"
            }
            else
            {
            #line default
            #line hidden
                WriteLiteral(@"    <table class=""table"">
        <thead>
            <tr>
                <th>Name</th>
                <th>Workers</th>
                <th>Queues</th>
                <th>Started</th>
                <th>Heartbeat</th>
            </tr>
        </thead>
        <tbody>
");



            #line 35 "..\..\Dashboard\Pages\ServersPage.cshtml"
                foreach (var server in servers)
                {
            #line default
            #line hidden
                    WriteLiteral("                <tr>\r\n                    <td>");



            #line 38 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    Write(server.Name.ToUpperInvariant());


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                    <td>");



            #line 39 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    Write(server.WorkersCount);


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                    <td>");



            #line 40 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    Write(HtmlHelper.Raw(String.Join(" ", server.Queues.Select(HtmlHelper.QueueLabel))));


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                    <td data-moment=\"");



            #line 41 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    Write(JobHelper.ToTimestamp(server.StartedAt));


            #line default
            #line hidden
                    WriteLiteral("\">");



            #line 41 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    Write(server.StartedAt);


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                    <td>\r\n");



            #line 43 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    if (server.Heartbeat.HasValue)
                    {
            #line default
            #line hidden
                        WriteLiteral("                            <span data-moment=\"");



            #line 45 "..\..\Dashboard\Pages\ServersPage.cshtml"
                        Write(JobHelper.ToTimestamp(server.Heartbeat.Value));


            #line default
            #line hidden
                        WriteLiteral("\">\r\n                                ");



            #line 46 "..\..\Dashboard\Pages\ServersPage.cshtml"
                        Write(server.Heartbeat);


            #line default
            #line hidden
                        WriteLiteral("\r\n                            </span>\r\n");



            #line 48 "..\..\Dashboard\Pages\ServersPage.cshtml"
                    }


            #line default
            #line hidden
                    WriteLiteral("                    </td>\r\n                </tr>\r\n");



            #line 51 "..\..\Dashboard\Pages\ServersPage.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("        </tbody>\r\n    </table>\r\n");



            #line 54 "..\..\Dashboard\Pages\ServersPage.cshtml"
            }

            #line default
            #line hidden
        }
Example #14
0
        public void RawReturnsWrapperMarkup()
        {
            // Arrange
            var viewContext = new Mock<ViewContext>().Object;
            var viewDataContainer = new Mock<IViewDataContainer>().Object;
            var htmlHelper = new HtmlHelper(viewContext, viewDataContainer);
            string markup = "<b>bold</b>";

            // Act
            IHtmlString markupHtml = htmlHelper.Raw(markup);

            // Assert
            Assert.Equal("<b>bold</b>", markupHtml.ToString());
            Assert.Equal("<b>bold</b>", markupHtml.ToHtmlString());
        }
Example #15
0
 public IHtmlString Raw(object value) => HtmlHelper.Raw(value);
Example #16
0
 public static IHtmlString Json(this HtmlHelper helper, object data)
 {
     return(helper.Raw(System.Web.Helpers.Json.Encode(data)));
 }
Example #17
0
 /// <summary>
 /// Produces the tag for inline image test test 3
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="contentId">e.g. logo</param>
 /// <param name="alt">e.g. Company Logo</param>
 /// <returns><img src="cid:logo" alt="Company Logo"/></returns>
 public static IHtmlString InlineImage(this HtmlHelper htmlHelper, string contentId, string alt = "")
 {
     return(htmlHelper.Raw(string.Format("<img src=\"cid:{0}\" alt=\"{1}\"/>", contentId, alt)));
 }
Example #18
0
 public static IHtmlString GetBaseUri(this HtmlHelper htmlHelper, HttpContext httpContext)
 {
     return(htmlHelper.Raw(httpContext.Request.Url.GetLeftPart(UriPartial.Authority)));
 }
Example #19
0
 /// <summary>
 /// Html validation message
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TProperty"></typeparam>
 /// <param name="helper"></param>
 /// <param name="expression"></param>
 /// <returns></returns>
 public static IHtmlString HtmlValidationMessageFor <TModel, TProperty>(this HtmlHelper <TModel> helper,
                                                                        Expression <Func <TModel, TProperty> > expression
                                                                        )
 {
     return(helper.Raw(HttpUtility.HtmlDecode(helper.ValidationMessageFor(expression).ToHtmlString())));
 }
Example #20
0
 public static IHtmlString ToJSON(this HtmlHelper html, Object input)
 {
     return(html.Raw(ToJSON(input)));
 }
Example #21
0
 /// <summary>
 /// Html validation message
 /// </summary>
 /// <param name="helper"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static IHtmlString HtmlValidationMessage(this HtmlHelper helper, string name)
 {
     return(helper.Raw(HttpUtility.HtmlDecode(helper.ValidationMessage(name).ToHtmlString())));
 }
 /// <summary>
 /// 插入样式文件
 /// </summary>
 /// <param name="html">Reference to the HtmlHelper object</param>
 /// <param name="url">URL of the style file</param>
 public static IHtmlString IncludeStyle(this HtmlHelper html, string url)
 {
     return(html.Raw("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + GetPathWithVersioning(url) + "\" />"));
 }
Example #23
0
        /// <summary>
        /// Returns a raw JSON encoded string with doubly encoded escape sequences. This is necessary for the JSON parser.
        /// </summary>
        public static IHtmlString RawJson(this HtmlHelper htmlHelper, object value)
        {
            var rawJson = htmlHelper.Raw(Json.Encode(value)).ToHtmlString().Replace("\\", "\\\\");

            return(new HtmlString(rawJson));
        }
        public static IHtmlString Code(this HtmlHelper htmlHelper, string code)
        {
            int num = 0;

            string[] lines = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            if (lines.Length > 1)
            {
                num = lines
                      .Skip(1)
                      .Min(x =>
                {
                    int index = x.ToList().FindIndex(c => c != ' ');
                    return(index == -1 ? Int32.MaxValue : index);
                });
            }
            string spaces = new String(' ', num);

            code = code.Replace(Environment.NewLine + spaces, Environment.NewLine);
            return(new HtmlString(string.Format(@"<pre class='prettyprint'>{0}</pre>", htmlHelper.Raw(HttpUtility.HtmlEncode(code)))));
        }
 public static IHtmlString JsonFor <T>(this HtmlHelper helper, T obj)
 {
     return(helper.Raw(obj.ToJson()));
 }
 /// <summary>
 /// Splits the content to list DOM.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="mvcHtmlHelper">The MVC HTML helper.</param>
 /// <param name="text">The text.</param>
 /// <param name="seperator">The seperator.</param>
 /// <param name="ulClass">The ul class.</param>
 /// <param name="liClass">The li class.</param>
 /// <param name="itemTextBuilder">The item text builder.</param>
 /// <returns></returns>
 public static IHtmlString SplitContentToListDom <TModel>(this HtmlHelper <TModel> mvcHtmlHelper, string text, Func <string, IEnumerable <string> > seperator, string ulClass = null, string liClass = null, Func <string, string> itemTextBuilder = null)
 {
     return(mvcHtmlHelper?.Raw(HtmlViewHelper.SplitToListRaw(HtmlViewHelper.TryStructurizeListContent(text), seperator, ulClass, liClass, itemTextBuilder)));
 }
Example #27
0
 public static IHtmlString PreserveNewLines(this HtmlHelper htmlHelper, string message)
 {
     return(message == null ? null : htmlHelper.Raw(htmlHelper.Encode(message).Replace("\n", "<br/>")));
 }
 /// <summary>
 /// Renders the read only attribute.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="mvcHtmlHelper">The MVC HTML helper.</param>
 /// <param name="isReadOnly">if set to <c>true</c> [is read only].</param>
 /// <returns></returns>
 public static IHtmlString RenderReadOnlyAttribute <TModel>(this HtmlHelper <TModel> mvcHtmlHelper, bool?isReadOnly)
 {
     return(mvcHtmlHelper?.Raw((isReadOnly ?? false) ? " readonly" : string.Empty));
 }
 public static IHtmlString IsSelected(this HtmlHelper helper, bool isSelected)
 {
     return(helper.Raw(isSelected ? "selected=\"selected\"" : string.Empty));
 }
Example #30
0
        public void RawReturnsWrapperMarkupOfObject()
        {
            // Arrange
            var viewContext = new Mock<ViewContext>().Object;
            var viewDataContainer = new Mock<IViewDataContainer>().Object;
            var htmlHelper = new HtmlHelper(viewContext, viewDataContainer);
            ObjectWithWrapperMarkup obj = new ObjectWithWrapperMarkup();

            // Act
            IHtmlString markupHtml = htmlHelper.Raw(obj);

            // Assert
            Assert.Equal("<b>boldFromObject</b>", markupHtml.ToString());
            Assert.Equal("<b>boldFromObject</b>", markupHtml.ToHtmlString());
        }
 public static IHtmlString IsDisabled(this HtmlHelper helper, bool isDisabled)
 {
     return(helper.Raw(isDisabled ? "disabled=\"disabled\"" : string.Empty));
 }
Example #32
0
        public void RawAllowsNullValue()
        {
            // Arrange
            var viewContext = new Mock<ViewContext>().Object;
            var viewDataContainer = new Mock<IViewDataContainer>().Object;
            var htmlHelper = new HtmlHelper(viewContext, viewDataContainer);

            // Act
            IHtmlString markupHtml = htmlHelper.Raw(null);

            // Assert
            Assert.Equal(null, markupHtml.ToString());
            Assert.Equal(null, markupHtml.ToHtmlString());
        }
        public static IHtmlString SpanInputFor <TModel, TProperty>(this HtmlHelper <TModel> helper, int span,
                                                                   Expression <Func <TModel, TProperty> > expression,
                                                                   IDictionary <string, object> spanAttributes  = null,
                                                                   IDictionary <string, object> inputAttributes = null,
                                                                   IDictionary <string, object> labelAttributes = null,
                                                                   IDictionary <string, object> abbrAttributes  = null,
                                                                   string inputType = null)
        {
            if (span < 1 || span > 12)
            {
                throw new ArgumentOutOfRangeException("span", "Bootstrap span must be between 1 and 12");
            }

            var attributes  = default(IDictionary <string, object>);
            var additionals = default(IDictionary <string, object>);

            var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);

            var abbr = string.Empty;

            if (metadata.IsRequired)
            {
                additionals = metadata.AdditionalValues.ContainsKey(BootstrapHtmlExtensions.AbbrKey)
                                        ? (IDictionary <string, object>)metadata.AdditionalValues[BootstrapHtmlExtensions.AbbrKey]
                                        : null;

                attributes = BootstrapHtmlExtensions.MergeAttributes(BootstrapHtmlExtensions.DefaultAbbrAttributes,
                                                                     additionals,
                                                                     abbrAttributes);

                if (attributes["title"].ToString().IndexOf("{0}", StringComparison.CurrentCulture) > 0)
                {
                    attributes["title"] = string.Format(attributes["title"].ToString(), metadata.DisplayName ?? metadata.PropertyName);
                }

                abbr = string.Format(@"<abbr {0}>*</abbr>",
                                     attributes.Aggregate(string.Empty, (a, b) =>
                                                          string.Concat(a, string.Format(@"{0}=""{1}""", b.Key, b.Value))));
            }

            additionals = metadata.AdditionalValues.ContainsKey(BootstrapHtmlExtensions.LabelKey)
                                ? (IDictionary <string, object>)metadata.AdditionalValues[BootstrapHtmlExtensions.LabelKey]
                                : null;

            attributes = BootstrapHtmlExtensions.MergeAttributes(BootstrapHtmlExtensions.DefaultLabelAttributes,
                                                                 additionals,
                                                                 labelAttributes);

            var label = string.Format(@"<label {0}>{1} {2}</label>",
                                      attributes.Aggregate(string.Empty, (a, b) =>
                                                           string.Concat(a, string.Format(@"{0}=""{1}""", b.Key, b.Value))),
                                      helper.DisplayNameFor(expression),
                                      abbr);

            additionals = metadata.AdditionalValues.ContainsKey(BootstrapHtmlExtensions.InputKey)
                                ? (IDictionary <string, object>)metadata.AdditionalValues[BootstrapHtmlExtensions.InputKey]
                                : null;

            attributes = BootstrapHtmlExtensions.MergeAttributes(BootstrapHtmlExtensions.DefaultInputAttributes,
                                                                 additionals,
                                                                 inputAttributes);

            var input = default(MvcHtmlString);

            switch (inputType)
            {
            case "DatePicker":
                attributes = BootstrapHtmlExtensions.MergeAttributes(BootstrapHtmlExtensions.DefaultDatePickerAttributes,
                                                                     additionals,
                                                                     inputAttributes);

                input = helper.TextBoxFor(expression, default(string), attributes);
                break;

            case "DropDownList":
                attributes = BootstrapHtmlExtensions.MergeAttributes(BootstrapHtmlExtensions.DefaultSelect2Attributes,
                                                                     additionals,
                                                                     inputAttributes);

                input = helper.TextBoxFor(expression, default(string), attributes);
                break;

            case "ListBox":
                input = helper.ListBoxFor(expression, new List <SelectListItem>(), attributes);
                break;

            case "TextArea":
                input = helper.TextAreaFor(expression, attributes);
                break;

            default:
                input = helper.TextBoxFor(expression, default(string), attributes);
                break;
            }

            additionals = metadata.AdditionalValues.ContainsKey(BootstrapHtmlExtensions.SpanKey)
                                ? (IDictionary <string, object>)metadata.AdditionalValues[BootstrapHtmlExtensions.SpanKey]
                                : null;

            attributes = BootstrapHtmlExtensions.MergeAttributes(BootstrapHtmlExtensions.DefaultSpanAttributes,
                                                                 additionals,
                                                                 spanAttributes);

            attributes["class"] = Regex.Replace(attributes["class"].ToString(), @"col\-md\-([{]\d*[}]|\d*)", string.Format("col-md-{0}", span));

            return(helper.Raw(string.Format(@"<div {0}>{1}{2}</div>",
                                            attributes.Aggregate(string.Empty, (a, b) => string.Concat(a, string.Format(@"{0}=""{1}""", b.Key, b.Value))),
                                            label, input)));
        }