aboutsummaryrefslogtreecommitdiff
path: root/src/guff/handlers
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-08 23:22:03 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-08 23:22:03 -0500
commit94529553ac724a11b6821dd1374c98b0f51b4f14 (patch)
tree61217fd1d344a57a90456e12f62a0358a4863f8b /src/guff/handlers
parent6d3952936c2408f7525941e677db25fb59d34d9b (diff)
downloadold-guff-94529553ac724a11b6821dd1374c98b0f51b4f14.tar.bz2
old-guff-94529553ac724a11b6821dd1374c98b0f51b4f14.zip
initial page rendering
Diffstat (limited to 'src/guff/handlers')
-rw-r--r--src/guff/handlers/blog.cr44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/guff/handlers/blog.cr b/src/guff/handlers/blog.cr
index c95938c..2394354 100644
--- a/src/guff/handlers/blog.cr
+++ b/src/guff/handlers/blog.cr
@@ -1,4 +1,5 @@
require "../handler"
+require "../views/html/page"
class Guff::Handlers::BlogHandler < Guff::Handler
ROUTES = [{
@@ -88,17 +89,52 @@ class Guff::Handlers::BlogHandler < Guff::Handler
call_next(context) unless ROUTES.reduce(false) do |matched, route|
unless matched
if md = (route[:re] as Regex).match(path)
- # matched route
- matched = true
-
- context.response.puts "blog: route = %s, md = %s" % [
+ # log blog route match
+ puts "blog: route = %s, md = %s" % [
route.to_s,
md.to_s
]
+
+ # search for matching posts
+ posts = @models.post.get_posts(
+ filters: get_filters(md),
+ tags: [["foo"]],
+ )
+
+ if posts.size > 0
+ # mark as matched
+ matched = true
+
+ # draw result
+ draw(context, route, posts)
+ end
end
end
matched
end
end
+
+ FILTERS = {
+ year: "year",
+ month: "month",
+ day: "day",
+ slug: "slug",
+ }
+
+ private def get_filters(md) : Hash(Symbol, String)
+ FILTERS.reduce({} of Symbol => String) do |r, k, s|
+ r[k] = md[s] if md[s]?
+ r
+ end
+ end
+
+ private def draw(context, route, posts)
+ # create page
+ page = PageHTMLView.new("Posts", posts.rows.map { |post| post.to_s }.join)
+
+ # render page
+ context.response.content_type = page.content_type
+ context.response.puts page
+ end
end