From 5d7cd9615840341d2ccab1d8b7acfd49d6a5b743 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 10 Mar 2016 09:25:07 -0500 Subject: rename test to test-blog --- src/guff/handlers/test-blog.cr | 45 ++++++++++++++++++++++++++++++++++++++++++ src/guff/handlers/test.cr | 45 ------------------------------------------ 2 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 src/guff/handlers/test-blog.cr delete mode 100644 src/guff/handlers/test.cr (limited to 'src/guff/handlers') diff --git a/src/guff/handlers/test-blog.cr b/src/guff/handlers/test-blog.cr new file mode 100644 index 0000000..61f8241 --- /dev/null +++ b/src/guff/handlers/test-blog.cr @@ -0,0 +1,45 @@ +require "../handler" +require "../views/html/test-blog" + +class Guff::Handlers::TestBlogHandler < Guff::Handler + def call(context : HTTP::Server::Context) + case (context.request.path || "") as String + when /^\/test\/blog\/?$/ + draw_page(context) + when /^\/test\/blog\/set_state$/ + set_state(context) + when /^\/test\/blog\/add_post$/ + add_post(context) + else + call_next(context) + end + end + + private def draw_page(context) + TestBlogHTMLView.run(@models, context) + end + + private def add_post(context) + params = HTTP::Params.parse(context.request.body as String) + + @models.post.add_post( + name: params["name"].to_s, + slug: params["slug"].to_s, + body: params["body"].to_s, + tags: ["_blog"] + (params["tags"] || "").to_s.split(" "), + ) + + redirect(context, "/test/blog") + end + + private def set_state(context) + params = HTTP::Params.parse(context.request.body as String) + + @models.post.update_post( + post_id: params["post_id"].to_i, + state: params["state"].to_s, + ) + + redirect(context, "/test/blog") + end +end diff --git a/src/guff/handlers/test.cr b/src/guff/handlers/test.cr deleted file mode 100644 index f87800e..0000000 --- a/src/guff/handlers/test.cr +++ /dev/null @@ -1,45 +0,0 @@ -require "../handler" -require "../views/html/test" - -class Guff::Handlers::TestHandler < Guff::Handler - def call(context : HTTP::Server::Context) - case (context.request.path || "") as String - when /^\/test\/?$/ - draw_page(context) - when /^\/test\/set_state$/ - set_state(context) - when /^\/test\/add_post$/ - add_post(context) - else - call_next(context) - end - end - - private def draw_page(context) - TestHTMLView.run(@models, context) - end - - private def add_post(context) - params = HTTP::Params.parse(context.request.body as String) - - @models.post.add_post( - name: params["name"].to_s, - slug: params["slug"].to_s, - body: params["body"].to_s, - tags: ["_blog"] + (params["tags"] || "").to_s.split(" "), - ) - - redirect(context, "/test") - end - - private def set_state(context) - params = HTTP::Params.parse(context.request.body as String) - - @models.post.update_post( - post_id: params["post_id"].to_i, - state: params["state"].to_s, - ) - - redirect(context, "/test") - end -end -- cgit v1.2.3