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
-
- - Id: <%= @post.id %>
- - Uploaded <%= time_ago_in_words(@post.created_at) %> ago by <%= link_to_unless(@post.uploader.nil?, @post.uploader_name, user_path(@post.uploader)) %>
- <% if @post.approver %>
- - Approver: <%= @post.approver.name %>
- <% end %>
- <% if @post.is_image? %>
- -
- [M]
- [L]
- [O]
-
- <% end %>
- - <%= link_to "Tag History", post_versions_path(:post_id => @post) %>
- - <%= link_to "Note History", note_versions_path(:post_id => @post) %>
-
+ <%= render :partial => "information", :locals => {:post => @post} %>
Options
-
+ <%= render :partial => "options", :locals => {:post => @post} %>
@@ -57,7 +28,7 @@
Image
- <%= @post.presenter.image_html %>
+ <%= @post.presenter.image_html(self, @current_user) %>