Files
danbooru/app/helpers/posts_helper.rb
2013-04-09 15:31:49 -04:00

35 lines
956 B
Ruby

module PostsHelper
def resize_image_links(post, user)
links = []
if post.has_large?
links << link_to("L", post.large_file_url, :id => "large-file-link")
end
if post.has_large?
links << link_to("O", post.file_url, :id => "original-file-link")
end
if links.any?
content_tag("span", raw("Resize: " + links.join(" ")))
else
nil
end
end
def post_source_tag(post)
if post.source =~ %r!http://img\d+\.pixiv\.net/img/([^\/]+)/!
text = "pixiv/#{$1}"
link_to(text, post.normalized_source)
elsif post.source =~ %r!http://i\d\.pixiv\.net/img\d+/img/([^\/]+)/!
text = "pixiv/#{$1}"
link_to(text, post.normalized_source)
elsif post.source =~ /^http/
text = truncate(post.normalized_source.sub(/^https?:\/\/(?:www)?/, ""))
link_to(truncate(text, :length => 20), post.normalized_source)
else
truncate(post.source, :length => 100)
end
end
end