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
|
class Shared::EmbeddedVideoComponent < ApplicationComponent
|
||||||
def embedded_video_code(resource)
|
attr_reader :record
|
||||||
link = resource.video_url
|
|
||||||
title = t("proposals.show.embed_video_title", proposal: resource.title)
|
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.*/
|
if link =~ /vimeo.*/
|
||||||
server = "Vimeo"
|
server = "Vimeo"
|
||||||
elsif link =~ /youtu*.*/
|
elsif link =~ /youtu*.*/
|
||||||
@@ -9,10 +19,10 @@ module EmbedVideosHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
if server == "Vimeo"
|
if server == "Vimeo"
|
||||||
reg_exp = resource.class::VIMEO_REGEX
|
reg_exp = record.class::VIMEO_REGEX
|
||||||
src = "https://player.vimeo.com/video/"
|
src = "https://player.vimeo.com/video/"
|
||||||
elsif server == "YouTube"
|
elsif server == "YouTube"
|
||||||
reg_exp = resource.class::YOUTUBE_REGEX
|
reg_exp = record.class::YOUTUBE_REGEX
|
||||||
src = "https://www.youtube.com/embed/"
|
src = "https://www.youtube.com/embed/"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,13 +65,7 @@
|
|||||||
|
|
||||||
<blockquote><%= @proposal.summary %></blockquote>
|
<blockquote><%= @proposal.summary %></blockquote>
|
||||||
|
|
||||||
<% if @proposal.video_url.present? %>
|
<%= render Shared::EmbeddedVideoComponent.new(@proposal) %>
|
||||||
<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 %>
|
|
||||||
|
|
||||||
<%= auto_link_already_sanitized_html wysiwyg(@proposal.description) %>
|
<%= auto_link_already_sanitized_html wysiwyg(@proposal.description) %>
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,7 @@
|
|||||||
|
|
||||||
<blockquote><%= @proposal.summary %></blockquote>
|
<blockquote><%= @proposal.summary %></blockquote>
|
||||||
|
|
||||||
<% if @proposal.video_url.present? %>
|
<%= render Shared::EmbeddedVideoComponent.new(@proposal) %>
|
||||||
<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 %>
|
|
||||||
|
|
||||||
<%= auto_link_already_sanitized_html wysiwyg(@proposal.description) %>
|
<%= auto_link_already_sanitized_html wysiwyg(@proposal.description) %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user