public void Load(string viewFullPath, string viewFilesRootFullPath, string viewContent) { string viewPathRelativeToViewRoot = viewFullPath.Substring(viewFilesRootFullPath.Length) .Replace(@"\", "/"); ViewPath = Constants.ViewFilesRoot + viewPathRelativeToViewRoot; // --------------- if (!ViewPath.EndsWith(Constants.ViewFileExtension)) { throw new ViewExtensionsException( string.Format("{0} does not end with {1}", viewFullPath, Constants.ViewFileExtension)); } Url = UrlHelpers.TrimTrailingIndex(viewPathRelativeToViewRoot .Substring(0, viewPathRelativeToViewRoot.Length - Constants.ViewFileExtension.Length)); // --------------- Title = ViewBagPageItem(@"Title", viewContent) ?? ""; // If no key can be found on the page, use url instead. Key = ViewBagPageItem(@"Key", viewContent) ?? Url; Description = ViewBagPageItem(@"Description", viewContent) ?? ""; VersionNameRegex = ViewBagPageItem(@"VersionNameRegex", viewContent) ?? ""; string orderString = ViewBagPageItem(@"Order", viewContent) ?? "1000"; Order = int.Parse(orderString); }
public static MvcHtmlString VersionSwitcher(this HtmlHelper htmlHelper) { if (_versionInfos == null) { return(null); } var versionName = CurrentVersion(); var sb = new StringBuilder(); foreach (var versionInfo in _versionInfos) { if (versionInfo.VersionName == versionName) { // Class is used for bootstrap styling sb.AppendFormat(@"<span class=""btn btn-primary"">{0}</span>", versionInfo.Caption); } else if (versionInfo.VersionUrlOverride != null) { // Class is used for bootstrap styling sb.AppendFormat( @"<a class=""btn btn-default"" href=""{0}"">{1}</a>", versionInfo.VersionUrlOverride, versionInfo.Caption); } else { Uri url = HttpContext.Current.Request.Url; // Class is used for bootstrap styling sb.AppendFormat( @"<a class=""btn btn-default"" href=""{0}"">{1}</a>", UrlHelpers.DomainOnlyUrl(UrlWithVersionUrlName(url, versionInfo.VersionUrlName)), versionInfo.Caption); } } return(new MvcHtmlString(sb.ToString())); }
public string ViewLink(string title = null, string cssClass = null, string fragment = null) { string currentUrl = UrlHelpers.CurrentUrl(); string finalCssClass = cssClass; if (currentUrl == Url) { finalCssClass = (string.IsNullOrEmpty(cssClass) ? "" : (cssClass + " ")) + "selected"; } string finalUrl = Url; if (fragment != null) { finalUrl += "#" + fragment; } return(HtmlHelpers.LinkHtml(finalUrl, title ?? Title, finalCssClass)); }
public static T ByUrl <T>(string url) where T : class, IViewInfo { string cleanedUrl = url ?? ""; if (!cleanedUrl.StartsWith("/")) { cleanedUrl = "/" + cleanedUrl; } cleanedUrl = UrlHelpers.TrimTrailingIndex(cleanedUrl); if (!_viewInfosByUrl.ContainsKey(cleanedUrl)) { throw new ViewExtensionsException(string.Format("Unknown url: {0}", url)); } IViewInfo viewInfo = _viewInfosByUrl[cleanedUrl]; return((T)viewInfo); }
/// <summary> /// Generates a table listing all children (but not their grand children, etc) /// of the current page. /// /// Whether a page is a child depends on its url: /// /a/b current page /// /a/b/c child page /// /// The table has 2 columns: /// 1) link to the child page /// 2) description of the child /// </summary> /// <param name="column1Header"> /// Header of the first column. Header of the second column is always "Description". /// </param> /// <param name="cssClass"> /// Class to be given to the table tag. Leave null if no class to be given. /// </param> /// <returns> /// Html of the table. Null if there are no children. /// </returns> public static string TableChildrenCurrentPage(string column1Header = "Member", string cssClass = null) { string currentUrl = UrlHelpers.CurrentUrl(); int currentUrlNbrComponents = NbrComponents(currentUrl); int childUrlNbrComponents = currentUrlNbrComponents + 1; var sb = new StringBuilder(); sb.AppendLine(string.Format("<table {0}>", HtmlHelpers.ClassAttribute(cssClass))); sb.AppendLine(string.Format(@"<thead><tr><th align=""left"">{0}</th><th align=""left"">Description</th></tr></thead>", column1Header)); sb.AppendLine("<tbody>"); bool viewInfosFound = false; _viewInfos .Where(v => v.Url.StartsWith(currentUrl) && (NbrComponents(v.Url) == childUrlNbrComponents) && v.ShowInMenuForCurrentVersion()) .OrderBy(v => v.Order) .ThenBy(v => v.Url) .ToList() .ForEach(v => { sb.AppendLine(HtmlHelpers.TableRowLinkedHtml(v.Url, v.Title, v.Description)); viewInfosFound = true; }); if (!viewInfosFound) { return(null); } sb.AppendLine("</tbody>"); sb.AppendLine("</table>"); return(sb.ToString()); }