changes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -14,41 +14,12 @@
|
||||
|
||||
<section>
|
||||
<h1>Information</h1>
|
||||
<ul>
|
||||
<li>Id: <%= @post.id %></li>
|
||||
<li>Uploaded <%= time_ago_in_words(@post.created_at) %> ago by <%= link_to_unless(@post.uploader.nil?, @post.uploader_name, user_path(@post.uploader)) %></li>
|
||||
<% if @post.approver %>
|
||||
<li>Approver: <%= @post.approver.name %></li>
|
||||
<% end %>
|
||||
<% if @post.is_image? %>
|
||||
<li>
|
||||
[M]
|
||||
[L]
|
||||
[O]
|
||||
</li>
|
||||
<% end %>
|
||||
<li><%= link_to "Tag History", post_versions_path(:post_id => @post) %></li>
|
||||
<li><%= link_to "Note History", note_versions_path(:post_id => @post) %></li>
|
||||
</ul>
|
||||
<%= render :partial => "information", :locals => {:post => @post} %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h1>Options</h1>
|
||||
<menu>
|
||||
<% if !@post.is_deleted? && @post.is_image? && @post.image_width && @post.image_width > 700 %>
|
||||
<li><%= link_to "Resize", "#" %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Favorite", "#" %></li>
|
||||
<li><%= link_to "Unfavorite", "#" %></li>
|
||||
<li><%= link_to "Add translation", "#" %></li>
|
||||
<li><%= link_to "Unapprove", "#" %></li>
|
||||
<% if @current_user.is_janitor? %>
|
||||
<li><%= link_to "Approve", "#" %></li>
|
||||
<li><%= link_to "Undelete", "#" %></li>
|
||||
<li><%= link_to "Delete", "#" %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Add to Pool", "#" %></li>
|
||||
</menu>
|
||||
<%= render :partial => "options", :locals => {:post => @post} %>
|
||||
</section>
|
||||
</aside>
|
||||
|
||||
@@ -57,7 +28,7 @@
|
||||
|
||||
<section>
|
||||
<h2>Image</h2>
|
||||
<%= @post.presenter.image_html %>
|
||||
<%= @post.presenter.image_html(self, @current_user) %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
Reference in New Issue
Block a user