mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FEATURE: Onebox for Embed Motoko (#19293)
This commit is contained in:
parent
2d628c80a1
commit
e6439e89cf
|
@ -211,3 +211,4 @@ require_relative "engine/reddit_media_onebox"
|
|||
require_relative "engine/google_drive_onebox"
|
||||
require_relative "engine/facebook_media_onebox"
|
||||
require_relative "engine/hackernews_onebox"
|
||||
require_relative "engine/motoko_onebox"
|
||||
|
|
28
lib/onebox/engine/motoko_onebox.rb
Normal file
28
lib/onebox/engine/motoko_onebox.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Onebox
|
||||
module Engine
|
||||
class MotokoOnebox
|
||||
include Engine
|
||||
include StandardEmbed
|
||||
|
||||
matches_regexp(/^https?:\/\/embed\.smartcontracts\.org\/?.*/)
|
||||
requires_iframe_origins "https://embed.smartcontracts.org"
|
||||
always_https
|
||||
|
||||
def to_html
|
||||
get_oembed.html
|
||||
end
|
||||
|
||||
def placeholder_html
|
||||
::Onebox::Helpers.generic_placeholder_html
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_oembed_url
|
||||
"https://embed.smartcontracts.org/api/onebox?url=#{url}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
spec/lib/onebox/engine/motoko_onebox_spec.rb
Normal file
16
spec/lib/onebox/engine/motoko_onebox_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Onebox::Engine::MotokoOnebox do
|
||||
before do
|
||||
body = '{"version":"1.0","provider_name":"Embed Motoko","provider_url":"https://embed.smartcontracts.org","type":"rich","width":800,"height":500,"html":"<iframe src=\"https://embed.smartcontracts.org\" width=\"800\" height=\"500\" style=\"border:0\" />"}'
|
||||
|
||||
stub_request(:get, "https://embed.smartcontracts.org/api/onebox?url=https://embed.smartcontracts.org")
|
||||
.to_return(status: 200, body: body, headers: {})
|
||||
end
|
||||
|
||||
it "returns the expected iframe markup" do
|
||||
expect(Onebox.preview('https://embed.smartcontracts.org').to_s.chomp).to include(
|
||||
'<iframe src="https://embed.smartcontracts.org" width="800" height="500" style="border:0"'
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user