From 78d1880795a0fc049f8273301dda1c820211e30a Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Tue, 22 Aug 2023 15:09:28 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Ensuring=20we=20inject=20Hyrax::?= =?UTF-8?q?DOI=20views=20before=20Hyrax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this commit, the logic for finding the Hyrax in the view path was assuming a version number (e.g. `hyrax-2.`); however if the we pinned Hyrax to a branch/sha then we might have `hyrax-a`. The result being that we pre-prended the view path into the application. That created the conditions where the `view_paths` first element might not have been the application but instead a gem/engine. Which means that the convention of overriding views in the application would not work. With this commit, we're using the Hyrax's engine's root to determine the view path suffix. Further, if Hyrax is not in the view path, we don't again inject at the beginning of the list the Hyrax::DOI engine into the view path. Related to: - https://github.com/scientist-softserv/palni-palci/pull/731 - https://github.com/samvera-labs/bulkrax/pull/855 --- lib/hyrax/doi/engine.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/hyrax/doi/engine.rb b/lib/hyrax/doi/engine.rb index 3f22acc..912c6ea 100644 --- a/lib/hyrax/doi/engine.rb +++ b/lib/hyrax/doi/engine.rb @@ -29,14 +29,12 @@ class Engine < ::Rails::Engine # Prepend our views in front of Hyrax but after the main app, so they have precedence # but can still be overridden my_engine_root = Hyrax::DOI::Engine.root.to_s + hyrax_engine_root = Hyrax::Engine.root.to_s paths = ActionController::Base.view_paths.collect(&:to_s) - hyrax_path = paths.detect { |path| path.match(/\/hyrax-[\d\.]+.*/) } - paths = if hyrax_path - paths.insert(paths.index(hyrax_path), my_engine_root + '/app/views') - else - paths.insert(0, my_engine_root + '/app/views') - end - ActionController::Base.view_paths = paths + hyrax_view_path = paths.detect { |path| path.match(%r{^#{hyrax_engine_root}}) } + paths.insert(paths.index(hyrax_view_path), File.join(my_engine_root, 'app', 'views')) if hyrax_view_path + + ActionController::Base.view_paths = paths.uniq end end end