internal static void CacheRenderedTag(string virtualPath, IHtmlString renderedTag) { RenderedTags[virtualPath] = renderedTag; var ctx = HttpContext.Current; var physicalPath = ctx.Server.MapPath(virtualPath); if (File.Exists(physicalPath)) { // add file watcher var fsw = new FileSystemWatcher( Path.GetDirectoryName(physicalPath), Path.GetFileName(physicalPath)); FileSystemWatchers.Add(fsw); // remove from lookup on change, to allow for creation of new md5 hash fsw.Renamed += (sender, args) => { RenderedTags.Remove(virtualPath); }; fsw.Changed += (sender, args) => { RenderedTags.Remove(virtualPath); }; fsw.Deleted += (sender, args) => { RenderedTags.Remove(virtualPath); }; fsw.Created += (sender, args) => { RenderedTags.Remove(virtualPath); }; fsw.EnableRaisingEvents = true; } }
/// <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); }
protected bool HasTag(IHtmlString html, string tag) { var doc = new HtmlDocument(); doc.LoadHtml(html.ToHtmlString()); var xpath = "//" + tag; return doc.DocumentNode.SelectSingleNode(xpath) != null; }
public static IHtmlString Concact(this IHtmlString html, IHtmlString other) { StringBuilder sb = new StringBuilder(); sb.Append(html.ToString()); sb.Append(other.ToString()); return new HtmlString(sb.ToString()); }
public static object Truncate(IHtmlString htmlString, int length) { if (htmlString.ToHtmlString().Length <= length) { return htmlString.ToHtmlString(); } return htmlString.ToHtmlString().Substring(0, length) + "..."; }
public FlowFormField(TextWriter writer, bool containsSection, string labelHtml, string elementHtml, string errorHtml = "", bool isValid = true, IHtmlString hint = null, string tip = null, bool hideTip = true, string hintClass = null, string parentClass = null, bool displayFieldName = true) { _containsSection = containsSection; _writer = writer; var generatedSection = HelperDefinitions.BeginField(containsSection, displayFieldName ? new HtmlString(labelHtml) : null, new HtmlString(elementHtml), new HtmlString(errorHtml), isValid, hint, tip, hideTip, hintClass, parentClass); _writer.Write(generatedSection.ToHtmlString()); }
public LabelAndControl(ViewContext viewContext, string labelFor, string labelText, IHtmlString control) { _labelFor = labelFor; _labelText = labelText; _control = control; _formLayout = viewContext.TempData["BootstrapFormLayout"].ToString(); HtmlAttributes["class"] = "control-group"; }
public static IHtmlString CreateField(this HtmlHelper html, string title, IHtmlString input, IHtmlString validation = null) { var result = string.Format(@"<div class=""control-group""><label for=""control-label"">{0}</label><div class=""controls"">{1}</div></div>", title, input); if (validation != null) { result = string.Format(@"<div class=""control-group""><label for=""control-label"">{0}</label><div class=""controls"">{1}<p>{2}</p></div></div>", title, input, validation); } return new HtmlString(result); }
public static System.Web.WebPages.HelperResult BeginSection(IHtmlString title, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) { #line default #line hidden return new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 14 "..\..\Templates\HtmlHelpers.cshtml" #line default #line hidden WriteLiteralTo(__razor_helper_writer, " <fieldset"); #line 15 "..\..\Templates\HtmlHelpers.cshtml" WriteTo(__razor_helper_writer, htmlAttributes); #line default #line hidden WriteLiteralTo(__razor_helper_writer, ">\r\n"); WriteLiteralTo(__razor_helper_writer, " <legend>"); #line 16 "..\..\Templates\HtmlHelpers.cshtml" WriteTo(__razor_helper_writer, title); #line default #line hidden WriteLiteralTo(__razor_helper_writer, "</legend>\r\n"); WriteLiteralTo(__razor_helper_writer, " "); #line 17 "..\..\Templates\HtmlHelpers.cshtml" WriteTo(__razor_helper_writer, leadingHtml); #line default #line hidden WriteLiteralTo(__razor_helper_writer, "\r\n"); WriteLiteralTo(__razor_helper_writer, " <dl>\r\n"); #line 19 "..\..\Templates\HtmlHelpers.cshtml" #line default #line hidden }); #line 19 "..\..\Templates\HtmlHelpers.cshtml" }
/// <summary> /// ����һ��MvcHtmlWrapper�������MvcHtmlWrapper��ֱ�ӷ��أ� /// �������������������MvcHtmlWrapper�� /// </summary> /// <param name="str">IHtmlString���ͣ�ʵ����ToHtmlString�ӿڵ�����</param> /// <returns></returns> public static MvcHtmlWrapper Create(IHtmlString str) { Contract.Requires(str != null); if (str is MvcHtmlWrapper) return str as MvcHtmlWrapper; if (str is MvcHtmlString) return new MvcHtmlWrapper(str); Contract.Assert(false); return null; }
protected void Page_Init(object sender, EventArgs e) { var env = AssemblyRegistration.Container.Resolve<IReactEnvironment>(); var objectModel = new { data = LoadJson() }; var reactComponent = env.CreateComponent("SlideshowUC", objectModel); var script = env.GetInitJavaScript(); SlideshowHtml = reactComponent.RenderHtml(); SlideshowJS = ReactInitJavaScript(script); }
public HelperResult RenderSection(string name, IHtmlString defaultContents) { if (this.IsSectionDefined(name)) { return this.RenderSection(name); } var result = new HelperResult((x) => x.Write(defaultContents.ToString())); return this.RenderSection(name, (x) => result); }
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, IHtmlString linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, Object> htmlAttributes) { var linkString = htmlHelper.ActionLink(guid, actionName, controllerName, routeValues, htmlAttributes); return ReplaceGuidWithRealText(linkText.ToString(), linkString); }
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()); } }
public static IHtmlString DemoRow(this HtmlHelper htmlHelper, string title, IHtmlString body, string title2 = null, IHtmlString body2 = null) { bool hasSecondCol = !title2.IsNullOrWhiteSpace(); var colClass = hasSecondCol ? "col-sm-6" : "col-xs-12"; string rowFormat = @"<div class=""row demoRow""> <div class=""{2} demoCol"">{0}</div> <div class=""{2} demoCol"">{1}</div> </div>"; return htmlHelper.Raw(string.Format(rowFormat, htmlHelper.DemoPanel(title, body), hasSecondCol ? htmlHelper.DemoPanel(title2, body2) : new HtmlString(""), colClass)); }
public void ConfigName(IHtmlString name) { this.FieldNamePrefix = name.ToString(); if (String.IsNullOrEmpty(this.FieldNamePrefix)) { this.FieldNamePrefix = String.Empty; } else { this.FieldNamePrefix = String.Format("{0}.", this.FieldNamePrefix); } this.FieldIdPrefix = this.FieldNamePrefix.Replace(".", "_").Replace("]", "_").Replace("[", "_"); }
protected BlogItemViewModelBase(BlogEntry blog) { ID = blog.ID; Title = blog.Title; Category = blog.Category.Name; Tags = blog.Tags.Select(t => new BlogTagViewModel(t.Name)); PostedAt = blog.PostedAt; Author = blog.Author.FullName; Content = new HtmlString(blog.Text); _url = new BlogItemLink(ID, Title); }
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, IHtmlString linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, Object routeValues, Object htmlAttributes) { var linkString = htmlHelper.ActionLink(guid, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttributes); return ReplaceGuidWithRealText(linkText.ToString(), linkString); }
public static IHtmlString DemoPanel(this HtmlHelper htmlHelper, string title, IHtmlString body) { const string panelFormat = @"<div class=""demoPanel""> <div class=""panel-heading""> <div class=""panel-title""> <b>{0}</b> </div> </div> <div class=""panel-body"">{1}</div> </div>"; return htmlHelper.Raw(string.Format(panelFormat, htmlHelper.Raw(title), body)); }
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)); }
/// <summary> /// Creates the HTML for a submit <button>. /// </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)); }
public static System.Web.WebPages.HelperResult DropdownLinksButton(string buttonTitle, IHtmlString links) { return new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 4 "..\..\Helpers\BootstrapHelper.cshtml" #line default #line hidden #line 4 "..\..\Helpers\BootstrapHelper.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, DropdownLinksButton(buttonTitle,item => new System.Web.WebPages.HelperResult(__razor_template_writer => { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_template_writer, " "); #line 4 "..\..\Helpers\BootstrapHelper.cshtml" WebViewPage.WriteTo(@__razor_template_writer, links); #line default #line hidden #line 4 "..\..\Helpers\BootstrapHelper.cshtml" }), null)); #line default #line hidden #line 4 "..\..\Helpers\BootstrapHelper.cshtml" #line default #line hidden }); }
public static IHtmlString MenuItem(this HtmlHelper html, String liId, String menuItemName, String spanCssClass, IHtmlString content) { var links = html.ViewContext.ViewData["UrlForPage"] as Func<string, string> ?? (x => x); var link = (links(menuItemName) ?? String.Empty).Trim(); ////Hot Fix for weibo: //if (link.Contains("rss.sinaapp.com")) //{ // var contentForRender = string.Format("<a onclick=\"javascript:_gaq.push(['_trackPageview', '{0}']);\" href='{1}' target=\"_blank\">{2}</a>", link, link, content); //} if (link.Length > 5 || link == "true") { var linkForRender = String.Format("<li id=\"{0}\"><span class=\"{1}\">{2}</span></li>", liId, spanCssClass, content); return html.Raw(linkForRender); } return html.Raw(String.Empty); }
/// <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> /// 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)); }
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> /// 为当前表中所有单元素添加搜索条件 /// </summary> /// <param name="str"></param> /// <param name="method">搜索方法</param> /// <param name="prefix">前缀</param> /// <returns></returns> public static MvcHtmlWrapper ForSearchAll(this IHtmlString str, SearchMethod?method, string prefix = "") { var wrapper = MvcHtmlWrapper.Create(str); Contract.Assert(null != wrapper); if (!method.HasValue) { return(wrapper); } var html = wrapper.HtmlString; #region 如果是CheckBox,则去掉hidden if (html.Contains("type=\"checkbox\"")) { var checkMatch = Regex.Match(html, "<input name=\"[^\"]+\" type=\"hidden\" [^>]+ />"); if (checkMatch.Success) { wrapper.Add(checkMatch.Groups[0].Value, String.Empty); } } #endregion #region 替换掉Name var namePrefix = new StringBuilder(); namePrefix.AppendFormat("[{0}]", method);//添加筛选谓词 if (!String.IsNullOrWhiteSpace(prefix)) { namePrefix.AppendFormat("({0})", prefix);//添加前缀 } var matches = Regex.Matches(html, "name=\"(?<name>[^\"]+)\""); foreach (Match match in matches) { wrapper.Add(match.Groups[0].Value, String.Format("name=\"{1}{0}\"", match.Groups[1].Value, namePrefix)); } #endregion return(wrapper); }
public virtual string GetEditable(Context context, string key, EditableOptions options) { if (context == null) { throw new ArgumentNullException("context"); } if (key == null) { throw new ArgumentNullException("key"); } if (options == null) { throw new ArgumentNullException("options"); } using (var serviceContext = PortalViewContext.CreateServiceContext()) { var attachedEntity = serviceContext.MergeClone(Entity.Attributes.ContainsKey(key) ? Entity : FullEntity); var portalViewEntity = PortalViewContext.GetEntity(serviceContext, attachedEntity); IHtmlString html = null; context.Stack(() => { html = Html.AttributeInternal( portalViewEntity.GetAttribute(key), options.Type ?? "html", options.Title, options.Escape.GetValueOrDefault(false), options.Tag ?? "div", options.CssClass, options.Liquid.GetValueOrDefault(true), context, options.Default); }); return(html == null ? null : html.ToString()); } }
/// <summary> /// Renderiza los archivos js optimizados segun la vista actual /// </summary> /// <param name="scriptView">Vista del script</param> /// <returns>Indicador</returns> public static IHtmlString RenderViewJs(string scriptView = null) { if (string.IsNullOrWhiteSpace(scriptView)) { var actionName = HttpContext.Current.Request.RequestContext.RouteData.Values["action"] ?? ""; var controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"] ?? ""; var area = HttpContext.Current.Request.RequestContext.RouteData.DataTokens["area"] ?? "general"; scriptView = area.ToString().ToLower() + controllerName.ToString().ToLower() + actionName.ToString().ToLower(); } scriptView = "~/Scripts/" + scriptView; var exists = BundleTable.Bundles.GetRegisteredBundles().Any(b => b.Path == scriptView); IHtmlString result = null; if (exists) { result = Scripts.Render(scriptView); } return(result); }
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()); }
/// <summary> /// Checks for content /// </summary> /// <param name="HtmlString">String to test</param> /// <param name="EmptyParagraphsIsNull">Should a string made up of only empty <p> 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); }
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)); }
public static System.Web.WebPages.HelperResult MessageParagraph(IHtmlString paragraph) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 108 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <p>\r\n"); WebViewPage.WriteLiteralTo(@__razor_helper_writer, " "); #line 110 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, paragraph); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n"); WebViewPage.WriteLiteralTo(@__razor_helper_writer, " </p>\r\n"); #line 112 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden })); }
private static HelperResult Format(Func <dynamic, object> format, dynamic arg) { var result = format(arg); return(new HelperResult(tw => { var helper = result as HelperResult; if (helper != null) { helper.WriteTo(tw); return; } IHtmlString htmlString = result as IHtmlString; if (htmlString != null) { tw.Write(htmlString); return; } if (result != null) { tw.Write(HttpUtility.HtmlEncode(result)); } })); }
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); }
/// <summary> /// Renders the output for the rebel editor markup /// </summary> /// <param name="label">The label.</param> /// <param name="editor">The editor.</param> /// <param name="validationMessage">The validation message.</param> /// <param name="description">The description.</param> /// <param name="tooltip">The tooltip.</param> /// <returns></returns> private static IHtmlString UmbEditorMarkup(IHtmlString label, IHtmlString editor, IHtmlString validationMessage = null, string description = "", string tooltip = "") { var sb = new StringBuilder(); sb.AppendLine("<div class='property-editor clearfix'>"); if (validationMessage != null) { sb.Append(validationMessage); } sb.AppendLine("<div class='property-editor-label' title='" + tooltip + "'>"); sb.Append(label); if (!description.IsNullOrWhiteSpace()) { sb.AppendLine("<small>"); sb.Append(description); sb.AppendLine("</small>"); } sb.AppendLine("</div>"); sb.AppendLine("<div class='property-editor-control'>"); sb.Append(editor); sb.AppendLine("</div>"); sb.AppendLine("</div>"); return(new HtmlString(sb.ToString())); }
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 IHtmlString LoadAbsoluteStyles(this IFrontHtmlHelper frontHtml, string baseUri, string themeName) { IEnumerable<IHtmlString> styles = new IHtmlString[0]; var key = "___RegisteredSystemStyles____"; if (frontHtml.Html.ViewContext.HttpContext.Items[key] == null) { styles = styles //.Concat(this.IncludeModuleThemeStyles(baseUri)) //.Concat(this.IncludeInlineEditingStyles(baseUri)) //.Concat(this.IncludeStyleEditingStyles(baseUri)) .Distinct(new IHtmlStringComparer()); //if (this.PageContext.PageRequestContext.Site.EnableJquery) //{ // styles = styles.Concat(new[] { Kooboo.Common.Web.WebResourceLoader.MvcExtensions.ExternalResources(this.Html, null, "jQuery-Styles", null, baseUri) }); //} styles = styles.Concat(frontHtml.Page_Context.Styles); frontHtml.Html.ViewContext.HttpContext.Items[key] = new object(); } styles = styles.Concat(IncludeThemeStyles(frontHtml, themeName, baseUri)); return new AggregateHtmlString(styles); }
public void NavigationPagerItemsPositionIsRight_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", NavigationPagerItemsPosition = PagerItemsPosition.Right }, 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("1"); for (int i = 2; i <= 10; i++) { sb.AppendFormat(linkFormat, i, i); } sb.AppendFormat(linkFormat, 11, "...").Append("First").Append("Prev"); sb.AppendFormat(linkFormat, 2, "Next"); sb.AppendFormat(linkFormat, 11, "Last"); sb.Append("</div>").Append(TestHelper.CopyrightText); Assert.AreEqual(html.ToHtmlString(), sb.ToString()); }
/// <summary> /// Insert any html content /// </summary> /// <param name="html"></param> public void Element(IHtmlString html) { InnerHtml += html; }
public PeopleSetPropertiesBuilder(IHtmlString outermostContainer) : base(outermostContainer) { }
public static System.Web.WebPages.HelperResult BeginSection(IHtmlString heading, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 12 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <fieldset"); #line 13 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, htmlAttributes); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n"); #line 14 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" if (heading != null && !string.IsNullOrWhiteSpace(heading.ToString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <legend>"); #line 16 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, heading); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</legend>\r\n"); #line 17 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" } if (leadingHtml != null && !string.IsNullOrWhiteSpace(leadingHtml.ToString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " "); #line 20 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, leadingHtml); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n"); #line 21 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" } #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <dl>\r\n"); #line 23 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden })); }
public static System.Web.WebPages.HelperResult BeginMessage(MessageType messageType, IHtmlString heading) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 94 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div class=\""); #line 95 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, string.Format("{0}{1}", messageType.ToString().ToLower(), "_message")); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n"); #line 96 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" if (!string.IsNullOrEmpty(heading.ToHtmlString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <h3>"); #line 98 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, heading); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</h3>\r\n"); #line 99 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" } #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div class=\"message\">\r\n"); #line 101 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden })); }
public static System.Web.WebPages.HelperResult BeginField(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, ModelMetadata fieldMetadata, IReadonlyFieldConfiguration fieldConfiguration, IHtmlString requiredDesignator) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 73 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden #line 74 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, BeginFieldInternal(labelHtml, elementHtml, validationHtml, fieldConfiguration, fieldMetadata, requiredDesignator)); #line default #line hidden #line 74 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <dl>\r\n"); #line 76 "..\..\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) { 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 BeginNestedSection(IHtmlString heading, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 26 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" if (heading != null && !string.IsNullOrWhiteSpace(heading.ToString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <dt>"); #line 29 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, heading); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</dt>\r\n"); #line 30 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" } #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <dd>\r\n"); #line 32 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" if (leadingHtml != null && !string.IsNullOrWhiteSpace(leadingHtml.ToString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " "); #line 34 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, leadingHtml); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n"); #line 35 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" } #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <dl"); #line 36 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, htmlAttributes); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n"); #line 37 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml" #line default #line hidden })); }
public string ClientTemplateFormat(IHtmlString name, int escape) { return ClientTemplateFormat(name.ToHtmlString(), escape); }
public string CheckedFormat(IHtmlString name, int escape) { return CheckedFormat(name.ToHtmlString(), escape); }
/// <summary> /// Returns textIfTrue if the key exists in the ViewDataDictionary and if its true, otherwise empty MvcHtmlString /// </summary> public static IHtmlString WriteIf(this ViewDataDictionary viewData, string key, IHtmlString textIfTrue) { return(viewData.WriteIf(key, textIfTrue, MvcHtmlString.Empty)); }
/// <summary> /// Truncates a string on word breaks /// </summary> public static string Truncate(this UmbracoHelper helper, IHtmlString s, int maxLength) { return(helper.TruncateWordBreak(s.ToString(), maxLength)); }
/// <summary> /// Highlights all occurances of the search terms in a body of text /// </summary> public static IHtmlString Highlight(this UmbracoHelper helper, IHtmlString s, IEnumerable <string> terms) { return(new HtmlString(helper.Highlight(s.ToString(), terms))); }
/// <summary> /// Creates a nested form section. /// </summary> /// <example> /// @using (var s = f.BeginSection("Section heading")) { /// using (var ss = s.BeginSection("Nested section heading")) { /// @ss.FieldFor(m => m.FirstName) /// } /// } /// </example> /// <typeparam name="TModel">The view model type for the current view</typeparam> /// <param name="section">The section the section is being created under</param> /// <param name="heading">The heading for the section</param> /// <param name="leadingHtml">Any HTML to output at the start of the section</param> /// <param name="htmlAttributes">Any HTML attributes to apply to the section container</param> /// <returns>The nested form section</returns> public static Section <TModel> BeginSection <TModel>(this Section <TModel> section, string heading = null, IHtmlString leadingHtml = null, HtmlAttributes htmlAttributes = null) { return(new Section <TModel>(section.Form, heading.ToHtml(), true, leadingHtml, htmlAttributes)); }
/// <summary> /// Returns textIfTrue if the key exists in the ViewDataDictionary and if its true, otherwise textIfFalse /// </summary> public static IHtmlString WriteIf(this ViewDataDictionary viewData, string key, IHtmlString textIfTrue, IHtmlString textIfFalse) { if (GetDefault <bool>(viewData, key)) { return(textIfTrue); } else { return(textIfFalse); } }
/// <summary> /// Outputs a field with passed in HTML. /// </summary> /// <param name="labelHtml">The HTML for the label part of the field</param> /// <param name="elementHtml">The HTML for the field element part of the field</param> /// <param name="validationHtml">The HTML for the validation markup part of the field</param> /// <param name="metadata">Any field metadata</param> /// <param name="isValid">Whether or not the field is valid</param> /// <returns>A field configuration that can be used to output the field as well as configure it fluently</returns> public IFieldConfiguration Field(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml = null, ModelMetadata metadata = null, bool isValid = true) { var fc = new FieldConfiguration(); fc.SetField(() => Form.Template.Field(labelHtml, elementHtml, validationHtml, metadata, new ReadonlyFieldConfiguration(fc), isValid)); return(fc); }
public string RawClientTemplateFormat(IHtmlString name, int espace) { return RawClientTemplateFormat(name.ToHtmlString(), espace); }
/// <summary> /// Creates a top-level form section. /// </summary> /// <example> /// @using (var s = f.BeginSection("Section heading")) { /// @s.FieldFor(m => m.FirstName) /// } /// </example> /// <typeparam name="TModel">The view model type for the current view</typeparam> /// <param name="form">The form the section is being created in</param> /// <param name="heading">The heading for the section</param> /// <param name="leadingHtml">Any HTML to output at the start of the section</param> /// <param name="htmlAttributes">Any HTML attributes to apply to the section container</param> /// <returns>The form section</returns> public static Section <TModel> BeginSection <TModel>(this IForm <TModel> form, string heading = null, IHtmlString leadingHtml = null, HtmlAttributes htmlAttributes = null) { return(new Section <TModel>(form, heading.ToHtml(), false, leadingHtml, htmlAttributes)); }
public string CheckFormat(IHtmlString name, string trueValue, string falseValue, int escape) { return CheckFormat(name.ToHtmlString(), trueValue, falseValue, escape); }
/// <summary> /// Writes the <see cref="IHtmlString"/>. /// </summary> /// <param name="result"></param> public virtual void Write( IHtmlString result) { WriteLiteral((object)result); }
public static void AreEqual(IHtmlString expected, IHtmlString actual) { HtmlAssert.AreEqual(expected.ToString(), actual.ToString()); }
/// <summary> /// Writes the <see cref="IHtmlString"/>. /// </summary> /// <param name="writer"></param> /// <param name="result"></param> public virtual void WriteTo( TextWriter writer, IHtmlString result) { WriteLiteralTo(writer, (object)result); }