本文整理汇总了C#中ServiceStack.WebHost.Endpoints.Support.Markdown.MarkdownPage类的典型用法代码示例。如果您正苦于以下问题:C# MarkdownPage类的具体用法?C# MarkdownPage怎么用?C# MarkdownPage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MarkdownPage类属于ServiceStack.WebHost.Endpoints.Support.Markdown命名空间,在下文中一共展示了MarkdownPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
// Get executing path and /example.md full path
string exeLocation = Assembly.GetExecutingAssembly().Location;
string path = Path.GetDirectoryName( exeLocation );
string template = Path.Combine(path, "example.md");
// Create the markdown-razor template compiler
MarkdownFormat format = new MarkdownFormat();
string contents = File.ReadAllText(template);
var page = new MarkdownPage(format, path, "example", contents );
format.AddPage(page);
// Create our view container (ViewBag)
var view = new Dictionary<string, object>()
{
{ "examples", examples }
};
// Compile and output.
// This can be redirected to html file
// e.g. RazorExample.exe > output.html
var html = format.RenderDynamicPageHtml("example", view);
Console.WriteLine(html);
}
示例2: Init
public void Init(MarkdownPage markdownPage, Dictionary<string, object> scopeArgs,
bool renderHtml, ViewDataDictionary viewData, HtmlHelper htmlHelper)
{
Init(null, null, markdownPage.Markdown, viewData, htmlHelper);
this.RenderHtml = renderHtml;
this.MarkdownPage = markdownPage;
this.ScopeArgs = scopeArgs;
}
示例3: Does_handle_foreach_when_enumerable_is_empty_first_time
public void Does_handle_foreach_when_enumerable_is_empty_first_time()
{
var content = (string)dynamicListPageContent.Clone();
var markdownPage = new MarkdownPage(new MarkdownFormat(), dynamicListPagePath, "", content);
markdownPage.Compile();
var model = new Person { Links = new List<Link>() };
var scopeArgs = new Dictionary<string, object> { { "Model", model } };
markdownPage.RenderToHtml(scopeArgs); // First time the list is empty
var expected = "A new list item";
model.Links.Add(new Link { Name = expected } );
var html = markdownPage.RenderToHtml(scopeArgs); // Second time the list has 1 item
Console.WriteLine(html);
Assert.That(html, Contains.Substring(expected));
}
示例4: RegisterMarkdownPage
public void RegisterMarkdownPage(MarkdownPage markdownPage)
{
AddPage(markdownPage);
}
示例5: ProcessMarkdownPage
public bool ProcessMarkdownPage(IHttpRequest httpReq, MarkdownPage markdownPage, object dto, IHttpResponse httpRes)
{
httpRes.AddHeaderLastModified(markdownPage.GetLastModified());
var renderInTemplate = true;
var renderHtml = true;
string format;
if (httpReq != null && (format = httpReq.QueryString["format"]) != null)
{
renderHtml = !(format.StartsWithIgnoreCase("markdown")
|| format.StartsWithIgnoreCase("text")
|| format.StartsWithIgnoreCase("plain"));
renderInTemplate = !httpReq.GetFormatModifier().StartsWithIgnoreCase("bare");
}
if (!renderHtml)
{
httpRes.ContentType = ContentType.PlainText;
}
var template = httpReq.GetTemplate();
var markup = RenderDynamicPage(markdownPage, markdownPage.Name, dto, renderHtml, renderInTemplate, template);
var markupBytes = markup.ToUtf8Bytes();
httpRes.OutputStream.Write(markupBytes, 0, markupBytes.Length);
return true;
}
示例6: AddPage
public 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;
AddTemplate(templatePath, File.ReadAllText(templatePath));
}
示例7: AddFileAndPage
public static void AddFileAndPage(this MarkdownFormat markdown, MarkdownPage markdownPage)
{
var pathProvider = (InMemoryVirtualPathProvider)markdown.VirtualPathProvider;
pathProvider.AddFile(markdownPage.FilePath, markdownPage.Contents);
markdown.AddPage(markdownPage);
}
开发者ID:grammarware,项目名称:fodder,代码行数:6,代码来源:tests_ServiceStack_ServiceHost_Tests_Formats_MarkdownFormatExtensions.cs
示例8: RenderStaticPage
private string RenderStaticPage(MarkdownPage markdownPage, bool renderHtml)
{
//TODO: Optimize if contains no dynamic elements
return RenderDynamicPage(markdownPage, new Dictionary<string, object>(), renderHtml, true);
}
示例9: RenderDynamicPage
private string RenderDynamicPage(MarkdownPage markdownPage, string pageName, object model, bool renderHtml, bool renderTemplate, string templatePath = null)
{
if (markdownPage == null)
throw new InvalidDataException(ErrorPageNotFound.FormatWith(pageName));
var scopeArgs = new Dictionary<string, object> { { MarkdownPage.ModelName, model } };
return RenderDynamicPage(markdownPage, scopeArgs, renderHtml, renderTemplate, templatePath);
}
示例10: AddPage
public void AddPage(MarkdownPage page)
{
try
{
page.Compile();
AddViewPage(page);
}
catch (Exception ex)
{
Log.Error("AddViewPage() page.Prepare(): " + ex.Message, ex);
}
try
{
var templatePath = page.Template;
if (page.Template == null) return;
if (MasterPageTemplates.ContainsKey(templatePath)) return;
var templateFile = VirtualPathProvider.GetFile(templatePath);
var templateContents = GetPageContents(templateFile);
AddTemplate(templatePath, templateContents);
}
catch (Exception ex)
{
Log.Error("Error compiling template " + page.Template + ": " + ex.Message, ex);
}
}
示例11: GetLatestPage
private IVirtualFile GetLatestPage(MarkdownPage markdownPage)
{
var file = VirtualPathProvider.GetFile(markdownPage.FilePath);
return file;
}
示例12: ReloadIfNeeded
private MarkdownPage ReloadIfNeeded(MarkdownPage markdownPage)
{
if (markdownPage == null || !WatchForModifiedPages) return markdownPage;
if (markdownPage.FilePath != null)
{
var latestPage = GetLatestPage(markdownPage);
if (latestPage == null) return markdownPage;
if (latestPage.LastModified > markdownPage.LastModified)
{
markdownPage.Reload(GetPageContents(latestPage), latestPage.LastModified);
}
}
return markdownPage;
}
示例13: ReloadModifiedPageAndTemplates
public void ReloadModifiedPageAndTemplates(MarkdownPage markdownPage)
{
if (markdownPage == null || !WatchForModifiedPages) return;
ReloadIfNeeded(markdownPage);
IVirtualFile latestPage;
MarkdownTemplate template;
if (markdownPage.DirectiveTemplate != null
&& this.MasterPageTemplates.TryGetValue(markdownPage.DirectiveTemplate, out template))
{
latestPage = GetLatestPage(markdownPage.DirectiveTemplate);
if (latestPage.LastModified > template.LastModified)
template.Reload(GetPageContents(latestPage), latestPage.LastModified);
}
if (markdownPage.Template != null
&& this.MasterPageTemplates.TryGetValue(markdownPage.Template, out template))
{
latestPage = GetLatestPage(template);
if (latestPage.LastModified > template.LastModified)
template.Reload(GetPageContents(latestPage), latestPage.LastModified);
}
}
示例14: ReloadModifiedPageAndTemplates
public void ReloadModifiedPageAndTemplates(MarkdownPage markdownPage)
{
var lastWriteTime = File.GetLastWriteTime(markdownPage.FilePath);
if (lastWriteTime > markdownPage.LastModified)
{
markdownPage.Reload();
}
MarkdownTemplate template;
if (markdownPage.DirectiveTemplatePath != null
&& this.PageTemplates.TryGetValue(markdownPage.DirectiveTemplatePath, out template))
{
lastWriteTime = File.GetLastWriteTime(markdownPage.DirectiveTemplatePath);
if (lastWriteTime > template.LastModified)
ReloadTemplate(template);
}
if (markdownPage.TemplatePath != null
&& this.PageTemplates.TryGetValue(markdownPage.TemplatePath, out template))
{
lastWriteTime = File.GetLastWriteTime(markdownPage.TemplatePath);
if (lastWriteTime > template.LastModified)
ReloadTemplate(template);
}
}
示例15: AddViewPage
private void AddViewPage(MarkdownPage page)
{
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().TrimStart(DirSeps), page);
break;
}
}