From ebcc465216f0aaca3f9e4dbd3742846b77aa290c Mon Sep 17 00:00:00 2001 From: Toks Date: Thu, 11 Jul 2013 16:52:42 -0400 Subject: [PATCH] Refactor post preview attributes into one method --- app/presenters/post_presenter.rb | 19 ++++++++++++++++++- app/views/comments/index_by_comment.html.erb | 2 +- app/views/comments/index_by_post.html.erb | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 49e1ca2db..46e739173 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -14,7 +14,7 @@ class PostPresenter < Presenter path = options[:path_prefix] || "/posts" - html = %{
} + html = %{
} if options[:tags].present? tag_param = "?tags=#{CGI::escape(options[:tags])}" elsif options[:pool_id] @@ -39,6 +39,23 @@ class PostPresenter < Presenter klass end + def self.preview_attributes(post) + %{ + id="post_#{post.id}" + data-id="#{post.id}" + data-tags="#{h(post.tag_string)}" + data-uploader="#{h(post.uploader_name)}" + data-rating="#{post.rating}" + data-width="#{post.image_width}" + data-height="#{post.image_height}" + data-flags="#{post.status_flags}" + data-parent-id="#{post.parent_id}" + data-has-children="#{post.has_children?}" + data-score="#{post.score}" + data-fav-count="#{post.fav_count}" + }.html_safe + end + def initialize(post) @post = post end diff --git a/app/views/comments/index_by_comment.html.erb b/app/views/comments/index_by_comment.html.erb index 067b7e7d0..ddd2d7af0 100644 --- a/app/views/comments/index_by_comment.html.erb +++ b/app/views/comments/index_by_comment.html.erb @@ -5,7 +5,7 @@
<% @comments.each do |comment| %> -
+
>
<%= link_to(image_tag(comment.post.preview_file_url), post_path(comment.post)) %>
diff --git a/app/views/comments/index_by_post.html.erb b/app/views/comments/index_by_post.html.erb index acd9467f0..0fadcbf52 100644 --- a/app/views/comments/index_by_post.html.erb +++ b/app/views/comments/index_by_post.html.erb @@ -7,7 +7,7 @@ <% end %> <% @posts.select {|x| Danbooru.config.can_user_see_post?(CurrentUser.user, x)}.each do |post| %> -
+
>
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>