From 2feff82cf98724bb1f8249d681f116459241c929 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 5 Mar 2016 19:50:08 -0500 Subject: add htmlpageview and views/page.cr --- src/guff.cr | 5 ++++- src/guff/html-page-view.cr | 37 +++++++++++++++++++++++++++++++++++++ src/guff/views/page.ecr | 13 +++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/guff/html-page-view.cr create mode 100644 src/guff/views/page.ecr diff --git a/src/guff.cr b/src/guff.cr index 174ec67..b2794b6 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -13,10 +13,13 @@ module Guff def call(context : HTTP::Server::Context) if md = RE.match(context.request.path || "") - context.response.puts "SlugHandler: path = %s, md = %s" % [ + title = "SlugHandler: path = %s, md = %s" % [ context.request.path, md.to_s ] + + context.response.content_type = "text/html; charset=utf-8" + context.response.puts HTMLPageView.new(title, "asdf") else call_next(context) end diff --git a/src/guff/html-page-view.cr b/src/guff/html-page-view.cr new file mode 100644 index 0000000..3ec33fe --- /dev/null +++ b/src/guff/html-page-view.cr @@ -0,0 +1,37 @@ +require "ecr/macros" +require "html" + +module Guff + class HTMLPageView + property :title + property :body + property :scripts + property :styles + property :metas + property :body_id + property :body_class + + def initialize(@title = "" : String, @body = "" : String) + @scripts = [] of String + @styles = [] of String + @metas = [] of Hash(String, String) + end + + def page_headers : String + # TODO + "" + end + + def page_footers : String + # TODO + "" + end + + def h(s : String?) : String + s ? HTML.escape(s) : "" + end + + + ECR.def_to_s("./src/guff/views/page.ecr") + end +end diff --git a/src/guff/views/page.ecr b/src/guff/views/page.ecr new file mode 100644 index 0000000..505731a --- /dev/null +++ b/src/guff/views/page.ecr @@ -0,0 +1,13 @@ + + + + <%= h(@title) %> + <%= page_headers %> + + + <%= + @body + %> + + <%= page_footers %> + -- cgit v1.2.3