From 911d4fa9eb9f42e65facfa63e46ffcba660766ad Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 27 Jul 2016 22:09:34 -0400 Subject: use theme templates for blog-post --- src/guff/handlers.cr | 11 ++++++----- src/guff/views/blog/post.cr | 23 ++++++++++++++++++----- src/views/blog/post.ecr | 4 +++- 3 files changed, 27 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/guff/handlers.cr b/src/guff/handlers.cr index f0a8571..2670f89 100644 --- a/src/guff/handlers.cr +++ b/src/guff/handlers.cr @@ -444,20 +444,21 @@ module Guff::Handlers $}x def call(context : HTTP::Server::Context) - if r = get(context.request) + site_id, r = get(context.request) + if site_id && r context.response.headers["x-frame-options"] = "SAMEORIGIN" context.response.content_type = "text/html; charset=utf-8" context.response.status_code = 200 - Views::Blog::PostView.new(@context, r).to_s(context.response) + Views::Blog::PostView.new(@context, site_id, r).to_s(context.response) else # unknown page call_next(context) end end - private def get(request : HTTP::Request) : Hash(String, String)? - r = nil + private def get(request : HTTP::Request) + site_id, r = nil, nil if request.method == "GET" if md = PATH_RE.match(request.path.not_nil!) @@ -478,7 +479,7 @@ module Guff::Handlers end # return result - r + {site_id, r} end end diff --git a/src/guff/views/blog/post.cr b/src/guff/views/blog/post.cr index 4b1dc1e..4bc5282 100644 --- a/src/guff/views/blog/post.cr +++ b/src/guff/views/blog/post.cr @@ -1,7 +1,20 @@ -class Guff::Views::Blog::PostView < Guff::Views::HTMLView - def initialize(context : Context, @item : Hash(String, String)) - super(context) - end +require "../template-html" + +class Guff::Views::Blog::PostView < Guff::Views::TemplateHTMLView + def initialize( + context : Context, + site_id : Int64, + item : Hash(String, String) + ) + # get site details + site = context.models.site.get(site_id) - ECR.def_to_s("src/views/blog/post.ecr") + super( + context: context, + theme_id: site["theme_id"].as(Int64).to_i32, + theme_slug: site["theme_slug"].as(String), + template_id: "blog-post.html", + data: item, + ) + end end diff --git a/src/views/blog/post.ecr b/src/views/blog/post.ecr index d0aa534..08ac564 100644 --- a/src/views/blog/post.ecr +++ b/src/views/blog/post.ecr @@ -1,4 +1,6 @@ - +<% + # deprecated: switched to theme templates +%> -- cgit v1.2.3