From 862c8a19a31756a32a961970e79859e00c6f2d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 3 Nov 2014 22:03:06 +0100 Subject: [PATCH] FEATURE: use img's title attribute in overlay information when provided --- app/models/optimized_image.rb | 6 ++--- lib/cooked_post_processor.rb | 4 +-- spec/components/cooked_post_processor_spec.rb | 27 +++++++++++++++++++ spec/fabricators/post_fabricator.rb | 4 +++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index 137679455f0..5df84700ead 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -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} diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index b58bc337970..57af1276d5c 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -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 diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index fd8ba3a7334..ae90bf35697 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -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 '' + cpp.should be_dirty + end + + end + context "topic image" do let(:topic) { build(:topic, id: 1) } diff --git a/spec/fabricators/post_fabricator.rb b/spec/fabricators/post_fabricator.rb index 2ff3bb79218..cab02e02ed0 100644 --- a/spec/fabricators/post_fabricator.rb +++ b/spec/fabricators/post_fabricator.rb @@ -76,6 +76,10 @@ Fabricator(:post_with_large_image, from: :post) do cooked '' end +Fabricator(:post_with_large_image_and_title, from: :post) do + cooked '' +end + Fabricator(:post_with_uploads, from: :post) do cooked ' Link