From 955d28062d6926b5ba30b4e306715e3b0454bd1b Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 27 Jul 2016 21:59:34 -0400 Subject: use theme templates for blog-list-item --- data/themes/default/templates/blog-list-item.html | 8 ++++++++ src/guff/views/blog/list.cr | 19 ++++++++++--------- src/guff/views/template-html.cr | 3 ++- src/views/blog/list-item.ecr | 4 +++- 4 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 data/themes/default/templates/blog-list-item.html diff --git a/data/themes/default/templates/blog-list-item.html b/data/themes/default/templates/blog-list-item.html new file mode 100644 index 0000000..f2c6c9f --- /dev/null +++ b/data/themes/default/templates/blog-list-item.html @@ -0,0 +1,8 @@ +
+ %{name|h}
+ + by %{user_name|h} + on %{posted_at_text|h} +

+ %{body} +
diff --git a/src/guff/views/blog/list.cr b/src/guff/views/blog/list.cr index a98131e..00bd587 100644 --- a/src/guff/views/blog/list.cr +++ b/src/guff/views/blog/list.cr @@ -19,15 +19,16 @@ class Guff::Views::Blog::ListView < Guff::Views::TemplateHTMLView 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, - }, ) + + self.data = { + "name" => TITLE, + "body" => String.build do |io| + # render items + results.rows.each do |row| + theme_templates["blog-list-item.html"].run(io, row) + end + end, + } of String => String end end diff --git a/src/guff/views/template-html.cr b/src/guff/views/template-html.cr index 6ad5859..b7cd8e0 100644 --- a/src/guff/views/template-html.cr +++ b/src/guff/views/template-html.cr @@ -1,12 +1,13 @@ class Guff::Views::TemplateHTMLView < Guff::Views::HTMLView getter :theme_templates + property :data def initialize( context : Context, @theme_id : Int32, @theme_slug : String, @template_id : String, - @data : Hash(String, String), + @data : Hash(String, String) = {} of String => String, @extra_assets : Theme::Assets? = nil, ) super(context) diff --git a/src/views/blog/list-item.ecr b/src/views/blog/list-item.ecr index 23b868e..9a3bc72 100644 --- a/src/views/blog/list-item.ecr +++ b/src/views/blog/list-item.ecr @@ -1,4 +1,6 @@ -
+<% + # deprecated: replaced with theme templates +%>
<%= h(@item["name"]) %>
by <%= h(@item["user_name"]) %> -- cgit v1.2.3