Skip to content

Commit

Permalink
Appease Rubocop: Layout/EmptyLineAfterGuardClause
Browse files Browse the repository at this point in the history
  • Loading branch information
camillevilla committed Sep 17, 2018
1 parent a4975fb commit 2fa172a
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/controllers/catalog_controller.rb
Expand Up @@ -223,6 +223,7 @@ class CatalogController < ApplicationController
# bail out to true (show the field) if we don't have 3 arguments (context being the added argument)
# This is required for the metadata configuration admin page to return the field properly.
return true if args.length < 3

full_text_highlight_exists_in_response?(*args)
end,
label: 'Sample matches in document text',
Expand Down
1 change: 1 addition & 0 deletions app/controllers/index_statuses_controller.rb
Expand Up @@ -35,6 +35,7 @@ def build_resource
def filtered_solr_document_ids
document_ids = @resource.solr_document_sidecars.pluck(:document_id)
return document_ids unless params[:q]

index_query_param = params[:q].downcase

document_ids.select { |id| id.include?(index_query_param) }
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/catalog_helper.rb
Expand Up @@ -29,13 +29,15 @@ def has_thumbnail?(document)
# @return [String]
def render_thumbnail_tag(document, image_options = {}, url_options = {})
return super unless document.reference? || document.canvas?

image = image_tag(thumbnail_tag_image_path(document), image_options)
link_to_document document, image, url_options
end

def notes_wrap(options = {})
return if options[:value].blank?
return options[:value].first if options[:value].count == 1

