diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-13 00:54:07 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-13 00:54:07 -0500 |
commit | fddd4596c03f4dd678229574787cb0e7051554a5 (patch) | |
tree | 1e6f482c27ee537d8075824b6e0f6f8db93fad93 /src/guff/views/html/test | |
parent | 3800ec5dad2834f1da281ded998bfd13d4233550 (diff) | |
download | old-guff-fddd4596c03f4dd678229574787cb0e7051554a5.tar.bz2 old-guff-fddd4596c03f4dd678229574787cb0e7051554a5.zip |
add views/{html,ecrs}/test
Diffstat (limited to 'src/guff/views/html/test')
-rw-r--r-- | src/guff/views/html/test/blog.cr | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/guff/views/html/test/blog.cr b/src/guff/views/html/test/blog.cr new file mode 100644 index 0000000..5f7372f --- /dev/null +++ b/src/guff/views/html/test/blog.cr @@ -0,0 +1,75 @@ +require "html" +require "ecr/macros" +require "../page" + +class Guff::TestBlogHTMLView + TITLE = "Guff Blog Test" + + POST_SETS = [{ + id: "draft", + name: "Drafts", + + actions: [{ + id: "posted", + name: "Post", + }, { + id: "deleted", + name: "Delete", + }], + }, { + id: "posted", + name: "Posted", + + actions: [{ + id: "draft", + name: "Draft", + }, { + id: "deleted", + name: "Delete", + }], + }, { + id: "deleted", + name: "Deleted Posts", + + actions: [{ + id: "draft", + name: "Draft", + }], + }] + + def self.run(models, context : HTTP::Server::Context) + new(models).run(context) + end + + def initialize(@models : Models) + @posts = {} of String => Results(Post) + end + + def run(context) + page = PageHTMLView.new(TITLE, self.to_s) + context.response.content_type = page.content_type + context.response.puts page + end + + private def posts(state : String) + @posts[state] ||= @models.post.get_posts( + tags: [["_blog"]], + filters: { state: state } + ) + end + + SET_TITLE_FORMAT = "%s (%d posts)" + + private def set_name(set) + "%s (%d posts)" % [ + set[:name] as String, + posts(set[:id] as String).num_rows + ] + end + + def h(s : String) + HTML.escape(s || "") + end + + ECR.def_to_s("./src/guff/views/ecrs/test/blog.ecr") +end |