public void OnBeforeEachTest() { markdownFormat = new MarkdownFormat { VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), "~/".MapProjectPath()), }; }
public MarkdownFormat Create(string pageTemplate) { var markdownFormat = new MarkdownFormat(); markdownFormat.AddPage( new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate)); return markdownFormat; }
public MarkdownPage(MarkdownFormat markdown, string fullPath, string name, string contents, MarkdownPageType pageType) : this() { Markdown = markdown; FilePath = fullPath; Name = name; Contents = contents; PageType = pageType; }
public MarkdownFormat Create(string websiteTemplate, string pageTemplate) { var markdownFormat = new MarkdownFormat { VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()) }; markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate); markdownFormat.AddPage( new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate) { Template = "websiteTemplate", }); return markdownFormat; }
public void TestFixtureSetUp() { var json = "~/AppData/ALFKI.json".MapProjectPath().ReadAllText(); response = JsonSerializer.DeserializeFromString<CustomerDetailsResponse>(json); appHost = new BasicAppHost { ConfigFilter = config => { //Files aren't copied, set RootDirectory to ProjectPath instead. config.WebHostPhysicalPath = "~".MapProjectPath(); } }.Init(); markdownFormat = appHost.GetPlugin<MarkdownFormat>(); }
public MarkdownPage(MarkdownFormat markdown, string fullPath, string name, string contents) : this(markdown, fullPath, name, contents, MarkdownPageType.ViewPage) { }
public void Register(IAppHost appHost) { if (instance == null) instance = this; this.AppHost = appHost; appHost.ViewEngines.Add(this); if (!WatchForModifiedPages) WatchForModifiedPages = appHost.Config.DebugMode; foreach (var ns in appHost.Config.RazorNamespaces) Evaluator.AddAssembly(ns); this.MarkdownBaseType = appHost.Config.MarkdownBaseType ?? this.MarkdownBaseType; this.MarkdownGlobalHelpers = appHost.Config.MarkdownGlobalHelpers ?? this.MarkdownGlobalHelpers; this.ReplaceTokens = appHost.Config.HtmlReplaceTokens ?? new Dictionary<string, string>(); var webHostUrl = appHost.Config.WebHostUrl; if (!webHostUrl.IsNullOrEmpty()) this.ReplaceTokens["~/"] = webHostUrl.WithTrailingSlash(); if (VirtualPathProvider == null) VirtualPathProvider = AppHost.VirtualPathProvider; RegisterMarkdownPages(appHost.Config.WebHostPhysicalPath); appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => { MarkdownPage markdownPage = null; if (catchAllPathsNotFound.Contains(pathInfo)) return null; markdownPage = FindByPathInfo(pathInfo); if (WatchForModifiedPages) ReloadModifiedPageAndTemplates(markdownPage); if (markdownPage == null) { if (pathInfo.EndsWith(".md")) { pathInfo = pathInfo.EndsWithIgnoreCase(DefaultPage + ".md") ? pathInfo.Substring(0, pathInfo.Length - (DefaultPage + ".md").Length) : pathInfo.WithoutExtension(); return new RedirectHttpHandler { AbsoluteUrl = webHostUrl.IsNullOrEmpty() ? null : webHostUrl.CombineWith(pathInfo), RelativeUrl = webHostUrl.IsNullOrEmpty() ? pathInfo : null }; } if (catchAllPathsNotFound.Count > 1000) //prevent DDOS catchAllPathsNotFound = new HashSet<string>(); var tmp = new HashSet<string>(catchAllPathsNotFound) { pathInfo }; catchAllPathsNotFound = tmp; return null; } return new MarkdownHandler(pathInfo) { MarkdownFormat = this, MarkdownPage = markdownPage, RequestName = "MarkdownPage" }; }); appHost.ContentTypes.Register(MimeTypes.MarkdownText, SerializeToStream, null); appHost.ContentTypes.Register(MimeTypes.PlainText, SerializeToStream, null); appHost.Config.IgnoreFormatsInMetadata.Add(MimeTypes.MarkdownText.ToContentFormat()); appHost.Config.IgnoreFormatsInMetadata.Add(MimeTypes.PlainText.ToContentFormat()); }
public void Register(IAppHost appHost) { if (instance == null) { instance = this; } this.AppHost = appHost; appHost.ViewEngines.Add(this); if (!WatchForModifiedPages) { WatchForModifiedPages = appHost.Config.DebugMode; } foreach (var ns in appHost.Config.RazorNamespaces) { Evaluator.AddAssembly(ns); } this.MarkdownBaseType = appHost.Config.MarkdownBaseType ?? this.MarkdownBaseType; this.MarkdownGlobalHelpers = appHost.Config.MarkdownGlobalHelpers ?? this.MarkdownGlobalHelpers; this.ReplaceTokens = appHost.Config.HtmlReplaceTokens ?? new Dictionary <string, string>(); var webHostUrl = appHost.Config.WebHostUrl; if (!webHostUrl.IsNullOrEmpty()) { this.ReplaceTokens["~/"] = webHostUrl.WithTrailingSlash(); } if (VirtualPathProvider == null) { VirtualPathProvider = AppHost.VirtualPathProvider; } RegisterMarkdownPages(appHost.Config.WebHostPhysicalPath); appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => { MarkdownPage markdownPage = null; if (catchAllPathsNotFound.Contains(pathInfo)) { return(null); } markdownPage = FindByPathInfo(pathInfo); if (WatchForModifiedPages) { ReloadModifiedPageAndTemplates(markdownPage); } if (markdownPage == null) { if (pathInfo.EndsWith(".md")) { pathInfo = pathInfo.EndsWithIgnoreCase(DefaultPage + ".md") ? pathInfo.Substring(0, pathInfo.Length - (DefaultPage + ".md").Length) : pathInfo.WithoutExtension(); return(new RedirectHttpHandler { AbsoluteUrl = webHostUrl.IsNullOrEmpty() ? null : webHostUrl.CombineWith(pathInfo), RelativeUrl = webHostUrl.IsNullOrEmpty() ? pathInfo : null }); } if (catchAllPathsNotFound.Count > 1000) //prevent DDOS { catchAllPathsNotFound = new HashSet <string>(); } var tmp = new HashSet <string>(catchAllPathsNotFound) { pathInfo }; catchAllPathsNotFound = tmp; return(null); } return(new MarkdownHandler(pathInfo) { MarkdownFormat = this, MarkdownPage = markdownPage, RequestName = "MarkdownPage" }); }); appHost.ContentTypes.Register(MimeTypes.MarkdownText, SerializeToStream, null); appHost.ContentTypes.Register(MimeTypes.PlainText, SerializeToStream, null); appHost.Config.IgnoreFormatsInMetadata.Add(MimeTypes.MarkdownText.ToContentFormat()); appHost.Config.IgnoreFormatsInMetadata.Add(MimeTypes.PlainText.ToContentFormat()); }