content_tag('ul', class: 'general-notes') do
safe_join(options[:value].collect do |note|
content_tag('li', note.html_safe) # rubocop:disable Rails/OutputSafety
Expand All @@ -45,15 +47,18 @@ def notes_wrap(options = {})

def table_of_contents_separator(options = {})
return if options[:value].blank?

contents = options[:value][0].split('--').map(&:strip)
return contents.join if contents.length == 1

contents = safe_join(contents.map { |v| "<li>#{v}</li>".html_safe }) # rubocop:disable Rails/OutputSafety
id = options[:document].id
render partial: 'catalog/table_of_contents', locals: { contents: contents, collapse_id: "collapseToc-#{id}" }
end

def manuscript_link(options = {})
return if options[:value].blank?

druid = options[:value][0]
document = options[:document]
title = document['title_full_display']
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/bibliography_concern.rb
Expand Up @@ -30,6 +30,7 @@ def bibliography_url

def zotero_url
return unless reference?

begin
url = URI.parse(bibliography_url)
url.to_s if url.host =~ /zotero/i
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/exhibit_extension.rb
Expand Up @@ -17,13 +17,15 @@ module ExhibitExtension
# @return [Viewer]
def required_viewer
return viewer if viewer.present?

Viewer.create(exhibit: self)
end

private

def send_publish_state_change_notification
return unless saved_changes.key?('published')

SendPublishStateChangeNotificationJob.perform_later(exhibit: self, published: published)
end
end
2 changes: 2 additions & 0 deletions app/models/concerns/manifest_concern.rb
Expand Up @@ -7,13 +7,15 @@ module ManifestConcern
def manifest
manifest_url = fetch('iiif_manifest_url_ssi', nil)
return if manifest_url.blank? || !manifest_available?

manifest_url
end

def exhibit_specific_manifest(custom_manifest_pattern)
return manifest if custom_manifest_pattern.blank?
# Return early if there is not a manifest pattern (a heuristic for a non-image thing)
return manifest if manifest.blank?

custom_manifest_pattern.gsub('{id}', first('related_document_id_ssim') || first('id'))
end

Expand Down
1 change: 1 addition & 0 deletions app/models/full_text_parser.rb
Expand Up @@ -45,6 +45,7 @@ def full_text_url(file_name)

def alto_xml_string_content(content)
return [] if content.blank?

alto = Nokogiri::XML.parse(content)
alto_ns = alto.namespaces.values.first { |ns| ns =~ %r{standards/alto/ns} }
namespace = { alto: alto_ns || 'http://www.loc.gov/standards/alto/ns-v3#' }
Expand Down
2 changes: 2 additions & 0 deletions app/models/iiif_canvas_indexer.rb
Expand Up @@ -56,11 +56,13 @@ def range_labels_for(canvas_id)

def canvases
return [] unless manifest_url

@canvases ||= manifest_harvester.canvases
end

def manifest_harvester
return unless manifest_url

@manifest_harvester ||= IiifManifestHarvester.new(manifest_url)
end
end
1 change: 1 addition & 0 deletions app/models/viewer.rb
Expand Up @@ -17,6 +17,7 @@ def default_viewer_path

def to_partial_path
return default_viewer_path if viewer_type == 'sul-embed' || viewer_type.nil?

"../viewers/#{viewer_type}"
end
end
1 change: 1 addition & 0 deletions lib/traject/adjust_cardinality.rb
Expand Up @@ -33,6 +33,7 @@ def flatten_top_level(attributes)
attributes.except(*flatten).tap do |output|
flatten.each do |field|
next unless attributes.key?(field)

value = attributes.fetch(field).first
output[field] = value
output.delete(field) if value.blank?
Expand Down
6 changes: 6 additions & 0 deletions lib/traject/dor_config.rb
Expand Up @@ -148,6 +148,7 @@
each_record do |resource, context|
content_metadata = resource.public_xml.at_xpath('/publicObject/contentMetadata')
next if content_metadata.blank?

# Select conventional file images or virtual external ones
images = content_metadata.xpath('(resource/file[@mimetype="image/jp2"] | resource/externalFile[@mimetype="image/jp2"])')
thumbnail_data = images.first { |node| (node.attr('id') || node.attr('fileId')) =~ /jp2$/ }
Expand All @@ -156,20 +157,23 @@

to_field 'content_metadata_first_image_file_name_ssm' do |_resource, accumulator, context|
next unless context.clipboard['thumbnail_data']

# Allow for selection of conventional id's or virtual fileIds
file_id = (context.clipboard['thumbnail_data'].attr('id') || context.clipboard['thumbnail_data'].attr('fileId')).gsub('.jp2', '')
accumulator << file_id
end

to_field 'content_metadata_first_image_width_ssm' do |_resource, accumulator, context|
next unless context.clipboard['thumbnail_data']

image_data = context.clipboard['thumbnail_data'].at_xpath('./imageData')

accumulator << image_data['width']
end

to_field 'content_metadata_first_image_height_ssm' do |_resource, accumulator, context|
next unless context.clipboard['thumbnail_data']

image_data = context.clipboard['thumbnail_data'].at_xpath('./imageData')

accumulator << image_data['height']
Expand Down Expand Up @@ -256,6 +260,7 @@ def iiif_manifest_url(bare_druid)
def extract_geonames_ids(sdb)
sdb.smods_rec.subject.map do |z|
next unless z.geographic.any?

uri = z.geographic.attr('valueURI')
next if uri.nil?

Expand All @@ -273,6 +278,7 @@ def get_geonames_api_envelope(id)
xml = Nokogiri::XML Faraday.get(url).body
bbox = xml.at_xpath('//geoname/bbox')
return if bbox.nil?

min_x, max_x = [bbox.at_xpath('west').text.to_f, bbox.at_xpath('east').text.to_f].minmax
min_y, max_y = [bbox.at_xpath('north').text.to_f, bbox.at_xpath('south').text.to_f].minmax
"ENVELOPE(#{min_x},#{max_x},#{max_y},#{min_y})"
Expand Down
7 changes: 7 additions & 0 deletions lib/traject/macros/canvas.rb
Expand Up @@ -70,8 +70,10 @@ def extract_canvas_range_labels
def extract_canvas_annotation_list_urls
lambda do |record, accumulator, _context|
return if record['otherContent'].blank?

record['otherContent'].each do |link|
next unless link['@type'] == 'sc:AnnotationList'

accumulator << link['@id'].to_s
end
end
Expand All @@ -80,8 +82,10 @@ def extract_canvas_annotation_list_urls
def extract_canvas_annotations
lambda do |record, accumulator, _context|
return if record['otherContent'].blank?

record['otherContent'].each do |link|
next unless link['@type'] == 'sc:AnnotationList'

extract_annotations_from_list(accumulator, link['@id'].to_s)
end
end
Expand All @@ -92,6 +96,7 @@ def extract_canvas_related_document_ids
lambda do |record, accumulator, _context|
match = record['@id'][Exhibits::Application.config.druid_regex]
return if match.blank?

accumulator << match
end
end
Expand All @@ -101,9 +106,11 @@ def extract_canvas_related_document_ids
def extract_annotations_from_list(accumulator, url)
annotation_list = JSON.parse(Faraday.get(url).body)
return unless annotation_list['@type'] == 'sc:AnnotationList' && annotation_list['resources']

annotation_list['resources'].each do |resource|
next unless resource['@type'] == 'oa:Annotation'
next if resource['resource']['chars'].blank?

accumulator << resource['resource']['chars'].to_s
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/factories/user.rb
Expand Up @@ -4,15 +4,15 @@
FactoryBot.define do
factory :curator, class: User do
sequence(:email) { |n| "curator#{n}@example.com" }
password 'password'
password_confirmation 'password'
password { 'password' }
password_confirmation { 'password' }
after(:build) { |user| user.webauth_groups = 'dlss:exhibits-creators' }
end

factory :admin, class: User do
sequence(:email) { |n| "admin#{n}@example.com" }
password 'password'
password_confirmation 'password'
password { 'password' }
password_confirmation { 'password' }
after(:build) { |user| user.webauth_groups = 'dlss:exhibits-admin' }
end
end

0 comments on commit 2fa172a

Please sign in to comment.