diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-10 09:25:07 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-10 09:25:07 -0500 |
commit | 5d7cd9615840341d2ccab1d8b7acfd49d6a5b743 (patch) | |
tree | f2ff9b9f47280826123e962efb95202af11f225a /src | |
parent | adfc9a07d407a9e29bcd7d8af4f24bf7d75c9fe6 (diff) | |
download | old-guff-5d7cd9615840341d2ccab1d8b7acfd49d6a5b743.tar.bz2 old-guff-5d7cd9615840341d2ccab1d8b7acfd49d6a5b743.zip |
rename test to test-blog
Diffstat (limited to 'src')
-rw-r--r-- | src/guff/handlers.cr | 2 | ||||
-rw-r--r-- | src/guff/handlers/test-blog.cr (renamed from src/guff/handlers/test.cr) | 16 | ||||
-rw-r--r-- | src/guff/views/ecrs/test-blog.ecr (renamed from src/guff/views/ecrs/test.ecr) | 42 | ||||
-rw-r--r-- | src/guff/views/html/test-blog.cr | 65 | ||||
-rw-r--r-- | src/guff/views/html/test.cr | 33 |
5 files changed, 80 insertions, 78 deletions
diff --git a/src/guff/handlers.cr b/src/guff/handlers.cr index ba48bbd..834be47 100644 --- a/src/guff/handlers.cr +++ b/src/guff/handlers.cr @@ -22,7 +22,7 @@ module Guff }, { env: %w{development}, init: ->(models : Models) { - TestHandler.new(models) as HTTP::Handler + TestBlogHandler.new(models) as HTTP::Handler }, }, { init: ->(models : Models) { diff --git a/src/guff/handlers/test.cr b/src/guff/handlers/test-blog.cr index f87800e..61f8241 100644 --- a/src/guff/handlers/test.cr +++ b/src/guff/handlers/test-blog.cr @@ -1,14 +1,14 @@ require "../handler" -require "../views/html/test" +require "../views/html/test-blog" -class Guff::Handlers::TestHandler < Guff::Handler +class Guff::Handlers::TestBlogHandler < Guff::Handler def call(context : HTTP::Server::Context) case (context.request.path || "") as String - when /^\/test\/?$/ + when /^\/test\/blog\/?$/ draw_page(context) - when /^\/test\/set_state$/ + when /^\/test\/blog\/set_state$/ set_state(context) - when /^\/test\/add_post$/ + when /^\/test\/blog\/add_post$/ add_post(context) else call_next(context) @@ -16,7 +16,7 @@ class Guff::Handlers::TestHandler < Guff::Handler end private def draw_page(context) - TestHTMLView.run(@models, context) + TestBlogHTMLView.run(@models, context) end private def add_post(context) @@ -29,7 +29,7 @@ class Guff::Handlers::TestHandler < Guff::Handler tags: ["_blog"] + (params["tags"] || "").to_s.split(" "), ) - redirect(context, "/test") + redirect(context, "/test/blog") end private def set_state(context) @@ -40,6 +40,6 @@ class Guff::Handlers::TestHandler < Guff::Handler state: params["state"].to_s, ) - redirect(context, "/test") + redirect(context, "/test/blog") end end diff --git a/src/guff/views/ecrs/test.ecr b/src/guff/views/ecrs/test-blog.ecr index d36b62c..f28966a 100644 --- a/src/guff/views/ecrs/test.ecr +++ b/src/guff/views/ecrs/test-blog.ecr @@ -1,40 +1,10 @@ <h1><%= h(TITLE) %></h1> <% - [{ - id: "draft", - name: "Draft Posts", - - 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", - }], - }].each do |kind| + POST_SETS.each do |set| %> <h2><%= - h(kind[:name] as String) + h(set[:name] as String) %></h2> <table> @@ -48,7 +18,7 @@ </tr> </thead> - <tbody><% posts(kind[:id] as String).rows.each do |post| %> + <tbody><% posts(set[:id] as String).rows.each do |post| %> <tr> <td><%= h(post.row["post_id"].to_s) @@ -66,11 +36,11 @@ post.row["body"].to_s %></td> - <% (kind[:actions] as Array(Hash(Symbol, String))).each do |a| %> + <% (set[:actions] as Array(Hash(Symbol, String))).each do |a| %> <td> <form method='post' - action='/test/set_state' + action='/test/blog/set_state' > <input type='hidden' @@ -100,7 +70,7 @@ <div class='section'> <form method='post' - action='/test/add_post' + action='/test/blog/add_post' > <label for='post-name'> Name diff --git a/src/guff/views/html/test-blog.cr b/src/guff/views/html/test-blog.cr new file mode 100644 index 0000000..9ad91f3 --- /dev/null +++ b/src/guff/views/html/test-blog.cr @@ -0,0 +1,65 @@ +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) + 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) + @models.post.get_posts( + tags: [["_blog"]], + filters: { state: state } + ) + end + + def h(s : String) + HTML.escape(s || "") + end + + ECR.def_to_s("./src/guff/views/ecrs/test-blog.ecr") +end diff --git a/src/guff/views/html/test.cr b/src/guff/views/html/test.cr deleted file mode 100644 index 37317e5..0000000 --- a/src/guff/views/html/test.cr +++ /dev/null @@ -1,33 +0,0 @@ -require "html" -require "ecr/macros" -require "./page" - -class Guff::TestHTMLView - TITLE = "Guff Blog Test" - - def self.run(models, context : HTTP::Server::Context) - new(models).run(context) - end - - def initialize(@models : Models) - 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) - @models.post.get_posts( - tags: [["_blog"]], - filters: { state: state } - ) - end - - def h(s : String) - HTML.escape(s || "") - end - - ECR.def_to_s("./src/guff/views/ecrs/test.ecr") -end |