From e6439e89cfb029b5a3baf2668514d9731310d18f Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Fri, 16 Dec 2022 07:59:40 -0700 Subject: [PATCH] FEATURE: Onebox for Embed Motoko (#19293) --- lib/onebox/engine.rb | 1 + lib/onebox/engine/motoko_onebox.rb | 28 ++++++++++++++++++++ spec/lib/onebox/engine/motoko_onebox_spec.rb | 16 +++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/onebox/engine/motoko_onebox.rb create mode 100644 spec/lib/onebox/engine/motoko_onebox_spec.rb diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb index 9d7c6c2cfa5..e28807c9889 100644 --- a/lib/onebox/engine.rb +++ b/lib/onebox/engine.rb @@ -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" diff --git a/lib/onebox/engine/motoko_onebox.rb b/lib/onebox/engine/motoko_onebox.rb new file mode 100644 index 00000000000..ec6433d2e47 --- /dev/null +++ b/lib/onebox/engine/motoko_onebox.rb @@ -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 diff --git a/spec/lib/onebox/engine/motoko_onebox_spec.rb b/spec/lib/onebox/engine/motoko_onebox_spec.rb new file mode 100644 index 00000000000..d8a81ee98bb --- /dev/null +++ b/spec/lib/onebox/engine/motoko_onebox_spec.rb @@ -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":"