FEATURE: use img's title attribute in overlay information when provided

This commit is contained in:
Régis Hanol 2014-11-03 22:03:06 +01:00
parent f361adef44
commit 862c8a19a3
4 changed files with 36 additions and 5 deletions

View file

@ -36,7 +36,7 @@ class OptimizedImage < ActiveRecord::Base
FileUtils.cp(original_path, temp_path)
resized = true
else
resized = resize(original_path, temp_path, width, height)
resized = resize(original_path, temp_path, width, height, opts[:allow_animation])
end
if resized
@ -78,8 +78,8 @@ class OptimizedImage < ActiveRecord::Base
end
end
def self.resize(from, to, width, height)
from << "[0]" unless opts[:allow_animation]
def self.resize(from, to, width, height, allow_animation=false)
from << "[0]" unless allow_animation
# NOTE: ORDER is important!
instructions = %W{
#{from}

View file

@ -181,9 +181,9 @@ class CookedPostProcessor
informations = "#{original_width}x#{original_height}"
informations << " #{number_to_human_size(upload.filesize)}" if upload
a["title"] = filename
a["title"] = img["title"] || filename
meta.add_child create_span_node("filename", filename)
meta.add_child create_span_node("filename", img["title"] || filename)
meta.add_child create_span_node("informations", informations)
meta.add_child create_span_node("expand")
end

View file

@ -98,6 +98,33 @@ describe CookedPostProcessor do
end
context "with title" do
let(:upload) { Fabricate(:upload) }
let(:post) { build(:post_with_large_image_and_title) }
let(:cpp) { CookedPostProcessor.new(post) }
before do
SiteSetting.max_image_height = 2000
SiteSetting.create_thumbnails = true
Upload.expects(:get_from_url).returns(upload)
FastImage.stubs(:size).returns([1000, 2000])
# hmmm this should be done in a cleaner way
OptimizedImage.expects(:resize).returns(true)
end
it "generates overlay information" do
cpp.post_process_images
cpp.html.should match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="WAT"><img src="/uploads/default/_optimized/da3/9a3/ee5e6b4b0d_690x1380.png" title="WAT" width="690" height="1380"><div class="meta">
<span class="filename">WAT</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
</div></a></div>'
cpp.should be_dirty
end
end
context "topic image" do
let(:topic) { build(:topic, id: 1) }

View file

@ -76,6 +76,10 @@ Fabricator(:post_with_large_image, from: :post) do
cooked '<img src="/uploads/default/1/1234567890123456.jpg">'
end
Fabricator(:post_with_large_image_and_title, from: :post) do
cooked '<img src="/uploads/default/1/1234567890123456.jpg" title="WAT">'
end
Fabricator(:post_with_uploads, from: :post) do
cooked '
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>