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);
        }
        //this is hideous but wanted to show an idea.
        public HtmlTag BuildLabel(BehaviorNode behaviorNode)
        {
            // TODO -- come back and policize this

            var span = new HtmlTag("span").AddClass("label");
            var pp = behaviorNode.GetType().PrettyPrint();
            span.Text("behavior");

            if (pp.StartsWith("WebForm"))
            {
                span.Text("View");
                span.AddClass("notice");
            }
            else if (pp.StartsWith("Call"))
            {
                span.AddClass("warning");
                span.Text("continuation");
            }
            else if (!behaviorNode.GetType().Name.StartsWith("Fubu"))
            {
                span.Text("fubu");
            }

            return span;
        }
 private static void setDisabledState(MenuItemToken item, HtmlTag link)
 {
     if (item.MenuItemState == MenuItemState.Disabled)
     {
         link.AddClass("disabled");
     }
 }
        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 virtual void Modify(HtmlTag form)
        {
            if (!_modify) return;

            form.Data("validation-mode", _value.ToLower());
            form.AddClass("validated-form");
        }
        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;
        }
Exemple #7
0
        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 void WriteResults(Counts counts)
        {
            var countsTag = new HtmlTag("div").AddClass("results");
            if (counts.WasSuccessful())
            {
                countsTag.Text("Succeeded with " + counts.ToString());
                countsTag.AddClass("results-" + HtmlClasses.PASS);
            }
            else
            {
                countsTag.Text("Failed with " + counts.ToString());
                countsTag.AddClass("results-" + HtmlClasses.FAIL);
            }

            _suiteName.Next = countsTag;
        }
 private static void AddNumberClasses(RequestData r, HtmlTag h)
 {
     if (r.Accessor.PropertyType == typeof(int) || r.Accessor.PropertyType == typeof(int?)
         || r.Accessor.PropertyType == typeof(uint) || r.Accessor.PropertyType == typeof(uint?)
         || r.Accessor.PropertyType == typeof(long) || r.Accessor.PropertyType == typeof(long?)
         || r.Accessor.PropertyType == typeof(ulong) || r.Accessor.PropertyType == typeof(ulong?)
         || r.Accessor.PropertyType == typeof(short) || r.Accessor.PropertyType == typeof(short?)
         || r.Accessor.PropertyType == typeof(ushort) || r.Accessor.PropertyType == typeof(ushort?))
     {
         h.AddClass("digits");
     }
     else if (r.Accessor.PropertyType == typeof(double) || r.Accessor.PropertyType == typeof(double?)
         || r.Accessor.PropertyType == typeof(decimal) || r.Accessor.PropertyType == typeof(decimal?)
         || r.Accessor.PropertyType == typeof(float) || r.Accessor.PropertyType == typeof(float?))
     {
         h.AddClass("number");
     }
 }
 public override HtmlTag Build(ElementRequest request)
 {
     HtmlTag root = new HtmlTag("div");
     root.AddClass("KYT_ListDisplayRoot");
     var selectListItems = request.RawValue as IEnumerable<string>;
     if (selectListItems == null) return root;
     selectListItems.Each(item=> root.Child(new HtmlTag("div").Text(item)));
     return root;
 }
        public InputConventions()
        {
            Editors.Always
                .Modify((request, tag) => tag.Attr("id", request.Accessor.Name));

            Editors
                .If(x => x.Accessor.FieldName.Contains("Password") && x.Accessor.PropertyType.IsString())
                .Attr("type", "password");

            Editors
                .If(x => x.Accessor.FieldName.Contains("Email") && x.Accessor.PropertyType.IsString())
                .Attr("type", "email");

            Editors
                .If(x => x.Accessor.FieldName.Contains("Body") && x.Accessor.PropertyType.IsString())
                .Modify((r, x) =>
                            {
                                x.TagName("textarea");
                                x.Text(r.StringValue());
                            });

            Editors
                .If(x => x.Accessor.InnerProperty.HasAttribute<RequiredAttribute>())
                .Modify(x => x.AddClass("required"));

            Editors
                .If(x => x.Accessor.InnerProperty.HasAttribute<MinLengthAttribute>())
                .Modify((request, tag) =>
                {
                    var length = request.Accessor.InnerProperty.GetAttribute<MinLengthAttribute>().Length;
                    tag.Attr("minlength", length);
                });

            Editors
                .If(x => x.Accessor.InnerProperty.HasAttribute<MaxLengthAttribute>())
                .Modify((request, tag) =>
                {
                    var length = request.Accessor.InnerProperty.GetAttribute<MaxLengthAttribute>().Length;
                    tag.Attr("maxlength", length);
                });

            Editors.Always
                .Modify((request, tag) =>
                            {
                                var result = request.Get<IFubuRequest>().Get<ValidationResult>();
                                if (result == null || result.IsValid) return;
                                var error = result.Errors.FirstOrDefault(x => x.PropertyName == request.Accessor.InnerProperty.Name);
                                if (error == null) return;

                                var errorLabel = new HtmlTag("label");
                                errorLabel.Text(error.ErrorMessage);
                                errorLabel.AddClass("error");
                                errorLabel.Attr("for", request.Accessor.InnerProperty.Name);
                                errorLabel.Attr("generated", "true");
                                tag.Next = errorLabel;
                            });
        }
 public static HtmlTag FontAwesome(this HtmlHelper htmlHelper, string icon, params string[] options)
 {
     var tag = new HtmlTag("span").AddClass("fa").AddClass(FAPrefix(icon));
     foreach (var item in options)
     {
         tag.AddClass(FAPrefix(item));
     }
     return tag;
 }
        private void writeChildren(MenuItemToken item, HtmlTag link)
        {
            link.AddClass("dropdown-toggle");
            link.Attr("data-toggle", "dropdown");

            link.Add("b").AddClass("caret");

            var ul = Add("ul").AddClass("dropdown-menu");
            item.Children.Each(child =>
            {
                var childTag = new MenuItemTag(child);
                ul.Append(childTag);
            });
        }
		public static HtmlTag GetRatingStars(int rating)
		{
			var t = new HtmlTag("span");

			for (int i = 0; i < rating; i++)
			{
				var img = new HtmlTag("img");
				img.Attr("src", "/Public/images/rating.png");
				img.AddClass("ratingImage");
				t.Append(img);
			}

			return t;
		}
        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 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());
        }
