From 385c421b160e9bb7515066ec8ff7205c5c95cfbc Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 27 Jul 2016 21:42:17 -0400 Subject: use theme templates for blog-list --- src/guff/handlers.cr | 11 ++++++----- src/guff/models/site.cr | 19 +++++++++++++++++++ src/guff/views/blog/list.cr | 37 +++++++++++++++++++++++++------------ src/views/blog/list.ecr | 4 +++- src/views/page.ecr | 4 +++- src/views/project.ecr | 4 +++- 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/guff/handlers.cr b/src/guff/handlers.cr index efdf6e0..f0a8571 100644 --- a/src/guff/handlers.cr +++ b/src/guff/handlers.cr @@ -496,21 +496,22 @@ module Guff::Handlers $}x def call(context : HTTP::Server::Context) - if r = find(context.request) + site_id, r = find(context.request) + if site_id && r # TODO: render page context.response.headers["x-frame-options"] = "SAMEORIGIN" context.response.content_type = "text/html; charset=utf-8" context.response.status_code = 200 - Views::Blog::ListView.new(@context, r).to_s(context.response) + Views::Blog::ListView.new(@context, site_id, r).to_s(context.response) else # unknown page call_next(context) end end - private def find(request : HTTP::Request) : PagedResultSet? - r = nil + private def find(request : HTTP::Request) + site_id, r = nil, nil if request.method == "GET" if md = PATH_RE.match(request.path.not_nil!) @@ -530,7 +531,7 @@ module Guff::Handlers end # return result - r + {site_id, r} end end diff --git a/src/guff/models/site.cr b/src/guff/models/site.cr index 99c09dd..431911d 100644 --- a/src/guff/models/site.cr +++ b/src/guff/models/site.cr @@ -47,6 +47,21 @@ class Guff::Models::SiteModel < Guff::Models::Model ORDER BY LOWER(name) ", + + get: " + SELECT a.site_id, + a.name, + a.is_active, + a.is_default, + a.theme_id, + b.theme_slug + + FROM sites a + + JOIN themes b + ON (b.theme_id = a.theme_id) + WHERE a.site_id = ? + " } def get_id(host : String?) : Int64? @@ -70,4 +85,8 @@ class Guff::Models::SiteModel < Guff::Models::Model rows end + + def get(site_id : Int64) + @context.dbs.ro.row(SQL[:get], [site_id.to_s]).not_nil! + end end diff --git a/src/guff/views/blog/list.cr b/src/guff/views/blog/list.cr index 0b26f98..a98131e 100644 --- a/src/guff/views/blog/list.cr +++ b/src/guff/views/blog/list.cr @@ -1,20 +1,33 @@ +require "../template-html" + # # TODO: add y/m/d/page # -class Guff::Views::Blog::ListView < Guff::Views::HTMLView +class Guff::Views::Blog::ListView < Guff::Views::TemplateHTMLView TITLE = "Blog List" - def initialize(context : Context, @results : PagedResultSet) - super(context) - end + def initialize( + context : Context, + site_id : Int64, + results : PagedResultSet + ) + # get site details + site = context.models.site.get(site_id) - def posts - String.build do |io| - @results.rows.each do |row| - ListItemView.new(@context, row).to_s(io) - end - end + super( + context: context, + theme_id: site["theme_id"].as(Int64).to_i32, + theme_slug: site["theme_slug"].as(String), + template_id: "blog-list.html", + data: { + "name" => TITLE, + "body" => String.build do |io| + # render items + results.rows.each do |row| + ListItemView.new(context, row).to_s(io) + end + end, + }, + ) end - - ECR.def_to_s("src/views/blog/list.ecr") end diff --git a/src/views/blog/list.ecr b/src/views/blog/list.ecr index d0a35ca..240a384 100644 --- a/src/views/blog/list.ecr +++ b/src/views/blog/list.ecr @@ -1,4 +1,6 @@ - +<% + # deprecated: replaced with theme templates +%> diff --git a/src/views/page.ecr b/src/views/page.ecr index 54f4c7b..a2dca05 100644 --- a/src/views/page.ecr +++ b/src/views/page.ecr @@ -1,4 +1,6 @@ - +<% + # deprecated: replaced with theme templates +%> diff --git a/src/views/project.ecr b/src/views/project.ecr index 9b1d21b..aba2f91 100644 --- a/src/views/project.ecr +++ b/src/views/project.ecr @@ -1,4 +1,6 @@ - +<% + # deprecated: replaced with theme templates +%> -- cgit v1.2.3