Extract component to render an embedded video
This commit is contained in:
5
app/components/shared/embedded_video_component.html.erb
Normal file
5
app/components/shared/embedded_video_component.html.erb
Normal 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>
|
||||
@@ -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
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user