Exemple #17
0
 public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
 {
     var text = Text(chain);
     if (shouldBeClickable(chain.Route))
     {
         cell.Child(new LinkTag(text, chain.Route.Pattern.ToAbsoluteUrl()).AddClass("route-link"));
     }
     else
     {
         cell.Text(text);
     }
     if (text.StartsWith(DiagnosticUrlPolicy.DIAGNOSTICS_URL_ROOT))
     {
         row.AddClass(BehaviorGraphWriter.FUBU_INTERNAL_CLASS);
     }
 }
 public void AddCreditCardClass(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
 {
     var lengthValidator = propertyValidators.Select(x => x.PropertyValidator).OfType<CreditCardValidator>().FirstOrDefault();
     if (lengthValidator != null)
     {
         if (requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
         {
             if (!_msUnobtrusive)
             {
                 htmlTag.Data("rule-creditcard", true);
             }
         }
         else
         {
             htmlTag.AddClass("creditcard");
         }
     }
 }
        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 FilterTemplatesFor(GridViewModel model)
        {
            var tag = new HtmlTag("div");
            var containerNameForGrid = model.GridType.ContainerNameForGrid();
            tag.Id("filters_" + containerNameForGrid);
            tag.AddClass("smart-grid-filter");
            tag.Append(new TableTag());

            var metadata = new Dictionary<string, object>{
                {"gridId", "grid_" + model.GridName},
                {"initialCriteria", model.InitialCriteria()}
            };

            tag.MetaData("filters", metadata);

            var properties = model.FilteredProperties;

            var templates = _sources.Distinct().SelectMany(x => x.TagsFor(properties));

            var operators = properties.Select(prop =>
            {
                return new SelectTag(select =>
                {
                    prop.Operators.Each(oper => select.Option(oper.ToString(), oper.Key));
                }).AddClass(prop.Accessor.Name);
            });

            tag.Add("div", div =>
            {
                div.Hide();
                div.AddClass("templates");
                div.Add("div").AddClass("smart-grid-editors").Append(templates);
                div.Add("div").AddClass("smart-grid-operators").Append(operators);

                div.Append(new SelectTag(select =>
                {
                    select.AddClass("smart-grid-properties");
                    properties.Each(prop => select.Option(prop.Header, prop.Accessor.Name));
                }));
            });

            return tag;
        }
 private HtmlTag getLiItem(MenuItem item)
 {
     if (item == null) return null;
     var li = new HtmlTag("li");
     if(item.CssClass.IsNotEmpty())
         li.AddClass(item.CssClass);
     var anchor = new HtmlTag("a");
     anchor.Attr("href", "#");
     anchor.Attr("rel", item.Url);
     anchor.Text(item.Text);
     li.Children.Add(anchor);
     if(item.Children!=null)
     {
         var ul = new HtmlTag("ul");
         renderListItems(ul, item.Children);
         li.Children.Add(ul);
     }
     return li;
 }
Exemple #22
0
        public static HtmlString AdminTree(IDocumentNode Model, string adminUrl, string divClassName = "")
        {
            var div = new HtmlTag("div");
            if (divClassName != "") div.AddClass(divClassName);

            var p = new HtmlTag("p").Append(new HtmlTag("a").Text("Root node").Attr("href", adminUrl));
            var tree = HtmlBuilder.ChildNodesRecursiveHtmlTag(Model, Model.AncestorAtLevel(0), 99, true, false, adminUrl);

            var pInfo = new HtmlTag("p").Text("Add new child");

            var form = new HtmlTag("form").Attr("method", "post").Attr("action", "#");

            form.Append(new HtmlTag("label").Attr("for", "new-name").Text("Header (name)"));
            form.Append(new HtmlTag("input").Id("new-name").Attr("name", "new-name").Attr("type", "text"));
            form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "insert-new").Attr("value", "Add"));

            div.Append(p).Append(tree).Append(pInfo).Append(form);

            return new HtmlString(div.ToHtmlString());
        }
 private void addClassesAndAttributesToRoot(HtmlTag root)
 {
     HtmlAttributes.ForEachItem(x => root.Attr(x.Key, x.Value));
     CssClasses.ForEachItem(x => root.AddClass(x));
 }
        public DashboardModel get__fubu()
        {
            var files = _files.FindFiles(FileSet.Deep("fubu-diagnostics/*.html"));
            var htmlTags = files.Select(x => {
                var contents = x.ReadContents();
                var tag = new HtmlTag("div").Id(Path.GetFileNameWithoutExtension(x.Path));
                tag.Encoded(false);
                tag.Text(contents);
                tag.Hide();
                tag.AddClass("left-content");

                return tag;
            }).ToArray();

            var allJS = findAssets(MimeType.Javascript).ToArray();
            var javascript = allJS.Where(x => !x.Filename.Contains(".jsx."));
            var react = allJS.Where(x => x.Filename.Contains(".jsx."));

            return new DashboardModel
            {
                StyleTags = findAssets(MimeType.Css).Select(x => new StylesheetLinkTag(_request.ToFullUrl(x.Url))).ToArray().ToTagList(),
                ScriptTags = javascript.Select(x => new ScriptTag(_ => _request.ToFullUrl(_), x)).ToArray().ToTagList(),
                Router = _routeWriter.WriteJavascriptRoutes("FubuDiagnostics.routes", _routes),
                ReactTags = react.Select(x => new ScriptTag(_ => _request.ToFullUrl(_), x).Attr("type", "text/jsx")).ToArray().ToTagList(),
                HtmlTags = htmlTags.ToTagList()
            };
        }
