forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add onebox for loom (discourse#26016)
Loom share links will now onebox and use the embedded loom player.
- Loading branch information
1 parent
b788c08
commit 40b707a
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |