Skip to content

Commit

Permalink
Separate EmbedThis component for media from the other viewers
Browse files Browse the repository at this point in the history
Roll back changes in 1ce562b
  • Loading branch information
jcoyne committed Nov 9, 2023
1 parent 87cac54 commit 465358b
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 41 deletions.
42 changes: 42 additions & 0 deletions app/components/embed/media/embed_this_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class='sul-embed-embed-this-form'>
<section>
<h3 class='sul-embed-options-label modal-subheader'>
Share link
</h3>
<div class='sul-embed-section'>
<input type="text" name="sul-embed-purl-link" id='sul-embed-purl-link' value="<%= purl_url %>">
</div>
</section>

<section>
<h3 class='sul-embed-options-label modal-subheader'>
<label for='sul-embed-iframe-code'>Embed</label>
</h3>
<div class='sul-embed-section'>
<textarea id='sul-embed-iframe-code' data-behavior='iframe-code'><%= render IframeComponent.new(viewer:) %></textarea>
</div>
<h4 class='sul-embed-options-label' id="select-options">Select options:</h4>
<div class='sul-embed-section sul-embed-embed-title-section'>
<input
type='checkbox'
id='sul-embed-embed-title'
data-embed-attr='hide_title'
<%= 'checked' unless request.hide_title? %>
/>
<label for='sul-embed-embed-title'>
title
<span class='sul-embed-embed-title'> (<%= purl_object_title %>)</span>
</label>
</div>
<%= content %>
<div class='sul-embed-section'>
<input
type='checkbox'
id='sul-embed-embed'
data-embed-attr='hide_embed'
<%= 'checked' unless request.hide_embed_this? %>
/>
<label for='sul-embed-embed'>embed</label>
</div>
</section>
</div>
17 changes: 17 additions & 0 deletions app/components/embed/media/embed_this_form_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Embed
module Media
class EmbedThisFormComponent < ViewComponent::Base
def initialize(viewer:)
@viewer = viewer
end

delegate :request, :purl_object, to: :viewer
delegate :title, to: :purl_object, prefix: true
delegate :purl_url, to: :purl_object

attr_reader :viewer
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
Share
</header>

<%= render EmbedThisFormComponent.new(viewer:) %>
<%= render Embed::Media::EmbedThisFormComponent.new(viewer:) %>

<form method="dialog">
<button data-action="click->media#closeShareModal">Close</button>
Expand Down
65 changes: 28 additions & 37 deletions app/components/embed_this_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
<div class='sul-embed-embed-this-form'>
<section>
<h3 class='sul-embed-options-label modal-subheader'>
Share link
</h3>
<div class='sul-embed-section'>
<input type="text" name="sul-embed-purl-link" id='sul-embed-purl-link' value="<%= purl_url %>">
</div>
</section>

<section>
<h3 class='sul-embed-options-label modal-subheader'>
<label for='sul-embed-iframe-code'>Embed</label>
</h3>
<div class='sul-embed-section'>
<textarea id='sul-embed-iframe-code' data-behavior='iframe-code'><%= render IframeComponent.new(viewer:) %></textarea>
</div>
<h4 class='sul-embed-options-label' id="select-options">Select options:</h4>
<div class='sul-embed-section sul-embed-embed-title-section'>
<input
type='checkbox'
id='sul-embed-embed-title'
data-embed-attr='hide_title'
<span class='sul-embed-options-label' id="select-options">Select options:</span>
<div class='sul-embed-section sul-embed-embed-title-section'>
<input
type='checkbox'
id='sul-embed-embed-title'
data-embed-attr='hide_title'
<%= 'checked' unless request.hide_title? %>
/>
<label for='sul-embed-embed-title'>
title
<span class='sul-embed-embed-title'> (<%= purl_object_title %>)</span>
</label>
/>
<label for='sul-embed-embed-title'>
title
<span class='sul-embed-embed-title'> (<%= purl_object_title %>)</span>
</label>
</div>
<%= content %>
<div class='sul-embed-section'>
<input
type='checkbox'
id='sul-embed-embed'
data-embed-attr='hide_embed'
<%= 'checked' unless request.hide_embed_this? %>
/>
<label for='sul-embed-embed'>embed</label>
</div>
<div>
<div class='sul-embed-options-label'>
<label for='sul-embed-iframe-code'>Embed code:</label>
</div>
<%= content %>
<div class='sul-embed-section'>
<input
type='checkbox'
id='sul-embed-embed'
data-embed-attr='hide_embed'
<%= 'checked' unless request.hide_embed_this? %>
/>
<label for='sul-embed-embed'>embed</label>
<textarea id='sul-embed-iframe-code' data-behavior='iframe-code'><%= render IframeComponent.new(viewer:) %></textarea>
</div>
</section>
</div>
</div>
</div>
48 changes: 48 additions & 0 deletions spec/components/embed/media/embed_this_form_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Embed::Media::EmbedThisFormComponent, type: :component do
let(:request) do
Embed::Request.new(url: 'http://purl.stanford.edu/abc123')
end
let(:object) do
instance_double(Embed::Purl, title: '', druid: '', all_resource_files: [], embargoed?: false, purl_url: 'https://stanford.edu/')
end
let(:viewer) { Embed::Viewer::File.new(request) }

before do
allow(request).to receive(:purl_object).and_return(object)
end

context 'without any content' do
before do
render_inline(described_class.new(viewer:))
end

it 'has the form elements for updating the embed code' do
expect(page.find('.sul-embed-options-label#select-options')).to have_content('Select options:')
expect(page).to have_css('input#sul-embed-embed-title[type="checkbox"]')
expect(page).to have_css('input#sul-embed-embed[type="checkbox"]')
expect(page).to have_css('textarea#sul-embed-iframe-code')
end
end

context 'with content' do
before do
with_controller_class EmbedController do
render_inline(described_class.new(viewer:)) do
vc_test_controller.helpers.tag :input, type: 'checkbox', id: 'sul-embed-embed-search'
end
end
end

it 'has the form elements for updating the embed code' do
expect(page.find('.sul-embed-options-label#select-options')).to have_content('Select options:')
expect(page).to have_css('input#sul-embed-embed-title[type="checkbox"]')
expect(page).to have_css('input#sul-embed-embed-search[type="checkbox"]')
expect(page).to have_css('input#sul-embed-embed[type="checkbox"]')
expect(page).to have_css('textarea#sul-embed-iframe-code')
end
end
end
4 changes: 1 addition & 3 deletions spec/components/embed_this_form_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
let(:request) do
Embed::Request.new(url: 'http://purl.stanford.edu/abc123')
end
let(:object) do
instance_double(Embed::Purl, title: '', druid: '', all_resource_files: [], embargoed?: false, purl_url: 'https://stanford.edu/')
end
let(:object) { instance_double(Embed::Purl, title: '', druid: '', all_resource_files: [], embargoed?: false) }
let(:viewer) { Embed::Viewer::File.new(request) }

before do
Expand Down

0 comments on commit 465358b

Please sign in to comment.