Exemple #25
0
        public static Nancy.ViewEngines.Razor.IHtmlString UserStatusesToSpan(UserAccountStatuses status)
        {
            var tag = new HtmlTag("span").AddClass("label");

            switch (status)
            {
                case UserAccountStatuses.ApprovalPending:
                    tag.Text(UserAccountStatuses.ApprovalPending.ToText());
                    break;
                case UserAccountStatuses.Approved:
                    tag.AddClass("label-success").Text(UserAccountStatuses.Approved.ToText());
                    break;
                case UserAccountStatuses.Banned:
                    tag.AddClass("label-important").Text(UserAccountStatuses.Banned.ToText());
                    break;
                case UserAccountStatuses.Disapproved:
                    tag.AddClass("label-warning").Text(UserAccountStatuses.Disapproved.ToText());
                    break;
                case UserAccountStatuses.NotActive:
                    tag.AddClass("label-inverse").Text(UserAccountStatuses.NotActive.ToText());
                    break;
                default:
                    tag.AddClass("label-info").Text("未知");
                    break;
            }
            return new NonEncodedHtmlString(tag.ToString());
        }
 public void AddRequiredClass(IEnumerable<ValidationAttribute> propertyValidators, HtmlTag htmlTag, RequestData request)
 {
     var required = propertyValidators.OfType<RequiredAttribute>().FirstOrDefault();
     if (required != null)
     {
         if (request.ViewContext.UnobtrusiveJavaScriptEnabled)
         {
             var msg = required.ErrorMessage ?? string.Format("The field '{0}' is required", request.Accessor.InnerProperty.Name);
             if (_msUnobtrusive)
                 htmlTag.Data("val", true).Data("val-required", msg);
             else
                 htmlTag.Data("rule-required", true).Data("msg-required", msg);
         }
         else 
             htmlTag.AddClass("required");
     }
 }
        public void AddRequiredClass(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
        {
            var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is NotEmptyValidator
                                                             || x.PropertyValidator is NotNullValidator);

            if (result != null)
            {
                if (requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
                {
                    if (_msUnobtrusive)
                        htmlTag.Data("val", true).Data("val-required", GetMessage(requestData, result) ?? string.Empty);
                    else
                        htmlTag.Data("rule-required", true).Data("msg-required", GetMessage(requestData, result) ?? string.Empty);
                }
                else
                    htmlTag.AddClass("required");
            }
        }
 public void AddEmailData(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
 {
     var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is EmailValidator);
     if (result != null)
     {
         if (requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
         {
             var msg = GetMessage(requestData, result) ?? string.Format("The value is not a valid email address");
             if (_msUnobtrusive)
                 htmlTag.Data("val", true).Data("val-email", msg);
             else
                 htmlTag.Data("rule-email", true).Data("msg-email", msg);
         }
         else
             htmlTag.AddClass("email");
     }
 }