From 7577c32a83d2897617fb60f488d6d71cd23be698 Mon Sep 17 00:00:00 2001
From: Paul Duncan <pabs@pablotron.org>
Date: Fri, 15 Jul 2016 19:46:16 -0400
Subject: add initial blog list templates

---
 src/guff.cr                  | 30 ++++++++++++++++++++++++++++--
 src/views/blog/list-item.ecr |  3 +++
 src/views/blog/list.ecr      | 25 +++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 src/views/blog/list-item.ecr
 create mode 100644 src/views/blog/list.ecr

(limited to 'src')

diff --git a/src/guff.cr b/src/guff.cr
index 2343d12..9791288 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -2122,8 +2122,33 @@ module Guff
       ECR.def_to_s("src/views/logout-page.ecr")
     end
 
+    class BlogListItemView < HTMLView
+      def initialize(context : Context, @post_id : Int64)
+        super(context)
+      end
+
+      ECR.def_to_s("src/views/blog/list-item.ecr")
+    end
+
+    #
+    # TODO: add y/m/d/page
+    #
     class BlogListView < HTMLView
-      ECR.def_to_s("src/views/blog-list.ecr")
+      TITLE = "Blog List"
+
+      def initialize(context : Context, @post_ids : Array(Int64))
+        super(context)
+      end
+
+      def posts
+        String.build do |io|
+          @post_ids.each do |id|
+            BlogListItemView.new(@context, id).to_s(io)
+          end
+        end
+      end
+
+      ECR.def_to_s("src/views/blog/list.ecr")
     end
   end
 
@@ -2599,7 +2624,8 @@ module Guff
           context.response.headers["x-frame-options"] = "SAMEORIGIN"
           context.response.content_type = "text/html; charset=utf-8"
           context.response.status_code = 200
-          context.response << "blog list: ids = #{ids.join(", ")}"
+
+          Views::BlogListView.new(@context, ids).to_s(context.response)
         else
           # unknown page
           call_next(context)
diff --git a/src/views/blog/list-item.ecr b/src/views/blog/list-item.ecr
new file mode 100644
index 0000000..13131e0
--- /dev/null
+++ b/src/views/blog/list-item.ecr
@@ -0,0 +1,3 @@
+<div class='post'>
+  id: <%= @post_id %>
+</div>
diff --git a/src/views/blog/list.ecr b/src/views/blog/list.ecr
new file mode 100644
index 0000000..d0a35ca
--- /dev/null
+++ b/src/views/blog/list.ecr
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang='en-US'>
+  <head>
+    <meta charset="utf-8"/>
+    <title><%=
+      h(TITLE)
+    %></title>
+
+    <%
+      # TODO: add theme styles
+    %>
+  </head>
+
+  <body>
+    <b>blog list</b>
+
+    <div class='posts'><%=
+      posts
+    %></div><!-- posts -->
+  </body>
+
+  <%
+    # TODO: add theme scripts
+  %>
+</html>
-- 
cgit v1.2.3