Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sul-dlss/purl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bbe5c0eb7f6740d85627788f1a8d76af04e96b29
Choose a base ref
..
head repository: sul-dlss/purl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bd7fce1c6b4e19b4480e53c897ef3d315f43dddd
Choose a head ref
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ AllCops:
- 'node_modules/**/*'
- 'spec/spec_helper.rb'
- 'vendor/**/*'
TargetRubyVersion: 3.0
TargetRubyVersion: 3.2

Rails:
Enabled: true
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -54,8 +54,7 @@ gem 'tophat'
# Use recaptcha gem to prevent robots spamming the feedback form
gem 'recaptcha'

# sul-dlss/osullivan#development has early support for generating IIIF v3 manifests
gem 'iiif-presentation', github: 'iiif-prezi/osullivan', branch: 'development2'
gem 'iiif-presentation', '~> 1.2'

group :production do
gem 'newrelic_rpm'
16 changes: 5 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
GIT
remote: https://github.com/iiif-prezi/osullivan.git
revision: 0548b1685bd75821a6c3064dcff0afd501e87153
branch: development2
specs:
iiif-presentation (1.1.0)
activesupport (>= 3.2.18)
faraday (~> 2.7)
json

GEM
remote: https://rubygems.org/
specs:
@@ -184,6 +174,10 @@ GEM
htmlentities (4.3.4)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
iiif-presentation (1.2.0)
activesupport (>= 3.2.18)
faraday (~> 2.7)
json
importmap-rails (1.2.1)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
@@ -422,7 +416,7 @@ DEPENDENCIES
faraday
honeybadger
htmlentities
iiif-presentation!
iiif-presentation (~> 1.2)
importmap-rails
jbuilder
mods_display (~> 1.1)
Binary file added app/assets/images/stanford_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/images/stanford_s.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/modules/record-metadata-section.scss
Original file line number Diff line number Diff line change
@@ -31,3 +31,11 @@
margin-left: auto;
}
}

// Based on sul-embed
.stanford-only-text {
background: url('stanford_s.png') no-repeat left;
background: url('stanford_s.svg') no-repeat left, none;
padding-left: 15px;
margin-left: 5px;
}
13 changes: 2 additions & 11 deletions app/controllers/preview_controller.rb
Original file line number Diff line number Diff line change
@@ -2,17 +2,8 @@ class PreviewController < ApplicationController
def index; end

def show
@mods = ModsDisplay::Record.new(params[:mods])
@mods = @mods.mods_display_html
@purl = @document = OpenStruct.new(
mods?: true,
mods: @mods,
title: Array.wrap(@mods.title).join(' -- '),
containing_purl_collections: []
)

@purl.define_singleton_method(:released_to?) do |*args|
end
@mods = ModsDisplay::Record.new(params[:mods]).mods_display_html
@purl = @document = PreviewResource.new(@mods)
end

def self.local_prefixes
6 changes: 6 additions & 0 deletions app/controllers/purl_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class PurlController < ApplicationController
before_action :load_purl, except: [:index]
before_action :fix_etag_header

rescue_from PurlResource::DruidNotValid, with: :invalid_druid
rescue_from PurlResource::ObjectNotReady, with: :object_not_ready
@@ -67,4 +68,9 @@ def load_purl
def missing_file
render '/errors/missing_file', status: :not_found
end

def fix_etag_header
# Apache adds -gzip to the etag header, which causes the request appear stale.
request.headers['HTTP_IF_NONE_MATCH'].sub!('-gzip', '') if request.if_none_match
end
end
8 changes: 7 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def iframe_url(druid)

def embeddable_url(druid)
if Settings.embed.url
Settings.embed.url % { druid: druid }
Settings.embed.url % { druid: }
else
purl_url(druid)
end
@@ -42,4 +42,10 @@ def embeddable_url(druid)
def with_copyright_symbol(str)
str.gsub(/\(c\) Copyright/i, '© Copyright')
end

def with_stanford_only(value)
return unless value.downcase.include?('https://stanford.idm.oclc.org/login?url=')

'<span class="stanford-only-text"><span class="visually-hidden">Stanford only </span></span>'.html_safe
end
end
4 changes: 2 additions & 2 deletions app/models/content_metadata.rb
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ def extract_resources(resource)
id: resource.attribute('id').to_s,
type: resource.attribute('type').to_s,
label: resource.xpath('(label|attr[@name="label"])').first.try(:text),
druid: druid
druid:
}

