From 835af696703484208882a70cc5dd47c5838ecf58 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 12 Oct 2023 17:10:34 -0400 Subject: Added blog post commenting --- app/views/blogs/_blog.html.haml | 2 +- app/views/blogs/show.html.haml | 5 +---- app/views/comments/_comment.html.haml | 13 +++++++++++++ app/views/comments/_form.html.haml | 23 +++++++++++++++++++++++ app/views/comments/_layout.html.haml | 6 ++++++ 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 app/views/comments/_comment.html.haml create mode 100644 app/views/comments/_form.html.haml create mode 100644 app/views/comments/_layout.html.haml (limited to 'app/views') diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index 26657e7..8972c2e 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -15,4 +15,4 @@ %cite.bubble %strong Hatkirby on - = blog.published_at.strftime("%m-%d-%Y") + = blog.published_at.strftime("%B #{blog.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index 9bff12b..0c549ac 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml @@ -1,7 +1,4 @@ - title @blog.title .breadcrumb= link_to "← Back to home page", root_path = render @blog, short: false -%footer#blog-footer - This entry was posted on - = succeed "." do - %time= @blog.published_at.strftime("%B #{@blog.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") += show_comments(@blog) diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml new file mode 100644 index 0000000..3e10759 --- /dev/null +++ b/app/views/comments/_comment.html.haml @@ -0,0 +1,13 @@ +.blog-comment + %blockquote.bubble.rounded.bottom + = image_tag comment.gravatar_url, class: "comment-avatar" + = markdown(comment.body, { restricted: true }) + .clear + %cite.bubble + %strong + - if comment.website.empty? + = comment.username + - else + = link_to comment.username, comment.website + on + = comment.published_at.strftime("%B #{comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") diff --git a/app/views/comments/_form.html.haml b/app/views/comments/_form.html.haml new file mode 100644 index 0000000..f6df807 --- /dev/null +++ b/app/views/comments/_form.html.haml @@ -0,0 +1,23 @@ += form_for @comment || blog.comments.new, html: { id: "comment-form" } do |f| + %fieldset#comment-body-field + %blockquote.bubble.rounded.bottom + = f.label :body + = f.text_area :body + %cite.bubble Feel free to post a comment! You may use Markdown. + - if @comment and @comment.errors.any? + %ul#form-errors + - @comment.errors.full_messages.each do |msg| + %li= msg + %fieldset#comment-other-fields + .comment-name-field.comment-field + .comment-field-label= f.label :username + .comment-field-input= f.text_field :username + .comment-email-field.comment-field + .comment-field-label= f.label :email + .comment-field-input= f.text_field :email, type: :email + .comment-website-field.comment-field + .comment-field-label= f.label :website, "Website (Optional)" + .comment-field-input= f.text_field :website, type: :url + .comment-submit-button.comment-field + .comment-field-label + .comment-field-input= f.submit "Post" diff --git a/app/views/comments/_layout.html.haml b/app/views/comments/_layout.html.haml new file mode 100644 index 0000000..9acf6b0 --- /dev/null +++ b/app/views/comments/_layout.html.haml @@ -0,0 +1,6 @@ +%a{ name: "comments" } +#comments + %h2 Comments + - blog.comments.published_and_ordered.each do |comment| + = render comment + = render "comments/form", blog: blog -- cgit 1.4.1