private static HtmlTag MakeRadioButton(string display, object value, string name) { DivTag divTag = new DivTag(display); HtmlTag radioButton = new RadioButtonTag(false).Attr("value", value).Attr("name",name); HtmlTag label = new HtmlTag("label").Text(display); label.AddChildren(radioButton); divTag.AddChildren(label); return divTag; }
public static HtmlDocument BuildDocument(IUrlRegistry urls, string title, params HtmlTag[] tags) { var css = GetResourceText(typeof(BehaviorGraphWriter), "diagnostics.css"); var realTitle = "FubuMVC: " + title; var document = new HtmlDocument(); document.Title = realTitle; var mainDiv = new HtmlTag("div").AddClass("main"); mainDiv.Add("h2").Text("FubuMVC Diagnostics").Child(buildVersionTag()); var navBar = mainDiv.Add("div").AddClass("homelink"); navBar.AddChildren(new LinkTag("Home", urls.UrlFor<BehaviorGraphWriter>(w => w.Index()))); navBar.Add("span").Text(" > " + title); document.Add(mainDiv); mainDiv.AddChildren(tags); document.AddStyle(css); return document; }
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; }
private static HtmlTag createExample(HtmlTag htmlTag, string methodCall) { var example = new HtmlTag("fieldset").AddClass("tag"); example.Add("legend").Text(methodCall); example.AddChildren(new HtmlTag("code").AddClass("source").Text(htmlTag.ToString())); example.AddChildren(new HtmlTag("div").AddClass("rendered").AddChildren(htmlTag)); return example; }
public HtmlDocument Chain(ChainRequest chainRequest) { var title = "Chain " + chainRequest.Id; var behaviorChain = _graph.Behaviors.FirstOrDefault(chain => chain.UniqueId == chainRequest.Id); if (behaviorChain == null) { return BuildDocument("Unknown chain", new HtmlTag("span").Text("No behavior chain registered with ID: " + chainRequest.Id)); } var content = new HtmlTag("div").AddClass("main-content"); var document = new HtmlTag("div"); var pattern = behaviorChain.RoutePattern; if( pattern == string.Empty ) { pattern = "(default)"; } document.Child(new HtmlTag("div").Text("Route: " + pattern)); var nodeTable = new TableTag(); nodeTable.AddHeaderRow(header => { header.Header("Category"); header.Header("Description"); header.Header("Type"); }); foreach (var node in behaviorChain) { var description = node.ToString().HtmlEncode().ConvertCRLFToBreaks(); nodeTable.AddBodyRow(row => { row.Cell().Text(node.Category.ToString()); row.Cell().UnEncoded().Text(description); row.Cell().Text(node.GetType().FullName); if (description.Contains(_diagnosticsNamespace)) { row.AddClass(FUBU_INTERNAL_CLASS); } }); } var logDiv = new HtmlTag("div").AddClass("convention-log"); var ul = logDiv.Add("ul"); var observer = _graph.Observer; behaviorChain.Calls.Each( call => observer.GetLog(call).Each( entry => ul.Add("li").Text(entry))); content.AddChildren(new[]{ document, new HtmlTag("h3").Text("Nodes:"), nodeTable, new HtmlTag("h3").Text("Log:"), logDiv}); return BuildDocument(title, content); }