Fixed TemplateRouter
parent
453ec7234b
commit
64d94daa78
|
@ -9,7 +9,8 @@ namespace ln.templates.http
|
||||||
public delegate void PrepareRenderContext(TemplateRouter templateRouter,TemplateDocument templateDocument, RenderContext renderContext);
|
public delegate void PrepareRenderContext(TemplateRouter templateRouter,TemplateDocument templateDocument, RenderContext renderContext);
|
||||||
public class TemplateRouter : IHttpRouter
|
public class TemplateRouter : IHttpRouter
|
||||||
{
|
{
|
||||||
ITemplateSource TemplateSource { get; }
|
public ITemplateSource TemplateSource { get; }
|
||||||
|
public String DefaultTemplatePath { get; set; }
|
||||||
|
|
||||||
public event PrepareRenderContext OnPrepareRenderContext;
|
public event PrepareRenderContext OnPrepareRenderContext;
|
||||||
|
|
||||||
|
@ -20,11 +21,19 @@ namespace ln.templates.http
|
||||||
|
|
||||||
public HttpResponse Route(HttpRoutingContext routingContext, HttpRequest httpRequest)
|
public HttpResponse Route(HttpRoutingContext routingContext, HttpRequest httpRequest)
|
||||||
{
|
{
|
||||||
TemplateDocument document = TemplateSource.GetTemplateByPath(routingContext.Path);
|
string lookupPath = routingContext.Path.Length > 0 ? routingContext.Path.Substring(1) : DefaultTemplatePath;
|
||||||
|
Console.WriteLine("... {0}", lookupPath);
|
||||||
|
|
||||||
|
TemplateDocument document = TemplateSource.GetTemplateByPath(lookupPath);
|
||||||
|
if ((DefaultTemplatePath != null) && (document != null))
|
||||||
|
document = TemplateSource.GetTemplateByPath(DefaultTemplatePath);
|
||||||
|
|
||||||
if (document != null)
|
if (document != null)
|
||||||
{
|
{
|
||||||
HttpResponse response = new HttpResponse(httpRequest);
|
HttpResponse response = new HttpResponse(httpRequest);
|
||||||
RenderContext renderContext = new RenderContext(response.ContentWriter, TemplateSource);
|
RenderContext renderContext = new RenderContext(response.ContentWriter, TemplateSource);
|
||||||
|
renderContext.SetScriptObject("request", httpRequest);
|
||||||
|
renderContext.SetScriptObject("response", response);
|
||||||
OnPrepareRenderContext?.Invoke(this, document, renderContext);
|
OnPrepareRenderContext?.Invoke(this, document, renderContext);
|
||||||
document.RenderTemplate(renderContext);
|
document.RenderTemplate(renderContext);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ln.http" Version="0.1.2"/>
|
<PackageReference Include="ln.http" Version="0.1.2"/>
|
||||||
<PackageReference Include="ln.templates" Version="0.1.0"/>
|
<PackageReference Include="ln.templates" Version="0.1.1"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in New Issue