public static void Main(string[] args) { // Get executing path and /example.md full path string exeLocation = Assembly.GetExecutingAssembly().Location; string path = Path.GetDirectoryName( exeLocation ); string template = Path.Combine(path, "example.md"); // Create the markdown-razor template compiler MarkdownFormat format = new MarkdownFormat(); string contents = File.ReadAllText(template); var page = new MarkdownPage(format, path, "example", contents ); format.AddPage(page); // Create our view container (ViewBag) var view = new Dictionary<string, object>() { { "examples", examples } }; // Compile and output. // This can be redirected to html file // e.g. RazorExample.exe > output.html var html = format.RenderDynamicPageHtml("example", view); Console.WriteLine(html); }
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(); markdownFormat.AddTemplate("/path/to/websitetpl", websiteTemplate); markdownFormat.AddPage( new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate) { Template = "/path/to/websitetpl", }); return markdownFormat; }
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; }
static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) { if (imported.Any(s => s.Contains("AppHost"))) { if (EditorApplication.isCompiling) { var startHosts = MonoBehaviour.FindObjectsOfType(typeof(StartHostBehavior)); foreach (var startHost in startHosts) { var monoScript = MonoScript.FromMonoBehaviour(startHost as MonoBehaviour); if (typeof(StartHostBehavior).IsAssignableFrom(monoScript.GetClass())) { Debug.Log(monoScript.ToJsv()); var host = startHost as StartHost; var hostPath = Path.Combine( Directory.GetCurrentDirectory(), host.webrootPath); var mf = new MarkdownFormat { VirtualPathProvider = new FileSystemVirtualPathProvider( new TestAppHost (), hostPath) }; var mp = mf.FindMarkdownPages("/"); var output = new Dictionary<string, string>(); foreach (var markdownPage in mp) { markdownPage.Compile(); //var view = new Dictionary<string, object>() {{ "examples", examples }}; output.Add(markdownPage.FilePath, markdownPage.RenderToString(new Dictionary<string, object>() { }, true)); } Debug.Log(hostPath); foreach (var outputPage in output) { var outputPath = hostPath + outputPage.Key.Replace('/', '\\') + ".html"; Debug.Log(outputPath); using (var outputStream = File.Create(outputPath)) { outputStream.Write(outputPage.Value); } } } } } } }
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 EndpointHostConfig.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.EndsWith(DefaultPage + ".md", StringComparison.InvariantCultureIgnoreCase) ? 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.ContentTypeFilters.Register(ContentType.MarkdownText, SerializeToStream, null); appHost.ContentTypeFilters.Register(ContentType.PlainText, SerializeToStream, null); appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.MarkdownText.ToContentFormat()); appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.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 EndpointHostConfig.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.ContentTypeFilters.Register(ContentType.MarkdownText, SerializeToStream, null); appHost.ContentTypeFilters.Register(ContentType.PlainText, SerializeToStream, null); appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.MarkdownText.ToContentFormat()); appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.PlainText.ToContentFormat()); }
public void OnBeforeEachTest() { markdownFormat = new MarkdownFormat { VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), "~/".MapProjectPath()), }; }
public void OnBeforeEachTest() { markdownFormat = new MarkdownFormat(); }