Extract component to render an embedded video

This commit is contained in:
Javi Martín
2024-05-19 04:29:02 +02:00
parent 236b58ab01
commit 579e332cf8
4 changed files with 23 additions and 20 deletions

View File

@@ -0,0 +1,5 @@
<div class="small-12 medium-7 small-centered">
<div class="flex-video">
<div id="js-embedded-video" data-video-code="<%= embedded_video_code %>"></div>
</div>
</div>

View File

@@ -1,7 +1,17 @@
module EmbedVideosHelper
def embedded_video_code(resource)
link = resource.video_url
title = t("proposals.show.embed_video_title", proposal: resource.title)
class Shared::EmbeddedVideoComponent < ApplicationComponent
attr_reader :record
def initialize(record)
@record = record
end
def render?
record.video_url.present?
end
def embedded_video_code
link = record.video_url
title = t("proposals.show.embed_video_title", proposal: record.title)
if link =~ /vimeo.*/
server = "Vimeo"
elsif link =~ /youtu*.*/
@@ -9,10 +19,10 @@ module EmbedVideosHelper
end
if server == "Vimeo"
reg_exp = resource.class::VIMEO_REGEX
reg_exp = record.class::VIMEO_REGEX
src = "https://player.vimeo.com/video/"
elsif server == "YouTube"
reg_exp = resource.class::YOUTUBE_REGEX
reg_exp = record.class::YOUTUBE_REGEX
src = "https://www.youtube.com/embed/"
end

View File

@@ -65,13 +65,7 @@
<blockquote><%= @proposal.summary %></blockquote>
<% if @proposal.video_url.present? %>
<div class="small-12 medium-7 small-centered">
<div class="flex-video">
<div id="js-embedded-video" data-video-code="<%= embedded_video_code(@proposal) %>"></div>
</div>
</div>
<% end %>
<%= render Shared::EmbeddedVideoComponent.new(@proposal) %>
<%= auto_link_already_sanitized_html wysiwyg(@proposal.description) %>

View File

@@ -30,13 +30,7 @@
<blockquote><%= @proposal.summary %></blockquote>
<% if @proposal.video_url.present? %>
<div class="small-12 medium-7 small-centered">
<div class="flex-video">
<div id="js-embedded-video" data-video-code="<%= embedded_video_code(@proposal) %>"></div>
</div>
</div>
<% end %>
<%= render Shared::EmbeddedVideoComponent.new(@proposal) %>
<%= auto_link_already_sanitized_html wysiwyg(@proposal.description) %>