resource_attributes[:sequence] = if resource.attribute('sequence')
@@ -79,7 +79,7 @@ def initialize(index:, files:, id:)
end

def self.from_grouping(index, files)
new(index: index, files: files, id: files[0].id)
new(index:, files:, id: files[0].id)
end

def primary
8 changes: 4 additions & 4 deletions app/models/iiif_presentation_manifest.rb
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ def downloadable_file?(file)
end

def ocr_text?
ocr_files.any?
ocr_files.present?
end

def description_or_note
@@ -223,7 +223,7 @@ def canvas_for_resource(purl_base_uri, resource)
end

other_content = other_content_for_resource(purl_base_uri, resource)
canv.otherContent = other_content if other_content.any?
canv.otherContent = other_content if other_content.present?

anno = annotation_for_resource(purl_base_uri, resource)
anno['on'] = canv['@id']
@@ -238,7 +238,7 @@ def other_content_for_resource(purl_base_uri, resource)

other_content = []

if grouped_resource.files.select { |file| file.role == 'annotations' && file.mimetype == 'application/json' }&.any?
if grouped_resource.files.any? { |file| file.role == 'annotations' && file.mimetype == 'application/json' }
anno_list = IIIF::Presentation::AnnotationList.new
anno_list['@id'] = "#{purl_base_uri}/iiif/annotationList/#{resource.id}"
other_content << anno_list
@@ -292,7 +292,7 @@ def content_search_service

{
'@context' => 'http://iiif.io/api/search/1/context.json',
'@id' => format(Settings.content_search.url, druid: druid),
'@id' => format(Settings.content_search.url, druid:),
'profile' => 'http://iiif.io/api/search/1/search',
'label' => 'Search within this manifest'
}
36 changes: 36 additions & 0 deletions app/models/preview_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# A lighter-weight version of PurlResource
class PreviewResource
def initialize(mods)
@mods = mods
end

attr_reader :mods

def mods?
true
end

def title
Array.wrap(@mods.title).join(' -- ')
end

def containing_purl_collections
[]
end

def released_to?(_key); end
def copyright?; end
def use_and_reproduction?; end
def license?; end
def catalog_key; end
def type; end

def respond_to_missing?(_name)
true
end

def method_missing(method_name, *_args)
Honeybadger.notify('Undefined method called on PreviewResource', context: { method_name: })
nil
end
end
6 changes: 3 additions & 3 deletions app/models/purl_resource.rb
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def self.all
def self.find(id)
raise DruidNotValid, id unless Dor::Util.validate_druid(id)

PurlResource.new(id: id).tap do |obj|
PurlResource.new(id:).tap do |obj|
raise ObjectNotReady, id unless obj.ready?
end
end
@@ -98,7 +98,7 @@ def content_metadata
# @returns [Bool] are there resources that can be shown?
# This prevents adding links to the embed service, when that service can't generate a valid response.
def embeddable?
content_metadata.resources.any?
content_metadata.resources.present?
end

def rights
@@ -239,7 +239,7 @@ def last_modified_header_value

concerning :ActiveModelness do
def attributes
{ druid: id, druid_tree: druid_tree }
{ druid: id, druid_tree: }
end

def persisted?
2 changes: 1 addition & 1 deletion app/views/purl/_mods_bibliographic.html.erb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<div class="section-body">
<dl>
<% fields.each do |field| %>
<%= mods_record_field(field) %>
<%= mods_record_field(field) {|value| format_mods_html(value, field: field) + with_stanford_only(value) } %>
<% end %>
</dl>
</div>
115 changes: 113 additions & 2 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,114 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../Gemfile", __dir__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_requirement
@bundler_requirement ||=
env_var_version || cli_arg_version ||
bundler_requirement_for(lockfile_version)
end

def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version

bundler_gem_version = Gem::Version.new(version)

requirement = bundler_gem_version.approximate_recommendation

return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")

requirement += ".a" if bundler_gem_version.prerelease?

requirement
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
11 changes: 10 additions & 1 deletion spec/features/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -170,7 +170,16 @@
end
end

context 'item with Stanford-only location in MODS' do
it 'adds a Stanford-only indicator' do
visit '/yk677wc8843'

expect(page).to have_selector '.stanford-only-text', text: 'Stanford only'
expect(page.find('.stanford-only-text')).to have_sibling('a', text: 'Cambridge Core')
end
end

def have_metadata_section(text)
have_selector '.section-heading', text: text
have_selector '.section-heading', text:
end
end
Loading