Esempio n. 1
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 static string AwesomeDisplay(this IFubuPage page, object model)
        {
            var type = model.GetType();
            var result = new StringBuilder();
            var tags = page.Tags(model);
            var sl = page.Get<IServiceLocator>();

            tags.SetProfile(AwesomeConfiguration.TagProfile);
            var tr = new HtmlTag("tr");
            foreach (var prop in getProperties(type))
            {

                var p = new SingleProperty(prop, type);
                var elementRequest = new ElementRequest(model, p, sl);
                var accessRight = page.Get<IFieldAccessService>().RightsFor(elementRequest);

                HtmlTag display = tags.DisplayFor(elementRequest).Authorized(accessRight.Read);
                var td = new HtmlTag("td").Append(display);
                tr.Append(td);

            }
            var editLink = new LinkTag("Edit", page.EditUrlFor(model));
            tr.Append(new HtmlTag("td").Append(editLink));
            var deleteLink = new LinkTag("Delete", page.DeleteUrlFor(model));
            tr.Append(new HtmlTag("td").Append(deleteLink));
            result.Append(tr.ToString());

            return result.ToString();
        }
Esempio n. 3
0
        public HtmlDocument Index()
        {
            var document = new HtmlDocument
                { Title = "How to use DownloadFileModel class to stream and download assets" };

            document.Body.Add("h1").Text("Using DownloadFileModel class to stream and download assets");

            LinkTag streamPdf = new LinkTag("Stream PDF to browser", "pdf/stream");
            LinkTag downloadPdf = new LinkTag("Force browser to open dialog for download PDF", "pdf/download");
            LinkTag streamJpeg = new LinkTag("Stream JPEG to browser", "jpeg/stream");

            document.Body.Append(streamPdf).Add("br");
            document.Body.Append(downloadPdf).Add("br");
            document.Body.Append(streamJpeg).Add("br");
                    
            return document;
        }
Esempio n. 4
0
        public HtmlDocument Example(ExampleHtmlRequest exampleHtmlRequest)
        {
            var modelPath = exampleHtmlRequest.Model ?? typeof(ExampleViewModel).FullName + "-Person";
            var tags = new List<HtmlTag>();
            var propertyPath = new List<string>(modelPath.Split('-'));
            var rootModelTypeName = propertyPath[0];
            tags.Add(new HtmlTag("h3").AddClass("viewmodel").Text(propertyPath.Join(".")));
            propertyPath.RemoveAt(0);

            Type scannedModelType = getTypeFromName(rootModelTypeName);
            var scannedModelInstance = createInstance(scannedModelType);
            var tagGeneratorType = typeof(TagGenerator<>).MakeGenericType(scannedModelType);
            var tagGenerator = (ITagGenerator)_serviceLocator.GetInstance(tagGeneratorType);
            tagGenerator.SetModel(scannedModelInstance);

            var propertyChainParts = new List<PropertyInfo>();

            while (propertyPath.Count > 0)
            {
                var parentPropertyInfo = scannedModelType.GetProperty(propertyPath[0]);
                propertyChainParts.Add(parentPropertyInfo);
                var currentModelType = parentPropertyInfo.PropertyType;
                var currentModel = createInstance(currentModelType);
                setProperty(parentPropertyInfo, scannedModelInstance, currentModel);

                scannedModelType = currentModelType;
                scannedModelInstance = currentModel;
                propertyPath.RemoveAt(0);
            }

            var modelProperties = scannedModelType.GetProperties();
            var propertiesToLink = modelProperties.Where(p => !TypeDescriptor.GetConverter(p.PropertyType).CanConvertFrom(typeof(string)));
            var propertiesToShow = modelProperties.Except(propertiesToLink);

            // show links to deeper properties
            var linkList = new HtmlTag("ul").AddClass("subproperties");
            foreach (var propertyInfo in propertiesToLink)
            {
                var linkTag = new LinkTag("", _examplePageUrl + "?model=" + modelPath + "-" + propertyInfo.Name);
                linkTag.Child(new HtmlTag("code").Text(getPropertySourceCode(propertyInfo)));
                var listItem = new HtmlTag("li").Child(linkTag);
                linkList.Child(listItem);
            }
            if (linkList.Children.Count > 0) tags.Add(linkList);

            // show examples
            populateInstance(scannedModelInstance, propertiesToShow);
            foreach (var propertyInfo in propertiesToShow)
            {
                var property = propertyChainParts.Count > 0 ?
                    (Accessor) new PropertyChain(propertyChainParts.Concat(new[]{propertyInfo}).ToArray()) :
                    new SingleProperty(propertyInfo);

                var propertyExpression = "x => x." + property.PropertyNames.Join(".");

                var propertySource = getPropertySourceCode(propertyInfo);

                var example = new HtmlTag("div").AddClass("example");
                example.AddChildren(new HtmlTag("code").AddClass("property").Text(propertySource));
                example.AddChildren(createExample(tagGenerator.LabelFor(tagGenerator.GetRequest(property)), "LabelFor({0})".ToFormat(propertyExpression)));
                example.AddChildren(createExample(tagGenerator.DisplayFor(tagGenerator.GetRequest(property)), "DisplayFor({0})".ToFormat(propertyExpression)));
                example.AddChildren(createExample(tagGenerator.InputFor(tagGenerator.GetRequest(property)), "InputFor({0})".ToFormat(propertyExpression)));
                tags.Add(example);
            }

            var doc = DiagnosticHtml.BuildDocument(_urlRegistry, "FubuMVC.UI Examples", tags.ToArray());
            doc.AddStyle(DiagnosticHtml.GetResourceText(GetType(), "examples.css"));
            return doc;
        }
Esempio n. 5
0
        public HtmlTag BuildLeafTag(ISpecNode node)
        {
            return new HtmlTag("li", tag =>
            {
                var url = _urls.UrlFor(node.Path());
                var link = new LinkTag(node.Path().Parts.Last(), url);

                tag.Add("span").AddClass("file").Append(link);
            });
        }
Esempio n. 6
0
        public HtmlTag TopTag(HtmlTag topChild)
        {
            if (topChild.TagName() != "ul")
            {
                throw new ArgumentOutOfRangeException("Only ul tags are valid here:  \n" + topChild.ToString());
            }

            var topUrl = _urls.UrlFor<JasminePages>(x => x.AllSpecs());
            return new HtmlTag("ul", tag =>
            {
                tag.Id("all-specs-node").AddClass("filetree");

                var link = new LinkTag("All Specs", topUrl, "all-specs");
                var li = tag.Add("li");
                li.Add("span").AddClass("folder").Append(link);

                li.Append(topChild);
            });
        }