Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
 private void ReloadTemplate(MarkdownTemplate template)
 {
     var contents = File.ReadAllText(template.FilePath);
     foreach (var markdownReplaceToken in MarkdownReplaceTokens)
     {
         contents = contents.Replace(markdownReplaceToken.Key, markdownReplaceToken.Value);
     }
     template.Reload(contents);
 }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
 private void ReloadTemplate(MarkdownTemplate template)
 {
     var contents = File.ReadAllText(template.FilePath);
     if (!string.IsNullOrEmpty(this.WebHostUrl))
     {
         contents = contents.Replace(WebHostUrlPlaceHolder, WebHostUrl.WithTrailingSlash());
     }
     template.Reload(contents);
 }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        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));
        }