From 453ec7234bcc9dd9481e090ea9a64f96fbed4944 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Tue, 1 Dec 2020 12:18:20 +0100 Subject: [PATCH] Initial Commit --- .gitignore | 41 ++++++++++++++++++++++ ln.templates.http.sln | 34 ++++++++++++++++++ ln.templates.http/TemplateRouter.cs | 36 +++++++++++++++++++ ln.templates.http/ln.templates.http.csproj | 21 +++++++++++ 4 files changed, 132 insertions(+) create mode 100644 .gitignore create mode 100644 ln.templates.http.sln create mode 100644 ln.templates.http/TemplateRouter.cs create mode 100644 ln.templates.http/ln.templates.http.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf793ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Autosave files +*~ + +# build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db +.vs/ + +# Mac bundle stuff +*.dmg +*.app + +# resharper +*_Resharper.* +*.Resharper + +# dotCover +*.dotCover diff --git a/ln.templates.http.sln b/ln.templates.http.sln new file mode 100644 index 0000000..700647e --- /dev/null +++ b/ln.templates.http.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.templates.http", "ln.templates.http\ln.templates.http.csproj", "{91A99735-380C-4D9D-B16F-13A4D9CD00D6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Debug|x64.ActiveCfg = Debug|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Debug|x64.Build.0 = Debug|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Debug|x86.ActiveCfg = Debug|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Debug|x86.Build.0 = Debug|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Release|Any CPU.Build.0 = Release|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Release|x64.ActiveCfg = Release|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Release|x64.Build.0 = Release|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Release|x86.ActiveCfg = Release|Any CPU + {91A99735-380C-4D9D-B16F-13A4D9CD00D6}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/ln.templates.http/TemplateRouter.cs b/ln.templates.http/TemplateRouter.cs new file mode 100644 index 0000000..2814bc3 --- /dev/null +++ b/ln.templates.http/TemplateRouter.cs @@ -0,0 +1,36 @@ +using System; +using ln.http; +using ln.http.exceptions; +using ln.http.router; +using ln.templates.html; + +namespace ln.templates.http +{ + public delegate void PrepareRenderContext(TemplateRouter templateRouter,TemplateDocument templateDocument, RenderContext renderContext); + public class TemplateRouter : IHttpRouter + { + ITemplateSource TemplateSource { get; } + + public event PrepareRenderContext OnPrepareRenderContext; + + public TemplateRouter(ITemplateSource templateSource) + { + TemplateSource = templateSource; + } + + public HttpResponse Route(HttpRoutingContext routingContext, HttpRequest httpRequest) + { + TemplateDocument document = TemplateSource.GetTemplateByPath(routingContext.Path); + if (document != null) + { + HttpResponse response = new HttpResponse(httpRequest); + RenderContext renderContext = new RenderContext(response.ContentWriter, TemplateSource); + OnPrepareRenderContext?.Invoke(this, document, renderContext); + document.RenderTemplate(renderContext); + + return response; + } + return null; + } + } +} diff --git a/ln.templates.http/ln.templates.http.csproj b/ln.templates.http/ln.templates.http.csproj new file mode 100644 index 0000000..b174d50 --- /dev/null +++ b/ln.templates.http/ln.templates.http.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp3.1 + + + + 0.0.1-test + Harald Wolff-Thobaben + l--n.de + A IHttpRouter for delivering TemplateDocuments + (c) 2020 Harald Wolff-Thobaben + + + + + + + + +