diff --git a/app/models/post.rb b/app/models/post.rb index 8cab9b780..21588e8ce 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -68,10 +68,18 @@ class Post < ActiveRecord::Base def file_url_for(user) case user.default_image_size when "medium" - medium_file_url + if image_width > Danbooru.config.medium_image_width + medium_file_url + else + file_url + end when "large" - large_file_url + if image_width > Danbooru.config.large_image_width + large_file_url + else + file_url + end else file_url @@ -81,10 +89,18 @@ class Post < ActiveRecord::Base def file_path_for(user) case user.default_image_size when "medium" - medium_file_path + if image_width > Danbooru.config.medium_image_width + medium_file_path + else + file_path + end when "large" - large_file_path + if image_width > Danbooru.config.large_image_width + large_file_path + else + file_path + end else file_path @@ -94,6 +110,10 @@ class Post < ActiveRecord::Base def is_image? file_ext =~ /jpg|gif|png/ end + + def is_flash? + file_ext =~ /swf/ + end end module ImageMethods @@ -105,13 +125,39 @@ class Post < ActiveRecord::Base image_width > Danbooru.config.large_image_width end + def medium_image_width + [Danbooru.config.medium_image_width, image_width].min + end + + def large_image_width + [Danbooru.config.large_image_width, image_width].min + end + + def medium_image_height + ratio = Danbooru.config.medium_image_width.to_f / image_width.to_f + if ratio < 1 + image_height * ratio + else + image_height + end + end + + def large_image_height + ratio = Danbooru.config.large_image_width.to_f / image_width.to_f + if ratio < 1 + image_height * ratio + else + image_height + end + end + def image_width_for(user) case user.default_image_size when "medium" - [Danbooru.config.medium_image_width, image_width].min + medium_image_width when "large" - [Danbooru.config.large_image_width, image_width].min + large_image_width else image_width @@ -121,17 +167,11 @@ class Post < ActiveRecord::Base def image_height_for(user) case user.default_image_size when "medium" - ratio = Danbooru.config.medium_image_width.to_f / image_width.to_f + medium_image_height when "large" - ratio = Danbooru.config.large_image_width.to_f / image_width.to_f + large_image_height - else - ratio = 1 - end - - if ratio < 1 - image_height * ratio else image_height end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 24fd10756..4c6dc7d1d 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -1,22 +1,22 @@ class PostPresenter < Presenter - def initialize(post, current_user) + def initialize(post) @post = post - @current_user = current_user end def tag_list_html end - def image_html(template) - return "" if @post.is_deleted? && !@current_user.is_janitor? + def image_html(template, current_user) + return "" if @post.is_deleted? && !current_user.is_janitor? if @post.is_flash? template.render(:partial => "posts/flash", :locals => {:post => @post}) elsif @post.is_image? template.image_tag( - @post.file_path_for(@current_user), - :width => @post.image_width_for(@current_user), - :height => @post.image_height_for(@current_user), + @post.file_url_for(current_user), + :alt => @post.tag_string, + :width => @post.image_width_for(current_user), + :height => @post.image_height_for(current_user), "data-original-width" => @post.image_width, "data-original-height" => @post.image_height ) diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 5964f9522..fc30ba9e6 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -14,41 +14,12 @@

Information

- + <%= render :partial => "information", :locals => {:post => @post} %>

Options

- - <% if !@post.is_deleted? && @post.is_image? && @post.image_width && @post.image_width > 700 %> -
  • <%= link_to "Resize", "#" %>
  • - <% end %> -
  • <%= link_to "Favorite", "#" %>
  • -
  • <%= link_to "Unfavorite", "#" %>
  • -
  • <%= link_to "Add translation", "#" %>
  • -
  • <%= link_to "Unapprove", "#" %>
  • - <% if @current_user.is_janitor? %> -
  • <%= link_to "Approve", "#" %>
  • -
  • <%= link_to "Undelete", "#" %>
  • -
  • <%= link_to "Delete", "#" %>
  • - <% end %> -
  • <%= link_to "Add to Pool", "#" %>
  • -
    + <%= render :partial => "options", :locals => {:post => @post} %>
    @@ -57,7 +28,7 @@

    Image

    - <%= @post.presenter.image_html %> + <%= @post.presenter.image_html(self, @current_user) %>