public static void AddFileAndTemplate(this MarkdownFormat markdown, string filePath, string contents) { var pathProvider = (InMemoryVirtualPathProvider)markdown.VirtualPathProvider; pathProvider.WriteFile(filePath, contents); markdown.AddTemplate(filePath, contents); }
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) { TemplatePath = "/path/to/websitetpl", }); return(markdownFormat); }
public void Can_Render_Template_with_section_and_variable_placeholders() { var template = @"## Welcome to Razor! @var lastName = Model.LastName; Hello @Upper(lastName), @Model.FirstName, @section Breadcrumbs { ### Breadcrumbs @Combine("" / "", Model.FirstName, lastName) } @section Menus { ### Menus @foreach (var link in Model.Links) { - @link.Name - @link.Href @var labels = link.Labels @foreach (var label in labels) { - @label } } }"; var websiteTemplate = @"<!doctype html> <html lang=""en-us""> <head> <title><!--@lastName--> page</title> </head> <body> <header> <!--@Menus--> </header> <h1>Website Template</h1> <div id=""content""><!--@Body--></div> <footer> <!--@Breadcrumbs--> </footer> </body> </html>"; var expectedHtml = @"<!doctype html> <html lang=""en-us""> <head> <title>Bellot page</title> </head> <body> <header> <h3>Menus</h3> <ul> <li>ServiceStack - http://www.servicestack.net <ul> <li>REST</li> <li>JSON</li> <li>XML</li> </ul></li> <li>AjaxStack - http://www.ajaxstack.com <ul> <li>HTML5</li> <li>AJAX</li> <li>SPA</li> </ul></li> </ul> </header> <h1>Website Template</h1> <div id=""content""><h2>Welcome to Razor!</h2> <p>Hello BELLOT, Demis,</p> </div> <footer> <h3>Breadcrumbs</h3> <p>Demis / Bellot</p> </footer> </body> </html>".Replace("\r\n", "\n"); markdownFormat.AddTemplate("/path/to/tpl", websiteTemplate); markdownFormat.AddPage( new MarkdownPage(markdownFormat, "/path/to/page-tpl", "DynamicModelTpl", template) { TemplatePath = "/path/to/tpl" }); var templateOutput = markdownFormat.RenderDynamicPageHtml("DynamicModelTpl", person); templateOutput = templateOutput.Replace("\r\n", "\n"); Console.WriteLine(templateOutput); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }
public void Simple_Layout_Example() { var websiteTemplate = @"<!DOCTYPE html> <html> <head> <title>Simple Site</title> </head> <body> <div id=""header""> <a href=""/"">Home</a> <a href=""/About"">About</a> </div> <div id=""body""> <!--@Body--> </div> </body> </html>".NormalizeNewLines(); var pageTemplate = @"@Layout ~/websiteTemplate # About this Site This is some content that will make up the ""about"" page of our web-site. We'll use this in conjunction with a layout template. The content you are seeing here comes from ^^^websiteTemplate. And obviously I can have code in here too. Here is the current date/year: @DateTime.Now.Year "; var expectedHtml = @"<!DOCTYPE html> <html> <head> <title>Simple Site</title> </head> <body> <div id=""header""> <a href=""/"">Home</a> <a href=""/About"">About</a> </div> <div id=""body""> <h1>About this Site</h1> <p>This is some content that will make up the ""about"" page of our web-site. We'll use this in conjunction with a layout template. The content you are seeing here comes from ^^^websiteTemplate.</p> <p>And obviously I can have code in here too. Here is the current date/year: 2011</p> </div> </body> </html>".NormalizeNewLines(); var markdownFormat = new MarkdownFormat(); markdownFormat.AddPage( new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate)); markdownFormat.AddTemplate(@"C:\path\to\websiteTemplate", websiteTemplate); var html = markdownFormat.RenderDynamicPageHtml(PageName); Console.WriteLine(html); Assert.That(html, Is.EqualTo(expectedHtml)); }