Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (48 sloc) 1.552 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
using System;
using ServiceStack.WebHost.Endpoints.Formats;
using ServiceStack.WebHost.Endpoints.Support.Markdown;
using System.Reflection;
using System.IO;
using System.Collections.Generic;

namespace RazorExample
{
class MainClass
{
// Stub some example objects
static List<Example> examples = new List<Example>() {
new Example { Name="Phil", Number=1 },
new Example { Name="Frank", Number=2 },
new Example { Name="Sally", Number=3 },
new Example { Name="Ralph", Number=4 },
new Example { Name="Ginny", Number=5 },
new Example { Name="Gomer", Number=6 },
new Example { Name="Alicia", Number=7 },
};

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);
}
}

class Example {
public string Name;
public int Number;
}
}
Something went wrong with that request. Please try again.