Пример #1
0
		private static ServerContext CreateContext(Dictionary<string, Route> scanResult, Http404Behavior http404Behavior, string rootRequestPath)
		{
			var context = new ServerContext
			{
				Http404Behavior = http404Behavior,
				RootRequestPath = rootRequestPath
			};

			var http404 = scanResult.Keys.FirstOrDefault(x => x.EndsWith("/_error/404"));

			if (http404 != null)
			{
				context.Custom404Page = scanResult[http404].Resource;
				scanResult.Remove(http404);
			}

			var http500 = scanResult.Keys.FirstOrDefault(x => x.EndsWith("/_error/500"));

			if (http500 != null)
			{
				context.Custom500Page = scanResult[http500].Resource;
				scanResult.Remove(http500);
			}

			context.Routes = scanResult;

			return context;
		}
Пример #2
0
		public Server(ServerContext context, RenderingEngine renderingEngine)
		{
			if (context == null) throw new ArgumentNullException(nameof(context));
			if (renderingEngine == null) throw new ArgumentNullException(nameof(renderingEngine));

			_context = context;
			_renderingEngine = renderingEngine;
		}
Пример #3
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);
		}