-
Notifications
You must be signed in to change notification settings - Fork 17
Use with Asp.Net MVC
You can either setup it manually in a few steps, or you can use the NuGet package that installs the Controller etc. to your project automatically.
#Kiwi.Mvc-package for automatic setup It's dead simple. Fire up an Asp.Net MVC3 project and open the Package manager console and type:
Install-Package Kiwi.Mvc3
#Manual setup ##Setup a Controller For this example I will use a live one. The GitHub Wiki for SisoDb which also has the wiki at http://sisodb.com/wiki
My controller is really simple. One Action and a cache profile, nothing more.
WikiController
[HandleError]
public class WikiController : Controller
{
[OutputCache(CacheProfile = "KiwiWikiCache")]
public ActionResult Doc(string docId)
{
return View(MvcApplication.MarkdownService.GetDocument(docId));
}
}
Web.config
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="KiwiWikiCache" duration="3600" varyByParam="docId"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
##Fix a route My route is going to match http://sisodb.com/wiki and http://sisodb.com/wiki/{docid} where docId matches the name of the Markdown file except the file suffix.
Global.asax
routes.MapRoute(
"Wiki", // Route name
"wiki/{docId}", // URL with parameters
new { controller = "wiki", action = "doc", docId = "home" } // Parameter defaults
);
##Setup a MarkdownService A bit temporary, but as for now I've just put a static member in Global.Asax.
MarkdownService = new MarkdownService(new FileContentProvider(Server.MapPath("~/App_Data/MarkdownFiles"));
You can also see that I have decided to reside my Markdow files under "~/App_Data/MarkdownFiles". There's nothing stopping you from using MarkdownService outside a webbapplication, it has no dependencies on any web stack.
We need a view that will render the Markdown document that our controller gets from the MarkdownService
.
Wiki/Doc.cshtml
@using Kiwi.Markdown
@model Document
@{
ViewBag.Title = @Model.Title;
}
<h1>@Model.Title</h1>
<p>@Html.Raw(Model.Content)</p>
That's it. Nothing more. There will be other Kiwi components coming that will assist you with the publishing etc of new Markdown files.
#Get the Markdown files
Go to the Wiki at your GitHub project and check under Git Access example Bring down the files using git clone
Take the files and put them in the ASP.Net MVC application's folder containing Markdown files (App_Data/Markdownfiles).
When moving the files to a server, you can use the strengths and features of Git.
# Clone and Get the Wiki locally
git clone git://github.com/danielwertheim/Kiwi.wiki.git
# Create a Zip which you can upload
git archive master --format=zip -o Kiwi-Package.zip
I'm working on a small MVC area that will let you complement the flow above with something like:
# Upload the Zip using Curl
curl --upload-file [email protected] http://sisodb.com/kiwi/package/put
Of course, the example above misses out setting headers for security, info but I guess you get the point.