added
This commit is contained in:
@@ -78,6 +78,19 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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?
|
def is_image?
|
||||||
file_ext =~ /jpg|gif|png/
|
file_ext =~ /jpg|gif|png/
|
||||||
end
|
end
|
||||||
@@ -91,6 +104,38 @@ class Post < ActiveRecord::Base
|
|||||||
def has_large?
|
def has_large?
|
||||||
image_width > Danbooru.config.large_image_width
|
image_width > Danbooru.config.large_image_width
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
module ModerationMethods
|
module ModerationMethods
|
||||||
|
|||||||
@@ -1,12 +1,26 @@
|
|||||||
class PostPresenter < Presenter
|
class PostPresenter < Presenter
|
||||||
def initialize(post)
|
def initialize(post, current_user)
|
||||||
@post = post
|
@post = post
|
||||||
|
@current_user = current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list_html
|
def tag_list_html
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def note_html
|
def note_html
|
||||||
|
|||||||
Reference in New Issue
Block a user