FEATURE: use img's title attribute in overlay information when provided
This commit is contained in:
parent
f361adef44
commit
862c8a19a3
|
@ -36,7 +36,7 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
FileUtils.cp(original_path, temp_path)
|
FileUtils.cp(original_path, temp_path)
|
||||||
resized = true
|
resized = true
|
||||||
else
|
else
|
||||||
resized = resize(original_path, temp_path, width, height)
|
resized = resize(original_path, temp_path, width, height, opts[:allow_animation])
|
||||||
end
|
end
|
||||||
|
|
||||||
if resized
|
if resized
|
||||||
|
@ -78,8 +78,8 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.resize(from, to, width, height)
|
def self.resize(from, to, width, height, allow_animation=false)
|
||||||
from << "[0]" unless opts[:allow_animation]
|
from << "[0]" unless allow_animation
|
||||||
# NOTE: ORDER is important!
|
# NOTE: ORDER is important!
|
||||||
instructions = %W{
|
instructions = %W{
|
||||||
#{from}
|
#{from}
|
||||||
|
|
|
@ -181,9 +181,9 @@ class CookedPostProcessor
|
||||||
informations = "#{original_width}x#{original_height}"
|
informations = "#{original_width}x#{original_height}"
|
||||||
informations << " #{number_to_human_size(upload.filesize)}" if upload
|
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("informations", informations)
|
||||||
meta.add_child create_span_node("expand")
|
meta.add_child create_span_node("expand")
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,6 +98,33 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
end
|
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
|
context "topic image" do
|
||||||
|
|
||||||
let(:topic) { build(:topic, id: 1) }
|
let(:topic) { build(:topic, id: 1) }
|
||||||
|
|
|
@ -76,6 +76,10 @@ Fabricator(:post_with_large_image, from: :post) do
|
||||||
cooked '<img src="/uploads/default/1/1234567890123456.jpg">'
|
cooked '<img src="/uploads/default/1/1234567890123456.jpg">'
|
||||||
end
|
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
|
Fabricator(:post_with_uploads, from: :post) do
|
||||||
cooked '
|
cooked '
|
||||||
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||||
|
|
Loading…
Reference in New Issue