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); } }
public MarkdownTemplate AddTemplate(string templatePath, string templateContents) { MarkdownTemplate template; if (MasterPageTemplates.TryGetValue(templatePath, out template)) { return(template); } var templateFile = VirtualPathProvider.GetFile(templatePath); var templateName = templateFile.Name.WithoutExtension(); template = new MarkdownTemplate(templatePath, templateName, templateContents) { LastModified = templateFile.LastModified, }; MasterPageTemplates.Add(templatePath, template); try { template.Prepare(); return(template); } catch (Exception ex) { Log.Error("AddViewPage() template.Prepare(): " + ex.Message, ex); return(null); } }
public void Can_Render_MarkdownTemplate() { var template = new MarkdownTemplate(staticTemplatePath, "default", staticTemplateContent); template.Prepare(); Assert.That(template.TextBlocks.Length, Is.EqualTo(2)); const string mockResponse = "[Replaced with Template]"; var expectedHtml = staticTemplateContent.ReplaceFirst(MarkdownFormat.TemplatePlaceHolder, mockResponse); var mockArgs = new Dictionary <string, object> { { MarkdownTemplate.BodyPlaceHolder, mockResponse } }; var templateOutput = template.RenderToString(mockArgs); Console.WriteLine("Template Output: " + templateOutput); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }