diff --git a/Gemfile.lock b/Gemfile.lock index 3f61738f2..408b7ba44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,8 +89,6 @@ GEM base64 (0.2.0) bcrypt (3.1.20) bcrypt_pbkdf (1.1.1) - bcrypt_pbkdf (1.1.1-arm64-darwin) - bcrypt_pbkdf (1.1.1-x86_64-darwin) benchmark (0.4.0) bibtex-ruby (6.1.0) latex-decode (~> 0.0) diff --git a/app/components/record/item/embed_component.rb b/app/components/record/item/embed_component.rb new file mode 100644 index 000000000..f7a60f240 --- /dev/null +++ b/app/components/record/item/embed_component.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Record + module Item + class EmbedComponent < ViewComponent::Base + def initialize(druid:) + @druid = druid + super + end + + attr_reader :druid + + def call + tag.div(data: { behavior: "purl-embed", embed_url: }) + end + + def embed_url + "#{Settings.PURL_EMBED_PROVIDER}.json?hide_title=true&url=#{Settings.PURL_EMBED_RESOURCE}#{druid}" + end + end + end +end diff --git a/app/components/record/item/marc/metadata_component.html.erb b/app/components/record/item/marc/metadata_component.html.erb index e0fbc755c..e3dcddb10 100644 --- a/app/components/record/item/marc/metadata_component.html.erb +++ b/app/components/record/item/marc/metadata_component.html.erb @@ -16,7 +16,7 @@

Digital content

-
+ <%= render Record::Item::EmbedComponent.new(druid: document.druid) %> <%= helpers.iiif_drag_n_drop(document.iiif_manifest) if document.iiif_manifest %>
diff --git a/app/components/record/item/mods/metadata_component.html.erb b/app/components/record/item/mods/metadata_component.html.erb index 924a16e71..fb4d24614 100644 --- a/app/components/record/item/mods/metadata_component.html.erb +++ b/app/components/record/item/mods/metadata_component.html.erb @@ -5,7 +5,7 @@ <% if document.druid && document.published_content? %>

Digital content

-
+ <%= render Record::Item::EmbedComponent.new(druid: document.druid) %> <%= helpers.iiif_drag_n_drop(document.iiif_manifest) if document.iiif_manifest %>
<% end %> diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb deleted file mode 100644 index dfbe06fd9..000000000 --- a/app/controllers/embed_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class EmbedController < ApplicationController - def show - respond_to do |format| - format.json { render json: { html: PURLEmbed.new(params[:id]).html } } - end - end -end diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb index cc621c704..87b1f8775 100644 --- a/config/initializers/zeitwerk.rb +++ b/config/initializers/zeitwerk.rb @@ -5,9 +5,3 @@ inflect.acronym 'IP' inflect.acronym 'MHLD' end - -Rails.autoloaders.each do |autoloader| - autoloader.inflector.inflect( - "purl_embed" => "PURLEmbed" - ) -end diff --git a/config/routes.rb b/config/routes.rb index 7c181ed72..46ac4a4c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,8 +75,6 @@ resource :quick_reports, only: [:create] - resources :embed, only: :show - resources :lib_guides, only: :index resources :browse, only: :index diff --git a/config/settings/test.yml b/config/settings/test.yml index e9dacf349..2608c450d 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -1,8 +1,6 @@ HOSTNAME: "TEST-HOST" HOURS_API: enabled: false -# Test needs to be under http otherwise jquery cannot be loaded -PURL_EMBED_PROVIDER: 'http://embed.stanford.edu/embed' SU_AFFILIATIONS: - test-stanford:test EXHIBITS_ACCESS_PANEL: diff --git a/lib/purl_embed.rb b/lib/purl_embed.rb deleted file mode 100644 index 308ce74a8..000000000 --- a/lib/purl_embed.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'oembed' -class PURLEmbed - delegate :html, to: :resource - - def initialize(druid) - @druid = druid - set_url_scheme - end - - private - - def resource - @resource ||= provider.get("#{Settings.PURL_EMBED_RESOURCE}#{@druid}") - end - - def provider - @provider ||= OEmbed::Provider.new("#{Settings.PURL_EMBED_PROVIDER}.{format}?hide_title=true", :json) - end - - def set_url_scheme - provider << Settings.PURL_EMBED_URL_SCHEME - end -end diff --git a/spec/controllers/embed_controller_spec.rb b/spec/controllers/embed_controller_spec.rb deleted file mode 100644 index 144c80192..000000000 --- a/spec/controllers/embed_controller_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe EmbedController do - let(:embed) { double('embed') } - - describe "routes" do - it "should route to the show action with ID passed in" do - expect(get: "/embed/abc123").to route_to(controller: 'embed', action: 'show', id: 'abc123') - end - end - - describe "GET show" do - before do - expect(PURLEmbed).to receive(:new).with('abc123').and_return(embed) - expect(embed).to receive(:html).and_return("

stuff

") - end - - it "should return correct response" do - get :show, params: { format: "json", id: "abc123" } - expect(response).to have_http_status :ok - end - end -end diff --git a/spec/features/blacklight_customizations/librarian_view_spec.rb b/spec/features/blacklight_customizations/librarian_view_spec.rb index bc4d84e1e..d67849a5c 100644 --- a/spec/features/blacklight_customizations/librarian_view_spec.rb +++ b/spec/features/blacklight_customizations/librarian_view_spec.rb @@ -3,8 +3,6 @@ require 'rails_helper' RSpec.describe "Librarian View Customization", :js do - let(:embed) { double('embed-response') } - it "MARC records should display" do visit solr_document_path('28') @@ -23,8 +21,6 @@ end it "MODS records should display" do - expect(embed).to receive(:html).and_return("") - expect(PURLEmbed).to receive(:new).and_return(embed) visit solr_document_path('35') within(".tech-details") do diff --git a/spec/lib/purl_embed_spec.rb b/spec/lib/purl_embed_spec.rb deleted file mode 100644 index e0a4ba1db..000000000 --- a/spec/lib/purl_embed_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe PURLEmbed do - let(:druid) { 'abc123' } - let(:provider) { double('provider') } - - before do - expect(provider).to receive(:<<).with(Settings.PURL_EMBED_URL_SCHEME) - end - - describe 'provider' do - let(:resource) { double('resource') } - - before do - allow_any_instance_of(PURLEmbed).to receive(:provider).and_return(provider) - end - - describe 'URL Scheme' do - it 'should set the PURL Embed URL scheme in the settings when instantiated' do - PURLEmbed.new(druid) # expectation in before block - end - end - - describe 'resource' do - before do - expect(resource).to receive(:html).and_return('') - expect(provider).to receive(:get).with("#{Settings.PURL_EMBED_RESOURCE}#{druid}").and_return(resource) - end - - it 'should get from the provider given the instantiated druid and return the html from the resource' do - expect(PURLEmbed.new(druid).html).to eq '' - end - end - end - - describe 'OEmbed Provider params' do - it 'passes the hide_title param' do - expect(OEmbed::Provider).to receive(:new).with( - "#{Settings.PURL_EMBED_PROVIDER}.{format}?hide_title=true", :json - ).and_return(provider) - PURLEmbed.new(druid) - end - end -end