From fddd4596c03f4dd678229574787cb0e7051554a5 Mon Sep 17 00:00:00 2001 From: Paul Duncan <pabs@pablotron.org> Date: Sun, 13 Mar 2016 00:54:07 -0500 Subject: add views/{html,ecrs}/test --- src/guff/handlers/test-blog.cr | 2 +- src/guff/views/ecrs/test-blog.ecr | 150 -------------------------------------- src/guff/views/ecrs/test/blog.ecr | 150 ++++++++++++++++++++++++++++++++++++++ src/guff/views/html/test-blog.cr | 75 ------------------- src/guff/views/html/test/blog.cr | 75 +++++++++++++++++++ 5 files changed, 226 insertions(+), 226 deletions(-) delete mode 100644 src/guff/views/ecrs/test-blog.ecr create mode 100644 src/guff/views/ecrs/test/blog.ecr delete mode 100644 src/guff/views/html/test-blog.cr create mode 100644 src/guff/views/html/test/blog.cr diff --git a/src/guff/handlers/test-blog.cr b/src/guff/handlers/test-blog.cr index 61f8241..f22ba76 100644 --- a/src/guff/handlers/test-blog.cr +++ b/src/guff/handlers/test-blog.cr @@ -1,5 +1,5 @@ require "../handler" -require "../views/html/test-blog" +require "../views/html/test/blog" class Guff::Handlers::TestBlogHandler < Guff::Handler def call(context : HTTP::Server::Context) diff --git a/src/guff/views/ecrs/test-blog.ecr b/src/guff/views/ecrs/test-blog.ecr deleted file mode 100644 index 1ce4347..0000000 --- a/src/guff/views/ecrs/test-blog.ecr +++ /dev/null @@ -1,150 +0,0 @@ -<h1><%= h(TITLE) %></h1> - -<table> - <thead> - <tr><% POST_SETS.each do |set| %> - <th> - <h2><%= - h(set_name(set)) - %></h2> - </th> - <% end %></tr> - </thead> - - <tbody> - <tr><% POST_SETS.each do |set| %> - <td valign='top'> - <table> - <thead> - <tr> - <th>ID</th> - <th>Created At</th> - <th>Name</th> - <th>Body</th> - <th colspan='2'>Actions</th> - </tr> - </thead> - - <tbody><% posts(set[:id] as String).rows.each do |post| %> - <tr> - <td><%= - h(post.row["post_id"].to_s) - %></td> - - <td><%= - h(post.row["created_at"].to_s) - %></td> - - <td><%= - h(post.row["name"].to_s) - %></td> - - <td><%= - post.row["body"].to_s - %></td> - - <% (set[:actions] as Array(Hash(Symbol, String))).each do |a| %> - <td> - <form - method='post' - action='/test/blog/set_state' - > - <input - type='hidden' - name='post_id' - value='<%= h(post.row["post_id"].to_s) %>' - /> - - <input - type='hidden' - name='state' - value='<%= a[:id] %>' - </input> - - <input - type='submit' - title='Set post to <%= h(a[:id]) %>..' - value='<%= h(a[:name]) %>' - /> - </form> - </td> - <% end %> - </tr> - <% end %></tbody> - </table> - </td> - <% end %></tr> - </tbody> -</table> - -<div class='section'> - <form - method='post' - action='/test/blog/add_post' - > - <fieldset> - <legend>Add Post</legend> - <label for='post-name'> - Name - </label><br/> - - <input - type='text' - id='post-name' - name='name' - title='Enter post title' - placeholder='Post Title' - value='' - /> - - <br/> - - <label for='post-slug'> - Slug - </label><br/> - - <input - type='text' - id='post-slug' - name='slug' - title='Enter post slug' - placeholder='post-slug' - value='' - /> - - <br/> - - <label for='post-body'> - Post Body - </label><br/> - - <textarea - id='post-body' - name='body' - ></textarea> - - <br/> - - <label for='post-tags'> - Tags (space-delimited) - </label><br/> - - <input - type='text' - id='post-tags' - name='tags' - title='Enter post tags' - placeholder='some post tags' - value='' - /> - - <br/> - - <input - type='submit' - title='Create new post.' - value='Add Post' - /> - </fieldset> - </form> -</div> diff --git a/src/guff/views/ecrs/test/blog.ecr b/src/guff/views/ecrs/test/blog.ecr new file mode 100644 index 0000000..1ce4347 --- /dev/null +++ b/src/guff/views/ecrs/test/blog.ecr @@ -0,0 +1,150 @@ +<h1><%= h(TITLE) %></h1> + +<table> + <thead> + <tr><% POST_SETS.each do |set| %> + <th> + <h2><%= + h(set_name(set)) + %></h2> + </th> + <% end %></tr> + </thead> + + <tbody> + <tr><% POST_SETS.each do |set| %> + <td valign='top'> + <table> + <thead> + <tr> + <th>ID</th> + <th>Created At</th> + <th>Name</th> + <th>Body</th> + <th colspan='2'>Actions</th> + </tr> + </thead> + + <tbody><% posts(set[:id] as String).rows.each do |post| %> + <tr> + <td><%= + h(post.row["post_id"].to_s) + %></td> + + <td><%= + h(post.row["created_at"].to_s) + %></td> + + <td><%= + h(post.row["name"].to_s) + %></td> + + <td><%= + post.row["body"].to_s + %></td> + + <% (set[:actions] as Array(Hash(Symbol, String))).each do |a| %> + <td> + <form + method='post' + action='/test/blog/set_state' + > + <input + type='hidden' + name='post_id' + value='<%= h(post.row["post_id"].to_s) %>' + /> + + <input + type='hidden' + name='state' + value='<%= a[:id] %>' + </input> + + <input + type='submit' + title='Set post to <%= h(a[:id]) %>..' + value='<%= h(a[:name]) %>' + /> + </form> + </td> + <% end %> + </tr> + <% end %></tbody> + </table> + </td> + <% end %></tr> + </tbody> +</table> + +<div class='section'> + <form + method='post' + action='/test/blog/add_post' + > + <fieldset> + <legend>Add Post</legend> + <label for='post-name'> + Name + </label><br/> + + <input + type='text' + id='post-name' + name='name' + title='Enter post title' + placeholder='Post Title' + value='' + /> + + <br/> + + <label for='post-slug'> + Slug + </label><br/> + + <input + type='text' + id='post-slug' + name='slug' + title='Enter post slug' + placeholder='post-slug' + value='' + /> + + <br/> + + <label for='post-body'> + Post Body + </label><br/> + + <textarea + id='post-body' + name='body' + ></textarea> + + <br/> + + <label for='post-tags'> + Tags (space-delimited) + </label><br/> + + <input + type='text' + id='post-tags' + name='tags' + title='Enter post tags' + placeholder='some post tags' + value='' + /> + + <br/> + + <input + type='submit' + title='Create new post.' + value='Add Post' + /> + </fieldset> + </form> +</div> diff --git a/src/guff/views/html/test-blog.cr b/src/guff/views/html/test-blog.cr deleted file mode 100644 index 696bfbb..0000000 --- a/src/guff/views/html/test-blog.cr +++ /dev/null @@ -1,75 +0,0 @@ -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 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 -- cgit v1.2.3