public MarkdownTemplate AddTemplate(string templatePath, string templateContents) { var templateFile = new FileInfo(templatePath); var templateName = templateFile.FullName.WithoutExtension(); foreach (var markdownReplaceToken in MarkdownReplaceTokens) { templateContents = templateContents.Replace(markdownReplaceToken.Key, markdownReplaceToken.Value); } var template = new MarkdownTemplate(templatePath, templateName, templateContents) { LastModified = templateFile.LastWriteTime, }; PageTemplates.Add(templatePath, template); try { template.Prepare(); return template; } catch (Exception ex) { Log.Error("AddViewPage() template.Prepare(): " + ex.Message, ex); return null; } }
private void AddPage(MarkdownPage page) { try { page.Prepare(); Pages.Add(page.Name, page); } catch (Exception ex) { log.Error("AddPage() page.Prepare(): " + ex.Message, ex); } var templatePath = page.GetTemplatePath(); if (!PageTemplates.ContainsKey(templatePath)) { var templateFile = new FileInfo(templatePath); if (!templateFile.Exists) { PageTemplates.Add(templateFile.FullName, null); return; } var pageContents = File.ReadAllText(templatePath); var template = new MarkdownTemplate( templatePath, templateFile.Name, pageContents); try { template.Prepare(); PageTemplates.Add(template.FilePath, template); } catch (Exception ex) { log.Error("AddPage() template.Prepare(): " + ex.Message, ex); } } }
public MarkdownTemplate AddTemplate(string templatePath, string templateContents) { var templateFile = new FileInfo(templatePath); var templateName = templateFile.FullName.WithoutExtension(); if (!string.IsNullOrEmpty(this.WebHostUrl)) { templateContents = templateContents.Replace(WebHostUrlPlaceHolder, WebHostUrl.WithTrailingSlash()); } var template = new MarkdownTemplate(templatePath, templateName, templateContents) { LastModified = templateFile.LastWriteTime, }; PageTemplates.Add(templatePath, template); try { template.Prepare(); return template; } catch (Exception ex) { Log.Error("AddViewPage() template.Prepare(): " + ex.Message, ex); return null; } }
private void AddPage(MarkdownPage page) { try { page.Prepare(); switch (page.PageType) { case MarkdownPageType.ViewPage: ViewPages.Add(page.Name, page); break; case MarkdownPageType.SharedViewPage: ViewSharedPages.Add(page.Name, page); break; case MarkdownPageType.ContentPage: ContentPages.Add(page.FilePath.WithoutExtension(), page); break; } } catch (Exception ex) { Log.Error("AddViewPage() page.Prepare(): " + ex.Message, ex); } var templatePath = page.TemplatePath; if (page.TemplatePath == null) return; if (PageTemplates.ContainsKey(templatePath)) return; var templateName = Path.GetFileName(templatePath).WithoutExtension(); var pageContents = File.ReadAllText(templatePath); var template = new MarkdownTemplate(templatePath, templateName, pageContents); PageTemplates.Add(templatePath, template); try { template.Prepare(); PageTemplates.Add(template.FilePath, template); } catch (Exception ex) { Log.Error("AddViewPage() template.Prepare(): " + ex.Message, ex); } }
public void Can_Render_MarkdownTemplate() { var template = new MarkdownTemplate(staticTemplatePath, "default", staticTemplateContent); template.Prepare(); Assert.That(template.Blocks.Count, Is.EqualTo(3)); const string mockResponse = "[Replaced with Template]"; var expectedHtml = staticTemplateContent.ReplaceFirst(MarkdownFormat.TemplatePlaceHolder, mockResponse); var templateArgs = new Dictionary<string, object> { { "model", mockResponse } }; var templateOutput = template.RenderToString(templateArgs); Console.WriteLine("Template Output: " + templateOutput); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }