diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index bf841c0e5..bb6c61ee9 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -21,6 +21,10 @@ module IconsHelper icon('fas', 'heart') end + def comment_icon + icon('fas', 'comment') + end + def finished_icon icon('fas', 'calendar') end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index c7d7c6c2b..c553b9bfc 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -1,6 +1,27 @@ module PostsHelper def display_post_truncated(post) length = 300 - return truncate(post.body, length: length, separator: ' ', omission: '... ') { link_to "Read more", post_path(post) } + return truncate(strip_tags(post.body), length: length, separator: ' ', omission: '... ') { link_to "Read more", post_path(post) } + end + + def post_byline(post) + byline = 'Posted by ' + + if post.author + byline += link_to post.author.login_name, member_path(post.author) + else + byline += 'Member Deleted' + end + + if post.forum + byline += ' in ' + byline += link_to post.forum, post.forum + end + + byline += " on #{post.created_at}" + + byline += " and edited at #{post.updated_at}" if post.updated_at > post.created_at + + byline.html_safe end end diff --git a/app/views/comments/_single.html.haml b/app/views/comments/_single.html.haml index d3488f4f9..e0726f343 100644 --- a/app/views/comments/_single.html.haml +++ b/app/views/comments/_single.html.haml @@ -1,10 +1,23 @@ -.well - .comment +.card.comment + .card-body .row .col-md-1 = render partial: "members/avatar", locals: { member: comment.author } - .col-md-11 - .comment-meta + .col-md-11.border-left + - if can?(:edit, comment) || can?(:destroy, comment) + .dropdown.float-right + %button#comment-edit-button.btn.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", type: "button"} Actions + .dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "comment-edit-button"} + - if can? :edit, comment + = link_to edit_comment_path(comment), class: 'dropdown-item' do + = edit_icon + Edit + - if can? :destroy, comment + = link_to comment, method: :delete, + data: { confirm: 'Are you sure?' }, class: 'dropdown-item text-danger' do + = delete_icon + Delete + .comment-meta.text-muted Posted by - if comment.author.deleted? Member Deleted @@ -20,10 +33,3 @@ :growstuff_markdown #{ strip_tags comment.body } - - if can?(:edit, comment) || can?(:destroy, comment) - .comment-actions - - if can? :edit, comment - = link_to 'Edit', edit_comment_path(comment), class: 'btn btn-default btn-xs' - - if can? :destroy, comment - = link_to 'Delete', comment, method: :delete, - data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' diff --git a/app/views/comments/new.html.haml b/app/views/comments/new.html.haml index 91f8eef79..e66aba331 100644 --- a/app/views/comments/new.html.haml +++ b/app/views/comments/new.html.haml @@ -1,6 +1,10 @@ = content_for :title, "New comment" -= render partial: "posts/single", locals: { post: @post || @comment.post, subject: true } +%section.blog-post + .card.post{ id: "post-#{@post.id}" } + .card-header + %h2.display-3= @post.subject + .card-body= render "posts/single", post: @post || @comment.post, subject: true = render partial: "posts/comments", locals: { post: @post || @comment.post } diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml index 6132343f1..e06a1a80e 100644 --- a/app/views/posts/_single.html.haml +++ b/app/views/posts/_single.html.haml @@ -1,56 +1,72 @@ +%p + Posted by + - if @post.author + = link_to @post.author.login_name, member_path(@post.author) + - else + Member Deleted + - if @post.forum + in + = link_to @post.forum, @post.forum + on + = @post.created_at + - if @post.updated_at > @post.created_at + and edited at + = @post.updated_at +:growstuff_markdown + #{ strip_tags @post.body } -.card - .post{ id: "post-#{post.id}" } - .row - .col-md-1 - = render partial: "members/avatar", locals: { member: post.author } - .col-md-11 - - if defined?(subject) - %h3= link_to strip_tags(post.subject), post +-# .card +-# .post{ id: "post-#{post.id}" } +-# .row +-# .col-md-1 +-# = render partial: "members/avatar", locals: { member: post.author } +-# .col-md-11 +-# - if defined?(subject) +-# %h3= link_to strip_tags(post.subject), post - .post-meta - %p - Posted by - - if post.author - = link_to post.author.login_name, member_path(post.author) - - else - Member Deleted - - if post.forum - in - = link_to post.forum, post.forum - on - = post.created_at - - if post.updated_at > post.created_at - and edited at - = post.updated_at +-# .post-meta +-# %p +-# Posted by +-# - if post.author +-# = link_to post.author.login_name, member_path(post.author) +-# - else +-# Member Deleted +-# - if post.forum +-# in +-# = link_to post.forum, post.forum +-# on +-# = post.created_at +-# - if post.updated_at > post.created_at +-# and edited at +-# = post.updated_at - .post-body - :growstuff_markdown - #{ strip_tags post.body } +-# .post-body +-# :growstuff_markdown +-# #{ strip_tags post.body } - - unless defined?(hide_comments) - .post-comments - %ul.list-inline - %li.first - = link_to localize_plural(post.comments, Comment), - post_path(post, anchor: 'comments') - - if can? :create, Comment - %li= link_to "Reply", new_comment_path(post_id: post.id) - %li= link_to "Permalink", post - - if can? :edit, post - %li= link_to "Edit", edit_post_path(post) +-# - unless defined?(hide_comments) +-# .post-comments +-# %ul.list-inline +-# %li.first +-# = link_to localize_plural(post.comments, Comment), +-# post_path(post, anchor: 'comments') +-# - if can? :create, Comment +-# %li= link_to "Reply", new_comment_path(post_id: post.id) +-# %li= link_to "Permalink", post +-# - if can? :edit, post +-# %li= link_to "Edit", edit_post_path(post) - .like-count - = pluralize(post.likes.count, "like") unless post.likes.empty? - - if member_signed_in? - - if !post.members.include? current_member - - if can?(:new, Like) - = link_to 'Like', likes_path(post_id: post.id, format: :json), - method: :post, remote: true, class: 'post-like' - - else - - like = post.likes.find_by(member: current_member) - - if like && can?(:destroy, like) - = link_to 'Unlike', like_path(id: like.id, format: :json), - method: :delete, remote: true, class: 'post-like' +-# .like-count +-# = pluralize(post.likes.count, "like") unless post.likes.empty? +-# - if member_signed_in? +-# - if !post.members.include? current_member +-# - if can?(:new, Like) +-# = link_to 'Like', likes_path(post_id: post.id, format: :json), +-# method: :post, remote: true, class: 'post-like' +-# - else +-# - like = post.likes.find_by(member: current_member) +-# - if like && can?(:destroy, like) +-# = link_to 'Unlike', like_path(id: like.id, format: :json), +-# method: :delete, remote: true, class: 'post-like' diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index b4d76e541..e12d99b9a 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -18,14 +18,16 @@ .card .card-body .row - .col-4= render 'members/avatar', member: post.author - .col-8 + .col-2.text-right + = render 'members/avatar', member: post.author + .col-10.border-left %h5.card-title = link_to post.subject, post - if post.comments.size.positive? %span.badge.badge-pill.badge-info.float-right = icon 'fas', 'comment' = post.comments.size + %p.text-muted= post_byline(post) %p.card-text= display_post_truncated(post) - post.crops.each do |crop| %span.badge.badge-pill.badge-primary= link_to crop, crop diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index 1456beada..4ef89d485 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -22,23 +22,9 @@ to: "or to start using #{ENV['GROWSTUFF_SITE_NAME']} to track what you're planting and harvesting" - content_for :buttonbar do - - if can?(:edit, @post) || can?(:destroy, @post) - - if can? :edit, @post - = link_to edit_post_path(@post), class: 'btn' do - = edit_icon - edit - - - if can? :destroy, @post - = link_to @post, method: :delete, - data: { confirm: 'Are you sure?' }, - class: 'btn btn-danger' do - = delete_icon - delete - - if @post.comments.count > 10 && can?(:create, Comment) = link_to 'Comment', new_comment_path(post_id: @post.id), class: 'btn' - - content_for :breadcrumbs do %nav{"aria-label" => "breadcrumb"} %ol.breadcrumb @@ -50,36 +36,32 @@ .row .col-8.col-xs-12 - - / Section: Blog v.4 %section.blog-post .card.post{ id: "post-#{@post.id}" } .card-header - %h2.display-3= @post.subject - .card-body - %p - Posted by - - if @post.author - = link_to @post.author.login_name, member_path(@post.author) - - else - Member Deleted - - if @post.forum - in - = link_to @post.forum, @post.forum - on - = @post.created_at - - if @post.updated_at > @post.created_at - and edited at - = @post.updated_at - :growstuff_markdown - #{ strip_tags @post.body } + %h2.display-3.float-left + = @post.subject + .dropdown.float-right + %button#post-edit-button.btn.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"} Actions + .dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "post-edit-button"} + - if can? :edit, @post + = link_to edit_post_path(@post), class: 'dropdown-item' do + = edit_icon + Edit + - if can? :delete, @post + = link_to post_path(@post), class: 'dropdown-item text-danger', data: { confirm: 'Are you sure?' } do + = delete_icon + Delete + .card-body= render 'posts/single', post: @post .card-footer - - if can? :create, Comment - = link_to new_comment_path(post_id: @post.id), class: 'btn' do - = icon 'fas', 'comment' - Comment + .float-right + - if can? :create, Comment + = link_to new_comment_path(post_id: @post.id), class: 'btn' do + = icon 'fas', 'comment' + Comment + = render "comments", post: @post .col-4.col-xs-12 = render @post.author @@ -94,6 +76,4 @@ - .col-md-12 - = render "comments", post: @post