/// <summary>Creates a new MarkdownFormat.</summary> /// /// <param name="websiteTemplate">The website template.</param> /// <param name="pageTemplate"> The page template.</param> /// /// <returns>A MarkdownFormat.</returns> 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 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 ".NormalizeNewLines(); 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: 2021</p> </div> </body> </html>".NormalizeNewLines(); markdownFormat.AddFileAndPage( new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate)); markdownFormat.AddFileAndTemplate(@"websiteTemplate", websiteTemplate); var html = markdownFormat.RenderDynamicPageHtml(PageName); Console.WriteLine(html); Assert.That(html, Is.EqualTo(expectedHtml)); }
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 } } }".NormalizeNewLines(); 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>".NormalizeNewLines(); 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>".NormalizeNewLines(); markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate); markdownFormat.AddPage( new MarkdownPage(markdownFormat, "/path/to/page-tpl", "DynamicModelTpl", template) { Template = "websiteTemplate" }); var templateOutput = markdownFormat.RenderDynamicPageHtml("DynamicModelTpl", person); templateOutput = templateOutput.Replace("\r\n", "\n"); Console.WriteLine(templateOutput); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }