added
This commit is contained in:
@@ -78,6 +78,19 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def file_path_for(user)
|
||||
case user.default_image_size
|
||||
when "medium"
|
||||
medium_file_path
|
||||
|
||||
when "large"
|
||||
large_file_path
|
||||
|
||||
else
|
||||
file_path
|
||||
end
|
||||
end
|
||||
|
||||
def is_image?
|
||||
file_ext =~ /jpg|gif|png/
|
||||
end
|
||||
@@ -91,6 +104,38 @@ class Post < ActiveRecord::Base
|
||||
def has_large?
|
||||
image_width > Danbooru.config.large_image_width
|
||||
end
|
||||
|
||||
def image_width_for(user)
|
||||
case user.default_image_size
|
||||
when "medium"
|
||||
[Danbooru.config.medium_image_width, image_width].min
|
||||
|
||||
when "large"
|
||||
[Danbooru.config.large_image_width, image_width].min
|
||||
|
||||
else
|
||||
image_width
|
||||
end
|
||||
end
|
||||
|
||||
def image_height_for(user)
|
||||
case user.default_image_size
|
||||
when "medium"
|
||||
ratio = Danbooru.config.medium_image_width.to_f / image_width.to_f
|
||||
|
||||
when "large"
|
||||
ratio = Danbooru.config.large_image_width.to_f / image_width.to_f
|
||||
|
||||
else
|
||||
ratio = 1
|
||||
end
|
||||
|
||||
if ratio < 1
|
||||
image_height * ratio
|
||||
else
|
||||
image_height
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ModerationMethods
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
class PostPresenter < Presenter
|
||||
def initialize(post)
|
||||
def initialize(post, current_user)
|
||||
@post = post
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def tag_list_html
|
||||
end
|
||||
|
||||
def image_html
|
||||
def image_html(template)
|
||||
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),
|
||||
"data-original-width" => @post.image_width,
|
||||
"data-original-height" => @post.image_height
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def note_html
|
||||
|
||||
Reference in New Issue
Block a user