From a3db5ba346afe57f8c6b98368f94b0d99b6a980c Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 16 May 2017 15:29:41 -0500 Subject: [PATCH] post replacement: move presenter methods to post_replacement.rb. --- app/models/post_replacement.rb | 54 ++++++++++++++++++++++++++++++-- app/presenters/post_presenter.rb | 49 ----------------------------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 1cfa6f93a..7caa200b8 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -50,8 +50,8 @@ class PostReplacement < ActiveRecord::Base post.source = upload.source post.tag_string = upload.tag_string - post.comments.create!({creator: User.system, body: post.presenter.comment_replacement_message(creator), do_not_bump_post: true}, without_protection: true) - ModAction.log(post.presenter.modaction_replacement_message) + post.comments.create!({creator: User.system, body: comment_replacement_message, do_not_bump_post: true}, without_protection: true) + ModAction.log(modaction_replacement_message) post.save! end @@ -88,5 +88,55 @@ class PostReplacement < ActiveRecord::Base end end + module PresenterMethods + def comment_replacement_message + "@#{creator.name} replaced this post with a new image:\n\n#{replacement_message}" + end + + def modaction_replacement_message + "replaced post ##{post.id}:\n\n#{replacement_message}" + end + + def replacement_message + linked_source = linked_source(post.source) + linked_source_was = linked_source(post.source_was) + + <<-EOS.strip_heredoc + [table] + [tbody] + [tr] + [th]Old[/th] + [td]#{linked_source_was}[/td] + [td]#{post.md5_was}[/td] + [td]#{post.file_ext_was}[/td] + [td]#{post.image_width_was} x #{post.image_height_was}[/td] + [td]#{post.file_size_was.to_s(:human_size, precision: 4)}[/td] + [/tr] + [tr] + [th]New[/th] + [td]#{linked_source}[/td] + [td]#{post.md5}[/td] + [td]#{post.file_ext}[/td] + [td]#{post.image_width} x #{post.image_height}[/td] + [td]#{post.file_size.to_s(:human_size, precision: 4)}[/td] + [/tr] + [/tbody] + [/table] + EOS + end + + def linked_source(source) + # truncate long sources in the middle: "www.pixiv.net...lust_id=23264933" + truncated_source = source.gsub(%r{\Ahttps?://}, "").truncate(64, omission: "...#{source.last(32)}") + + if source =~ %r{\Ahttps?://}i + %("#{truncated_source}":[#{source}]) + else + truncated_source + end + end + end + + include PresenterMethods extend SearchMethods end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 69d74bb33..eaee5e70e 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -279,53 +279,4 @@ class PostPresenter < Presenter pool_html << "" pool_html end - - def comment_replacement_message(replacer = CurrentUser.user) - "@#{replacer.name} replaced this post with a new image:\n\n#{replacement_message}" - end - - def modaction_replacement_message - "replaced post ##{@post.id}:\n\n#{replacement_message}" - end - - def replacement_message - linked_source = linked_source(@post.source) - linked_source_was = linked_source(@post.source_was) - - <<-EOS.strip_heredoc - [table] - [tbody] - [tr] - [th]Old[/th] - [td]#{linked_source_was}[/td] - [td]#{@post.md5_was}[/td] - [td]#{@post.file_ext_was}[/td] - [td]#{@post.image_width_was} x #{@post.image_height_was}[/td] - [td]#{@post.file_size_was.to_s(:human_size, precision: 4)}[/td] - [/tr] - [tr] - [th]New[/th] - [td]#{linked_source}[/td] - [td]#{@post.md5}[/td] - [td]#{@post.file_ext}[/td] - [td]#{@post.image_width} x #{@post.image_height}[/td] - [td]#{@post.file_size.to_s(:human_size, precision: 4)}[/td] - [/tr] - [/tbody] - [/table] - EOS - end - -protected - - def linked_source(source) - # truncate long sources in the middle: "www.pixiv.net...lust_id=23264933" - truncated_source = source.gsub(%r{\Ahttps?://}, "").truncate(64, omission: "...#{source.last(32)}") - - if source =~ %r{\Ahttps?://}i - %("#{truncated_source}":[#{source}]) - else - truncated_source - end - end end