Esempio n. 1
0
		private void Serve(HttpStatusCode statusCode, Resource context, IDictionary<string, object> environment)
		{
			string content;
			string contentType;

			if (context == null)
			{
				content = statusCode.ToString();
				contentType = "text";
			}
			else
			{
				content = _renderingEngine.Render(context, _context);
				contentType = "text/html";
			}

			Serve(statusCode, contentType, content, environment);
		}
Esempio n. 2
0
		public string Render(Resource resource, ServerContext context)
		{
			if (resource == null) throw new ArgumentNullException(nameof(resource));
			if (context == null) throw new ArgumentNullException(nameof(context));

			var mdBody = resource.Markdown; // todo: read and convert the md file to html

			string templateKey; // todo: actually deal with caching the templates and using the cached versions
			string templateBody;

			if (string.IsNullOrEmpty(resource.Template))
			{
				templateKey = "default";
				templateBody = @"<!DOCTYPE html>
<html>
<head>
	<title>@Model.Title</title>
</head>
<body>
	<h1>@Model.Title</h1>
	@Model.Body
</body>
</html>";
			}
			else
			{
				templateKey = resource.Template;
				templateBody = File.ReadAllText(resource.Template);
			}

			var model = new RenderingContext
			{
				Body = resource.Markdown,
				Title = resource.Markdown
			};

			return Engine.Razor.RunCompile(templateBody, templateKey, typeof(RenderingContext), model);
		}