Esempio n. 1
0
        public static HtmlTag RateSystemStatus(this HtmlHelper helper, DateTime startDate, DateTime endDate)
        {
            if (startDate == null)
            {
                throw new ArgumentNullException("Start date can not be null");
            }

            if (endDate == null)
            {
                throw new ArgumentNullException("End date can not be null");
            }

            HtmlTag status = new HtmlTag("span");

            if (startDate <= DateTime.Now && DateTime.Now <= endDate)
            {
                status.Text("Active").AddClass("btn btn-success btn-xs");
            }
            else if (startDate > DateTime.Now)
            {
                status.Text("Upcoming").AddClass("btn btn-warning btn-xs");
            }
            else if (endDate < DateTime.Now)
            {
                status.Text("Past").AddClass("btn btn-danger btn-xs");
            }

            return status;
        }
Esempio n. 2
0
        //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;
        }
Esempio n. 3
0
        public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
        {
            Type inputType = chain.ActionInputType();

            if (inputType == null)
            {
                cell.Text(" -");
            }
            else
            {
                cell.Text(inputType.Name).Title(inputType.AssemblyQualifiedName);
            }
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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 HtmlTag ToHtmlTag()
 {
     var root = new HtmlTag("Button");
     root.Text(_text);
     addMainTagAttributes();
     addClassesAndAttributesToRoot(root);
     return root;
 }
 private void AssertOption(
     HtmlTag option,
     string display, 
     object value)
 {
     Assert.Equal("option", option.TagName());
     Assert.Equal(display, option.Text());
     Assert.True(option.ValueIsEqual(value));
 }
Esempio n. 9
0
        public void write_body_for_chain_with_no_input_type()
        {
            var chain = new BehaviorChain();
            var tag = new HtmlTag("td");

            new InputModelColumn().WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(" -");
        }
        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;
                            });
        }
Esempio n. 11
0
        public void write_route_column_when_the_route_does_not_exist()
        {
            var chain = new BehaviorChain();

            var tag = new HtmlTag("td");

            new RouteColumn(new StubCurrentHttpRequest("http://server")).WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(" -");
        }
Esempio n. 12
0
        public void write_with_no_outputs()
        {
            var chain = new BehaviorChain();
            var tag = new HtmlTag("td");

            var column = new OutputColumn();
            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(" -");
        }
Esempio n. 13
0
        public HtmlTag VisualizePartial(TypeInput input)
        {
            var type = input.Type;

            var div = new HtmlTag("div");
            div.Text(type.Name);
            div.Title(type.AssemblyQualifiedName);

            return div;
        }
Esempio n. 14
0
        public void write_route_column_when_the_route_does_not_exist()
        {
            var chain = new BehaviorChain();

            var tag = new HtmlTag("td");

            new RouteColumn().WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(" -");
        }
Esempio n. 15
0
        public void write_body_for_chain_with_input_type()
        {
            var chain = new BehaviorChain();
            chain.AddToEnd(ActionCall.For<ControllerTarget>(x => x.OneInOneOut(null)));
            var tag = new HtmlTag("td");

            new InputModelColumn().WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(typeof (Model1).Name);
            tag.Title().ShouldEqual(typeof (Model1).AssemblyQualifiedName);
        }
Esempio n. 16
0
        public void write_route_column_when_the_route_exists()
        {
            var chain = new BehaviorChain();
            chain.Route = new RouteDefinition("some/thing/else");

            var tag = new HtmlTag("td");

            new RouteColumn().WriteBody(chain, tag);

            tag.Text().ShouldEqual(chain.Route.Pattern);
        }
Esempio n. 17
0
        public void write_body_cell_with_no_calls()
        {
            var chain = new BehaviorChain();

            var column = new ActionColumn();

            var tag = new HtmlTag("td");

            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(" -");
        }
