From 7e24e13e887d441fd82a8d427913cfe36d5682da Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 6 Mar 2016 02:13:07 -0500 Subject: s/HTMLPageView/PageHTMLView/ --- src/guff.cr | 2 +- src/guff/api-docs-html-view.cr | 4 +-- src/guff/html-page-view.cr | 66 ------------------------------------------ src/guff/page-html-view.cr | 66 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 src/guff/html-page-view.cr create mode 100644 src/guff/page-html-view.cr diff --git a/src/guff.cr b/src/guff.cr index 533a10f..afab4a4 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -18,7 +18,7 @@ module Guff md.to_s ] - page = HTMLPageView.new(title, "asdf") + page = PageHTMLView.new(title, "asdf") page.styles << "foo/bar.css" # TODO: refactor this diff --git a/src/guff/api-docs-html-view.cr b/src/guff/api-docs-html-view.cr index e3f1097..83c28d0 100644 --- a/src/guff/api-docs-html-view.cr +++ b/src/guff/api-docs-html-view.cr @@ -1,6 +1,6 @@ require "html" require "ecr/macros" -require "./html-page-view" +require "./page-html-view" require "./api-methods" module Guff @@ -8,7 +8,7 @@ module Guff TITLE = "Guff API Documentation" def self.run(context : HTTP::Server::Context) - page = HTMLPageView.new(TITLE, new.to_s) + page = PageHTMLView.new(TITLE, new.to_s) context.response.content_type = page.content_type context.response.puts page end diff --git a/src/guff/html-page-view.cr b/src/guff/html-page-view.cr deleted file mode 100644 index e1f69a7..0000000 --- a/src/guff/html-page-view.cr +++ /dev/null @@ -1,66 +0,0 @@ -require "ecr/macros" -require "html" - -module Guff - class HTMLPageView - property :charset - property :lang - property :title - property :body - property :scripts - property :styles - property :metas - property :body_id - property :body_class - - FORMATS = { - attr: "%s='%s'", - meta: "", - style: "", - script: "", - } - - def initialize(@title = "" : String, @body = "" : String) - @charset = "utf-8" - @lang = "en-US" - @scripts = [] of String - @styles = [] of String - @metas = [] of Hash(String, String) - end - - def body_attrs - { - "id": @body_id, - "class": @body_class, - }.map { |k, v| attr(k, v) }.join(" ") - end - - def page_headers : String - (@metas.map { |meta| - FORMATS[:meta] % [meta.map { |k, v| attr(k, v) }.join(" ")] - } + @styles.map { |path| - FORMATS[:style] % [h(path)] - }).join("") - end - - def page_footers : String - @scripts.map { |path| - FORMATS[:style] % [h(path)] - }.join("") - end - - def h(s : String?) : String - s ? HTML.escape(s) : "" - end - - def attr(k : String, v : String?) : String - v ? FORMATS[:attr] % [k, h(v)] : "" - end - - def content_type - "text/html; charset=%s" % [@charset] - end - - ECR.def_to_s("./src/guff/views/page.ecr") - end -end diff --git a/src/guff/page-html-view.cr b/src/guff/page-html-view.cr new file mode 100644 index 0000000..42ea454 --- /dev/null +++ b/src/guff/page-html-view.cr @@ -0,0 +1,66 @@ +require "ecr/macros" +require "html" + +module Guff + class PageHTMLView + property :charset + property :lang + property :title + property :body + property :scripts + property :styles + property :metas + property :body_id + property :body_class + + FORMATS = { + attr: "%s='%s'", + meta: "", + style: "", + script: "", + } + + def initialize(@title = "" : String, @body = "" : String) + @charset = "utf-8" + @lang = "en-US" + @scripts = [] of String + @styles = [] of String + @metas = [] of Hash(String, String) + end + + def body_attrs + { + "id": @body_id, + "class": @body_class, + }.map { |k, v| attr(k, v) }.join(" ") + end + + def page_headers : String + (@metas.map { |meta| + FORMATS[:meta] % [meta.map { |k, v| attr(k, v) }.join(" ")] + } + @styles.map { |path| + FORMATS[:style] % [h(path)] + }).join("") + end + + def page_footers : String + @scripts.map { |path| + FORMATS[:style] % [h(path)] + }.join("") + end + + def h(s : String?) : String + s ? HTML.escape(s) : "" + end + + def attr(k : String, v : String?) : String + v ? FORMATS[:attr] % [k, h(v)] : "" + end + + def content_type + "text/html; charset=%s" % [@charset] + end + + ECR.def_to_s("./src/guff/views/page.ecr") + end +end -- cgit v1.2.3