diff --git a/Gemfile b/Gemfile index f916ad5b..7093ddad 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,9 @@ gem 'puma' # Ruby on Rails framework gem 'rails' +# Markdown renderer +gem 'redcarpet' + # Background job library on top of Redis gem 'resque' diff --git a/Gemfile.lock b/Gemfile.lock index 3fe15037..102a2c04 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -186,7 +186,7 @@ GEM activerecord (>= 6.1) request_store (~> 1.4) parallel (1.24.0) - parser (3.3.0.5) + parser (3.3.2.0) ast (~> 2.4.1) racc pg (1.5.6) @@ -194,7 +194,7 @@ GEM stringio puma (6.4.2) nio4r (~> 2.0) - racc (1.7.3) + racc (1.8.0) rack (2.2.9) rack-protection (3.1.0) rack (~> 2.2, >= 2.2.4) @@ -241,13 +241,14 @@ GEM ffi (~> 1.0) rdoc (6.6.3.1) psych (>= 4.0.0) + redcarpet (3.6.0) redis (5.0.7) redis-client (>= 0.9.0) redis-client (0.16.0) connection_pool redis-namespace (1.11.0) redis (>= 4) - regexp_parser (2.9.0) + regexp_parser (2.9.2) reline (0.5.1) io-console (~> 0.5) request_store (1.5.1) @@ -265,7 +266,8 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rexml (3.2.6) + rexml (3.2.8) + strscan (>= 3.0.9) rouge (4.1.2) rspec-core (3.13.0) rspec-support (~> 3.13.0) @@ -284,7 +286,7 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) - rubocop (1.60.2) + rubocop (1.64.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -292,11 +294,11 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.31.2) - parser (>= 3.3.0.4) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) rubocop-capybara (2.20.0) rubocop (~> 1.41) rubocop-factory_bot (2.25.1) @@ -341,6 +343,7 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) stringio (3.1.0) + strscan (3.1.0) thor (1.3.1) tilt (2.2.0) timeout (0.4.1) @@ -388,6 +391,7 @@ DEPENDENCIES pg puma rails + redcarpet resque rspec-rails rubocop diff --git a/app/models/comment.rb b/app/models/comment.rb index 1d39b4a6..5aba826b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -8,7 +8,7 @@ class Comment < ApplicationRecord default_scope { order(:id) } - auto_strip_attributes :text, squish: true + auto_strip_attributes :text def formatted_date created_at.strftime('%e %b @ %H:%M').squish diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 0e4699a7..49fd478e 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -4,10 +4,11 @@ <%= f.hidden_field :home_id, value: comment.home_id %> <div class="input-group"> - <%= f.text_field :text, + <%= f.text_area :text, class: 'form-control', placeholder: ['I think...', 'Love this!', 'What about ...', 'No. Way.', 'Ermahgerd!'].sample, required: true, + rows: comment.new_record? ? 3 : 10, autocomplete: 'off' %> <div class="input-group-append"> <%= f.submit comment.new_record? ? 'Comment' : 'Update', diff --git a/app/views/comments/_list.html.erb b/app/views/comments/_list.html.erb index d53e4b2c..467e6e90 100644 --- a/app/views/comments/_list.html.erb +++ b/app/views/comments/_list.html.erb @@ -1,3 +1,4 @@ +<% markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) %> <% if comments.each do |comment| %> <div class="media mt-2 mb-2 comment"> <%= image_tag comment.user.gravatar_url(70), @@ -8,19 +9,19 @@ <%= comment.user.display_name %> : <small> <%= comment.formatted_date %> + <% if comment.user == current_user %> + <span class="manage-comment-controls"> + <%= link_to fa_icon_inline('edit', type: :duotone), + edit_comment_path(comment) %> + <%= link_to fa_icon_inline('times', type: :duotone), + comment_path(comment), + method: :delete, + data: { confirm: 'Really delete comment?' } %> + </span> + <% end %> </small> </h5> - <%= comment.text %> - <% if comment.user == current_user %> - <span class="manage-comment-controls"> - <%= link_to fa_icon_inline('edit', type: :duotone), - edit_comment_path(comment) %> - <%= link_to fa_icon_inline('times', type: :duotone), - comment_path(comment), - method: :delete, - data: { confirm: 'Really delete comment?' } %> - </span> - <% end %> + <%= markdown.render(comment.text).html_safe %> </div> </div> <% end.empty? %>