Skip to content

Commit

Permalink
🐛 Move helper for snippets method
Browse files Browse the repository at this point in the history
Ref: https://github.com/scientist-softserv/adventist-dl/issues/469
Method `render_ocr_snippets` was causing AbstractController::DoubleRenderError
() during random situations, due to including the IiifPrintHelper in
ApplicationController.

This pull request moves it into a helper module which is injected by the
install generator, which matches how it was done in LV & NNP. See
https://github.com/scientist-softserv/louisville-hyku/blob/b672d2a3213aaee84c082eb8083d8ad70733036b/app/helpers/newspaper_works_helper.rb#L3
  • Loading branch information
LaRita Robinson authored and jeremyf committed Jul 5, 2023
1 parent b06d818 commit bdadcc0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
22 changes: 22 additions & 0 deletions app/helpers/iiif_print/iiif_print_helper_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module IiifPrint::IiifPrintHelperBehavior
##
# print the ocr snippets. if more than one, separate with <br/>
#
# @param options [Hash] options hash provided by Blacklight
# @return [String] snippets HTML to be rendered
# rubocop:disable Rails/OutputSafety
def render_ocr_snippets(options = {})
# debugger
snippets = options[:value]
snippets_content = [content_tag('div',
"... #{snippets.first} ...".html_safe,
class: 'ocr_snippet first_snippet')]
if snippets.length > 1
snippets_content << render(partial: 'catalog/snippets_more',
locals: { snippets: snippets.drop(1),
options: options })
end
snippets_content.join("\n").html_safe
end
# rubocop:enable Rails/OutputSafety
end
20 changes: 0 additions & 20 deletions app/helpers/iiif_print_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,4 @@ def highlight_matches(document, hl_fl, hl_tag)
end
hl_matches.uniq.sort.join(' ')
end

##
# print the ocr snippets. if more than one, separate with <br/>
#
# @param options [Hash] options hash provided by Blacklight
# @return [String] snippets HTML to be rendered
# rubocop:disable Rails/OutputSafety
def render_ocr_snippets(options = {})
snippets = options[:value]
snippets_content = [content_tag('div',
"... #{snippets.first} ...".html_safe,
class: 'ocr_snippet first_snippet')]
if snippets.length > 1
snippets_content << render(partial: 'catalog/snippets_more',
locals: { snippets: snippets.drop(1),
options: options })
end
snippets_content.join("\n").html_safe
end
# rubocop:enable Rails/OutputSafety
end
4 changes: 4 additions & 0 deletions lib/generators/iiif_print/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def inject_assets
generate 'iiif_print:assets'
end

def inject_helper
copy_file 'helpers/iiif_print_helper.rb'
end

# Blacklight IIIF Search generator has some linting that does not agree with CircleCI on Hyku
# ref https://github.com/boston-library/blacklight_iiif_search/blob/v1.0.0/lib/generators/blacklight_iiif_search/controller_generator.rb
# the follow two methods does a clean up to appease Rubocop
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module IiifPrintHelper
include IiifPrint::IiifPrintHelperBehavior
end

0 comments on commit bdadcc0

Please sign in to comment.