Esempio n. 18
0
        public void write_with_a_single_output()
        {
            var chain = new BehaviorChain();
            var node = new RenderJsonNode(typeof (RouteParameter));
            chain.AddToEnd(node);

            var tag = new HtmlTag("td");

            var column = new OutputColumn();
            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(node.Description);
        }
Esempio n. 19
0
        public void write_body_cell_with_only_one_call()
        {
            var chain = new BehaviorChain();
            ActionCall call = ActionCall.For<TargetController>(x => x.Go());
            chain.AddToEnd(call);

            var column = new ActionColumn();

            var tag = new HtmlTag("td");

            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(call.Description);
        }
        public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
        {
            if (!chain.Authorization.HasRules())
            {
                cell.Text("  [None]  ");
                return;
            }

            cell.Add("ul", ul =>
            {
                var authorizor = _factory.AuthorizorFor(chain.UniqueId);
                authorizor.RulesDescriptions().Each(rule => { ul.Add("li").Text(rule); });
            });
        }
Esempio n. 21
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);
     }
 }
Esempio n. 22
0
        public void write_with_multiple_outputs()
        {
            var chain = new BehaviorChain();
            var json = new RenderJsonNode(typeof (RouteParameter));
            chain.AddToEnd(json);

            var text = new RenderTextNode<RouteParameter>();
            chain.AddToEnd(text);

            var tag = new HtmlTag("td");

            var column = new OutputColumn();
            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(json.Description + ", " + text.Description);
        }
        public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
        {
            if (!chain.Authorization.HasRules())
            {
                cell.Text("  [None]  ");
                return;
            }

            cell.Add("ul", ul =>
            {
                var authorizor = _locator.GetInstance<IEndPointAuthorizor>(chain.UniqueId.ToString());
                authorizor.RulesDescriptions().Each(rule =>
                {
                    ul.Add("li").Text(rule);
                });
            });
        }
Esempio n. 24
0
        public void write_body_cell_with_multiple_calls()
        {
            var chain = new BehaviorChain();
            ActionCall call1 = ActionCall.For<TargetController>(x => x.Go());
            chain.AddToEnd(call1);

            ActionCall call2 = ActionCall.For<TargetController>(x => x.GoWithInput(null));
            chain.AddToEnd(call2);

            var column = new ActionColumn();

            var tag = new HtmlTag("td");

            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(call1.Description + ", " + call2.Description);
        }
        public override HtmlTags.HtmlTag Build(ElementRequest request)
        {
            HtmlTag el = new HtmlTag("ul").AddClass("pizza-type");

            IRepository repository = request.Get<IRepository>();
            IEnumerable<PizzaType> pizzaTypes = repository.GetAll<PizzaType>().Cast<PizzaType>();
            var stringifier = request.Get<Stringifier>();

            foreach (PizzaType pt in pizzaTypes)
            {
                HtmlTag radio = new HtmlTag("input");
                radio.Attr("type", "radio").Attr("name", "PizzaType");
                radio.Attr("value", pt.Id);
                radio.Text(stringifier.GetString(pt));
                el.Append(new HtmlTag("li").Append(radio));
            }

            return el;
        }
Esempio n. 26
0
 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;
 }
Esempio n. 27
0
 public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
 {
     cell.Text(Text(chain));
 }
Esempio n. 28
0
 public virtual void LabelsChain()
 {
     Labels.Always.BuildBy(req =>
                               {
                                   var htmlTag = new HtmlTag("label").Attr("for", req.Accessor.Name);
                                   var display = req.Accessor.FieldName;
                                   htmlTag.Text(display.ToSeperateWordsFromPascalCase());
                                   return htmlTag;
                               });
 }
Esempio n. 29
0
 private void addChildItems(HtmlTag ul)
 {
     var partial = "@foreach (var item in @Model." + _collectionName + " }){ @Html.Partial(\"" + _templateName + "\", item) }";
     ul.Text(partial);
 }
Esempio n. 30
0
 public void WriteBody(BehaviorChain chain, HtmlTag cell)
 {
     string text = Text(chain);
     cell.Text(text);
 }