Skip to content

Commit

Permalink
FEATURE: Add onebox for loom (discourse#26016)
Browse files Browse the repository at this point in the history
Loom share links will now onebox and use the embedded loom player.
  • Loading branch information
oblakeerickson authored Mar 4, 2024
1 parent b788c08 commit 40b707a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/assets/stylesheets/common/base/onebox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -980,14 +980,16 @@ aside.onebox.mixcloud-preview {
}
}

iframe.vimeo-onebox {
iframe.vimeo-onebox,
iframe.loom-onebox {
width: 100%;
height: auto;
aspect-ratio: 16/9;
}

@supports not (aspect-ratio: auto) {
iframe.vimeo-onebox {
iframe.vimeo-onebox,
iframe.loom-onebox {
width: 690px;
height: 388px;
}
Expand Down
1 change: 1 addition & 0 deletions lib/onebox/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,4 @@ def always_https?
require_relative "engine/hackernews_onebox"
require_relative "engine/motoko_onebox"
require_relative "engine/tiktok_onebox"
require_relative "engine/loom_onebox"
34 changes: 34 additions & 0 deletions lib/onebox/engine/loom_onebox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Onebox
module Engine
class LoomOnebox
include Engine
include StandardEmbed

matches_regexp(%r{^https?://(www\.)?loom\.com/share/\w+(/\w+)?/?})
requires_iframe_origins "https://www.loom.com"
always_https

def placeholder_html
::Onebox::Helpers.video_placeholder_html
end

def to_html
video_id = url.split("/").last
video_src = "https://www.loom.com/embed/#{video_id}"

<<~HTML
<iframe
class="loom-onebox"
src="#{video_src}"
frameborder="0"
webkitallowfullscreen
mozallowfullscreen
allowfullscreen
</iframe>
HTML
end
end
end
end
16 changes: 16 additions & 0 deletions spec/lib/onebox/engine/loom_onebox_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

RSpec.describe Onebox::Engine::LoomOnebox do
it "returns the right HTML markup for the onebox" do
expect(
Onebox
.preview(
"https://www.loom.com/share/c9695e5dc084496c80b7d7516d2a569a?sid=e1279914-ecaa-4faf-afa8-89cbab488240",
)
.to_s
.chomp,
).to eq(
'<iframe class="loom-onebox" src="https://www.loom.com/embed/c9695e5dc084496c80b7d7516d2a569a?sid=e1279914-ecaa-4faf-afa8-89cbab488240" frameborder="0" allowfullscreen="" seamless="seamless" sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation"></iframe>',
)
end
end

0 comments on commit 40b707a

Please sign in to comment.