public static void AddElementName(ElementRequest request, HtmlTag tag) { if (tag.IsInputElement()) { tag.Attr(HtmlAttributeConstants.Name, request.ElementId); } }
public static HtmlString AdminForm(DocumentNode Model, string adminUrl, string divClassName = "") { var div = new HtmlTag("div"); if (divClassName != "") div.AddClass(divClassName); var form = new FormTag().Method("post").Action("#"); form.Append(HtmlBuilder.HtmlTagLabelInput("Name (header)", "name", Model.Name)); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "update").Attr("value", "Update")); form.Append(HtmlBuilder.HtmlTagLabelCheckbox("Hide header", "hideHeader", Model.HideHeader)); form.Append(HtmlBuilder.HtmlTagLabelTextArea("Body text", "body", Model.Body)); form.Append(HtmlBuilder.HtmlTagLabelTextArea("Extra content 1", "extraContent1", Model.ExtraContent1, 5)); //form.Append(HtmlBuilder.HtmlTagLabelTextArea("Extra content 2", "extraContent2", Model.ExtraContent2, 5)); //form.Append(HtmlBuilder.HtmlTagLabelTextArea("Extra content 3", "extraContent3", Model.ExtraContent3, 3)); form.Append(HtmlBuilder.HtmlTagLabelInput("Author", "author", Model.Author)); form.Append(HtmlBuilder.HtmlTagLabelInput("ViewPath", "viewPath", Model.ViewPath)); form.Append(HtmlBuilder.HtmlTagLabelCheckbox("Hidden", "isHidden", Model.IsHidden)); form.Append(HtmlBuilder.HtmlTagLabelCheckbox("Deleted", "isDeleted", Model.IsDeleted)); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "update").Attr("value", "Update")); if (!String.IsNullOrEmpty(Model.Url)) { form.Append(new HtmlTag("p").Append(new HtmlTag("a").Attr("href", Model.Url).Text("View page"))); } div.Append(form); return new HtmlString(div.ToHtmlString()); }
public static HtmlTag Menu(this IFubuPage page, string menuName = null) { var navigationService = page.Get<INavigationService>(); var securityContext = page.Get<ISecurityContext>(); var items = navigationService.MenuFor(new NavigationKey(menuName ?? StringConstants.BlogName)); var menu = new HtmlTag("ul"); items.Each(x => { var link = new LinkTag(x.Key, x.Url); var li = new HtmlTag("li"); if (x.Key.Equals("Logout") && x.MenuItemState == MenuItemState.Available) { var spanTag = new HtmlTag("span"); spanTag.Text(string.Format("Welcome, {0}", securityContext.CurrentIdentity.Name)); menu.Append(spanTag); } if (x.MenuItemState == MenuItemState.Active) li.AddClass("current"); if(x.MenuItemState == MenuItemState.Active || x.MenuItemState == MenuItemState.Available) menu.Append(li.Append(link)); }); return menu; }
public void AddEqualToDataAttr(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData request) { var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is EqualValidator); if (result != null) { var equal = result.PropertyValidator.As<EqualValidator>(); MessageFormatter formatter = new MessageFormatter() .AppendPropertyName(result.DisplayName) .AppendArgument("ComparisonValue", equal.ValueToCompare); string message = formatter.BuildMessage(equal.ErrorMessageSource.GetString()); if (_msUnobtrusive) { htmlTag.Data("val", true); htmlTag.Data("val-equalto", message); if (request.Accessor.PropertyNames.Length > 1) htmlTag.Data("val-equalto-other", request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.MemberToCompare.Name); else htmlTag.Data("val-equalto-other", "*." + equal.MemberToCompare.Name); } else { htmlTag.Data("msg-equalto", message); if (request.Accessor.PropertyNames.Length > 1) htmlTag.Data("rule-equalto", "#" + request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.MemberToCompare.Name); else htmlTag.Data("rule-equalto", "#" + equal.MemberToCompare.Name); } } }
public static MvcHtmlString AuthButtons(this HtmlHelper htmlHelper) { var authContainer = new HtmlTag("div") .Attr("style", "overflow: hidden;") .Append("input", ht => ht.Id("authType").Attr("name", "authType").Attr("type", "hidden").Attr("value", "1")) .Append("a", ht => ht .Attr("href", "javascript:auth.signin('twitter')") .AddClasses("simpleAuthButton", "twitter") .Text("twitter")) .Append("a", ht => ht .Attr("href", "javascript:auth.signin('facebook')") .AddClasses("simpleAuthButton", "facebook") .Text("facebook")) .Append("a", ht => ht .Attr("href", "javascript:auth.signin('google')") .AddClasses("simpleAuthButton", "google") .Text("google")) .ToHtmlString(); return new MvcHtmlString(authContainer); }
public void mustache_text() { var tag = new HtmlTag("span"); tag.MustacheText("prop"); tag.ToString().ShouldEqual("<span>{{prop}}</span>"); }
public static void AddElementName(ElementRequest request, HtmlTag tag) { if (tag.IsInputElement()) { tag.Attr("name", request.ElementId); } }
public void AddEqualToDataAttr(IEnumerable<ValidationAttribute> propertyValidators, HtmlTag htmlTag, RequestData request) { var equal = propertyValidators.OfType<CompareAttribute>().FirstOrDefault(); if (equal != null) { var formatErrorMessage = equal.FormatErrorMessage(request.Accessor.Name); if (_msUnobtrusive) { htmlTag.Data("val", true); htmlTag.Data("val-equalto", formatErrorMessage); if (request.Accessor.PropertyNames.Length > 1) { htmlTag.Data("val-equalto-other", request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.OtherProperty); } else { htmlTag.Data("val-equalto-other", "*." + equal.OtherProperty); } } else { htmlTag.Data("msg-equalto", formatErrorMessage); if (request.Accessor.PropertyNames.Length > 1) htmlTag.Data("rule-equalto", "#" + request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.OtherProperty); else htmlTag.Data("rule-equalto", "#" + equal.OtherProperty); } } }
public ScriptTag(string mode, Func<string, string> toFullUrl, Asset asset, string defaultUrl = null) : base("script") { // http://stackoverflow.com/a/1288319/75194 Attr("type", "text/javascript"); if (asset == null) { Attr("src", toFullUrl(defaultUrl)); return; } if (asset.CdnUrl.IsNotEmpty()) { Attr("src", asset.CdnUrl); if (asset.FallbackTest.IsNotEmpty() && asset.File != null) { Next = new HtmlTag("script"); var text = "if ({0}) document.write(unescape(\"%3Cscript src='{1}' type='text/javascript'%3E%3C/script%3E\"));".ToFormat(asset.FallbackTest, asset.Url); Next.Encoded(false); Next.Text(text); } return; } var url = asset.Url; if (mode.InDevelopment() && asset.File != null) { url += "?Etag=" + asset.File.Etag(); } Attr("src", toFullUrl(url)); }
private static void setDisabledState(MenuItemToken item, HtmlTag link) { if (item.MenuItemState == MenuItemState.Disabled) { link.AddClass("disabled"); } }
public ConventionsViewModel get_conventions() { var configTypes = new string[] { ConfigurationType.Settings, ConfigurationType.Discovery, ConfigurationType.Explicit, ConfigurationType.Policy, ConfigurationType.Attributes, ConfigurationType.ModifyRoutes, ConfigurationType.InjectNodes, ConfigurationType.Conneg, ConfigurationType.Attachment, ConfigurationType.Navigation, ConfigurationType.ByNavigation, ConfigurationType.Reordering, ConfigurationType.Instrumentation }; var tag = new HtmlTag("ul"); configTypes.Each(configType => { tag.Add("li/a").Text(configType).Attr("href", "#" + configType); }); return new ConventionsViewModel { Descriptions = new TagList(configTypes.Select(configType => new ConfigurationTypeTag(configType, _graph))), TableOfContents = tag }; }
private static HtmlTag Checkbox(UIComponentContext context) { var checkbox = new CheckboxTag(context.Value<bool>()).Attr("value", "true"); var hidden = new HtmlTag("input").Attr("type", "hidden").Attr("value", "false"); checkbox.Next = hidden; return checkbox; }
public HtmlTag get_tasks() { var peers = _repository.FindPeers(); var cache = new Cache<Uri, TransportNode>(); peers.Each(peer => peer.OwnedTasks.Each(x => cache[x] = peer)); var tag = new HtmlTag("div"); tag.Add("h1").Text("Task Assignements"); var table = new TableTag(); tag.Append(table); table.AddClass("table"); table.AddHeaderRow(row => { row.Header("Task"); row.Header("Assigned to"); row.Header("Control Channel"); }); var tasks = _tasks.PermanentTasks().Union(_tasks.ActiveTasks()).ToArray(); tasks.Each(uri => { table.AddBodyRow(row => addRow(row, uri, cache)); }); return tag; }
public override void Build(ElementRequest request, HtmlTag tag) { tag .AllTags() .Where(t => t.IsInputElement()) .ForEach(t => t.AddClass("url")); }
public void mustache_attr() { var tag = new HtmlTag("a"); tag.MustacheAttr("href", "url"); tag.ToString().ShouldEqual("<a href=\"{{url}}\"></a>"); }
private void writeScripts(HtmlTag foot) { // Do this regardless foot.Append(_assets.For("FubuDiagnostics.js").ToEmbeddedScriptTag()); var routeData = _routeWriter.WriteJavascriptRoutes("FubuDiagnostics.routes", _routes); foot.Append(routeData); var extensionFiles = _assets.JavascriptFiles().Where(x => x.AssemblyName != "FubuMVC.Core"); if (_runtime.Mode.InDiagnostics()) { var names = _scripts.Union(extensionFiles.Select(x => x.Name.Split('.').Reverse().Take(2).Reverse().Join("."))); var links = _tags.BuildScriptTags(names.Select(x => "fubu-diagnostics/" + x)); links.Each(x => foot.Append(x)); } else { _scripts.Each(name => { var file = _assets.For(name); foot.Append(file.ToEmbeddedScriptTag()); }); extensionFiles.Each(file => foot.Append(file.ToEmbeddedScriptTag())); } }
private void AssertOptionGroup( HtmlTag optgroup, string display) { Assert.Equal("optgroup", optgroup.TagName()); Assert.Equal(display, optgroup.Attr("label")); }
public override HtmlTag Build(ElementRequest request) { HtmlTag root = new HtmlTag("div").Attr("data-bind", "foreach: "+ CCHtmlConventions2.DeriveElementName(request)); var child = new HtmlTag("div").Attr("data-bind", "text: $data" ); root.Append(child); return root; }
public static HtmlTag PrependAnchor(this HtmlTag tag) { var a = new HtmlTag("a").Attr("href", "#" + tag.Id()); a.Next = tag; return a; }
public TableTag() : base("table") { _header = new HtmlTag("thead", this); _footer = new HtmlTag("tfoot", this).Render(false); _body = new HtmlTag("tbody", this); }
public static HtmlTag ChildNodesRecursiveHtmlTag(this IDocumentNode currentNode, IDocumentNode IDocumentNode, int allExpandToLevel = 2, bool includeHidden = false, bool includeDeleted = false, string addAdminPath = "") { var ul = new HtmlTags.HtmlTag("ul"); foreach (var c in IDocumentNode.Children.Where(n => (includeDeleted || !n.IsDeleted) && (includeHidden || !n.IsHidden))) { var li = new HtmlTags.HtmlTag("li"); var path = addAdminPath + c.Url; li.Add("a").Attr("href", path).Text(c.Name); if (c == currentNode) { li.AddClass("selected"); } if (c.IsDescendantOrSameAs(currentNode)) { li.AddClass("sel"); } if (c.Children.Count > 0 && (c.Level < allExpandToLevel || c.IsDescendantOrSameAs(currentNode) || currentNode.IsDescendantOrSameAs(c))) { li.Children.Add(ChildNodesRecursiveHtmlTag(currentNode, c, allExpandToLevel, includeHidden, includeDeleted, addAdminPath)); } ul.Children.Add(li); } return(ul); }
public HtmlDocument Write() { HtmlTag header = new HtmlTag("div", x => { var table = x.Child<TableTag>() .AddBodyRow(row => { row.Cell("Request Url:"); row.Cell(_report.Url).AddClass("cell-data"); }) .AddBodyRow(row => { row.Cell("Execution Time:"); row.Cell(_report.ExecutionTime + " milliseconds"); }) .AddBodyRow(row => { row.Cell("At:"); row.Cell(_report.Time.ToString("G")); }); table.AddClass("summary"); writeFormData(x); }); var reportWriter = new DebugReportTagWriter(); _report.Steps.Each(reportWriter.WriteStep); string title = "Debug Run of " + _report.Url; return DiagnosticHtml.BuildDocument(_urls, title, header, reportWriter.Tag); }
public ConfigureFubuMVC() { IncludeDiagnostics(true); this.ApplyConvention<ModelValidationConfiguration>(); this.ApplyHandlerConventions<HandlersMarker>(); HtmlConvention(x => x.Editors.Always.Modify((request, tag) => { var fubuRequest = request.Get<IFubuRequest>(); var validationResult = fubuRequest.Get<ValidationResult>(); if (validationResult.IsValid) return; var ul = new HtmlTag("ul"); var liTags = validationResult.Errors.Where(error => error.PropertyName == request.Accessor.InnerProperty.Name).Select(vf => new HtmlTag("li", li => li.Text(vf.ErrorMessage))); ul.Append(liTags); tag.Append(ul); })); this.UseSpark(); Routes .IgnoreNamespaceText("fubu101") .HomeIs<GetHandler>(action => action.Execute(new MovieRequestModel())); Policies.EnrichCallsWith<MovieViewModelJsonBehavior>(request => request.Returns<MovieViewModel>()); Views.TryToAttachWithDefaultConventions(); }
public override HtmlTag Build(ElementRequest request) { HtmlTag root = new HtmlTag("a"); root.Attr("data-bind", "attr: { href: mailto:" + CCHtmlConventionsKO.DeriveElementName(request)+"}"); root.Children.Add(new HtmlTag("span").Attr("data-bind", "text:" + CCHtmlConventionsKO.DeriveElementName(request))); return root; }
public TestEditorTag(FixtureLibrary library) : base("div") { AddClass("main"); Add("h2").AddClass(HtmlClasses.TEST_NAME); Id("testEditor"); AddClass(HtmlClasses.TEST_EDITOR); _container = Add("div").AddClasses("container", HtmlClasses.SECTION, "test-editor"); FixtureGraph fixture = library.BuildTopLevelGraph(); HtmlTag holder = new HolderTag(fixture).AddClass("top-level-holder"); holder.Children.Last().Render(false); Container .MetaData(GrammarConstants.LEAF_NAME, GrammarConstants.TEST) .MetaData(GrammarConstants.FIXTURE, GrammarConstants.TEST) .MetaData(GrammarConstants.SELECTION_MODE, SelectionMode.OneOrMore.ToString()) .Append(holder) .Append(new HtmlTag("hr")); Container.ActionLink(fixture.Policies.AddGrammarText, GrammarConstants.ADD_SECTION_ACTIVATOR); Container.Append(new GrammarSelector(fixture).Build()); }
public virtual void Modify(HtmlTag form) { if (!_modify) return; form.Data("validation-mode", _value.ToLower()); form.AddClass("validated-form"); }
public override HtmlTag Build(ElementRequest request) { var tag = new HtmlTag("div").Text(request.StringValue()).AddClass("editable").Id(request.Accessor.Name); var options = new EditOptions(); if (request.Accessor.HasAttribute<MarkdownAttribute>()) { tag.UnEncoded().Text(new Markdown().Transform(request.RawValue== null ? "" : request.RawValue.ToString())); options.Markdown = true; } options.MultiLine = request.Accessor.Name == "Details"; options.RequiresExplicitUserActionForSave = true; options.MaximumLength = request.Accessor.PropertyType.Equals(typeof(string)) ? Entity.UnboundedStringLength : 0; options.IsDate = request.Accessor.PropertyType.IsDateTime(); options.IsTime = request.Accessor.Name.ToLower().Contains("time"); options.IsNumber = request.Accessor.PropertyType.IsIntegerBased() || request.Accessor.PropertyType.IsFloatingPoint(); options.Required = request.Accessor.HasAttribute<RequiredAttribute>(); options.PlaceholderText = "Double-Click to edit " + request.Accessor.Name.ToLower() + "."; var data = options.ToJson(); tag.Attr("data", "{editoptions:"+data+"}"); return tag; }
public static MvcHtmlString RenderAuthWarnings(this HtmlHelper htmlHelper) { var appSettingsKeys = new[] { "googleAppID", "googleAppSecret", "facebookAppID", "facebookAppSecret", "twitterConsumerKey", "twitterConsumerSecret" }; var noValueForSetting = appSettingsKeys .Any(key => string.IsNullOrEmpty(ConfigurationManager.AppSettings[key])); var message = ""; if (noValueForSetting) { message = new HtmlTag("p") .Attr("style", "color: Red;") .Text("Not all key and secrets are filled in a configuration file.") .ToHtmlString(); } return new MvcHtmlString(message); }
public ModalTag(string id) : base("div") { var labelId = id + "Label"; var bodyId = id + "Body"; AddClass("modal"); AddClass("hide"); Id(id); Attr("tabindex", "-1"); Attr("role", "dialog"); Attr("aria-labelledby", labelId); Attr("aria-hidden", "true"); Attr("data-show", "false"); var header = Add("div"); header.AddClass("modal-header"); header.Add("button").Attr("type", "button").AddClass("close").Attr("data-dismiss", "modal").Attr("aria-hidden", "true").Text("x"); _label = header.Add("h3").Id(labelId); _body = Add("div").Id(bodyId).AddClass("modal-body"); _footer = Add("div").AddClass("modal-footer"); }
public static HtmlTag AddValidationAttributes(HtmlTag tag, ModelInfo info) { var input = tag.FirstNonHiddenInput(); if (input == null) return tag; input.AddValidationAttributes(info); return tag; }
private static IEnumerable<HtmlTag> createTags(IEnumerable<LogEntry> entries) { foreach (LogEntry log in entries) { var text = "{0} in {1} milliseconds".ToFormat(log.Description, log.TimeInMilliseconds); if (!log.Success) { text += " -- Failed!"; } var headerTag = new HtmlTag("h4").Text(text).AddClass("log"); yield return headerTag; if (log.TraceText.IsNotEmpty()) { var traceTag = new HtmlTag("pre").AddClass("log").Text(log.TraceText); if (!log.Success) { traceTag.AddClass("failure"); } yield return traceTag; } yield return new HtmlTag("hr"); } }
public static HtmlString ChildNodes(this IDocumentNode IDocumentNode, int atLevel = 0, bool includeHidden = false, bool includeDeleted = false) { var ul = new HtmlTags.HtmlTag("ul"); ul.AddClass("topnavigation"); foreach (var c in IDocumentNode.AncestorAtLevel(atLevel).Children.Where(n => (includeDeleted || !n.IsDeleted) && (includeHidden || !n.IsHidden))) { var li = new HtmlTags.HtmlTag("li"); if (IDocumentNode.IsDescendantOrSameAs(c)) { li.AddClass("selected"); } li.Add("a").Attr("href", c.Url).Text(c.Name); ul.Children.Add(li); } return(new HtmlString(ul.ToHtmlString())); }
public HtmlTag WrapWith(HtmlTag wrapper) { wrapper.InsertFirst(this); return(wrapper); }
/// <summary> /// Adds a LiteralTag to the Children collection /// </summary> /// <param name="tag"></param> /// <param name="html"></param> /// <returns></returns> public static HtmlTag AppendHtml(this HtmlTag tag, string html) => tag.Append(new LiteralTag(html));
/// <summary> /// Adds the given tag as the last child of the parent, and returns the parent. /// </summary> /// <param name="child">The tag to add as a child of the parent.</param> /// <returns>The parent tag</returns> public HtmlTag Append(HtmlTag child) { child.Parent = this; _children.Add(child); return(this); }
/// <summary> /// Inserts a sibling tag immediately after the current tag. Any existing sibling will follow the inserted tag. /// </summary> /// <param name="nextTag">The tag to add as a sibling</param> /// <returns>The original tag</returns> public HtmlTag After(HtmlTag nextTag) { nextTag.Next = Next; Next = nextTag; return(this); }
public void Add(HtmlTag tag) { Last = tag; Current.Append(tag); }
private static HtmlTag WalkToTop(HtmlTag htmlTag) { return(htmlTag.Parent == null ? htmlTag : WalkToTop(htmlTag.Parent)); }
public void PushWithoutAttaching(HtmlTag tag) => _currentStack.Push(tag);
public void InsertFirst(HtmlTag tag) { tag.Parent = this; _children.Insert(0, tag); }
public void Push(HtmlTag tag) { Current.Append(tag); _currentStack.Push(tag); }
public HtmlTag Add(string tagName) { Last = Current.Add(tagName); return(Last); }