mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 21:02:48 +08:00
FIX: Support pausing GIFs for giphy/tenor oneboxes (#13194)
This commit is contained in:
parent
4b8bdd3f72
commit
47e09700fe
|
@ -171,7 +171,7 @@ require_relative "engine/imgur_onebox"
|
|||
require_relative "engine/pastebin_onebox"
|
||||
require_relative "engine/slides_onebox"
|
||||
require_relative "engine/xkcd_onebox"
|
||||
require_relative "engine/giphy_onebox"
|
||||
require_relative "engine/animated_image_onebox"
|
||||
require_relative "engine/gfycat_onebox"
|
||||
require_relative "engine/typeform_onebox"
|
||||
require_relative "engine/vimeo_onebox"
|
||||
|
|
18
lib/onebox/engine/animated_image_onebox.rb
Normal file
18
lib/onebox/engine/animated_image_onebox.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Onebox
|
||||
module Engine
|
||||
class AnimatedImageOnebox
|
||||
include Engine
|
||||
include StandardEmbed
|
||||
|
||||
matches_regexp(/^https?:\/\/.*(giphy\.com|gph\.is|tenor\.com)\//)
|
||||
always_https
|
||||
|
||||
def to_html
|
||||
og = get_opengraph
|
||||
"<img src='#{og.image}' width='#{og.image_width}' height='#{og.image_height}' class='animated onebox' #{og.title_attr}>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Onebox
|
||||
module Engine
|
||||
class GiphyOnebox
|
||||
include Engine
|
||||
include StandardEmbed
|
||||
|
||||
matches_regexp(/^https?:\/\/(giphy\.com\/gifs|gph\.is)\//)
|
||||
always_https
|
||||
|
||||
def to_html
|
||||
oembed = get_oembed
|
||||
|
||||
<<-HTML
|
||||
<a href="#{oembed.url}" target="_blank" rel="noopener" class="onebox">
|
||||
<img src="#{oembed.url}" width="#{oembed.width}" height="#{oembed.height}" #{oembed.title_attr}>
|
||||
</a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
335
spec/fixtures/onebox/giphy.response
vendored
Normal file
335
spec/fixtures/onebox/giphy.response
vendored
Normal file
File diff suppressed because one or more lines are too long
3
spec/fixtures/onebox/tenor.response
vendored
Normal file
3
spec/fixtures/onebox/tenor.response
vendored
Normal file
File diff suppressed because one or more lines are too long
31
spec/lib/onebox/engine/animated_image_onebox_spec.rb
Normal file
31
spec/lib/onebox/engine/animated_image_onebox_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Onebox::Engine::AnimatedImageOnebox do
|
||||
let(:giphy) { "http://gph.is/15bRbWf" }
|
||||
let(:tenor) { "https://tenor.com/bb3fQ.gif" }
|
||||
|
||||
before do
|
||||
@previous_options = Onebox.options.to_h
|
||||
Onebox.options = { redirect_limit: 0 }
|
||||
stub_request(:get, giphy).to_return(status: 200, body: onebox_response("giphy"))
|
||||
stub_request(:get, tenor).to_return(status: 200, body: onebox_response("tenor"))
|
||||
end
|
||||
|
||||
after do
|
||||
Onebox.options = @previous_options
|
||||
end
|
||||
|
||||
it "works for giphy short URLs" do
|
||||
html = described_class.new(giphy).to_html
|
||||
expect(html).to include("img")
|
||||
expect(html).to include("class='animated onebox'")
|
||||
end
|
||||
|
||||
it "works for tenor URLs" do
|
||||
html = described_class.new(tenor).to_html
|
||||
expect(html).to include("img")
|
||||
expect(html).to include("class='animated onebox'")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user