From 5a63c6b672816a24dd72f290acc3582830946706 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Wed, 4 Oct 2023 10:49:31 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Introduce=20Hyku::Applicat?= =?UTF-8?q?ion.theme=5Fview=5Fpath=5Froots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the introduction of [HykuKnapsack][1], we are adjusting how we create instances of Hyku. Namely we don't clone Hyku but instead we incorporate Hyku as a submodule into a Knapsack. The Knapsack is a Rails engine that is mounted in the Hyku application. What this means is that when we want to Prior to this commit, the only way to adjust themed views would have been to add them to the Rails application (e.g. Hyku) directly. Which would work in a non-Knapsack ecosystem. However, with Knapsack we need a means of saying "Hey, for themes we want to be able to add/adjust views within the knapsack." Hence this change. There should be a pairing commit in Knapsack that injects the `HykuKnapsack::Engine.root` into the `Hyku::Application.theme_view_path_roots` array. [1]: https://github.com/samvera-labs/hyku_knapsack --- .../concerns/hyrax/works_controller_behavior.rb | 6 ++++-- app/controllers/hyrax/contact_form_controller.rb | 6 ++++-- app/controllers/hyrax/pages_controller.rb | 6 ++++-- config/application.rb | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/controllers/concerns/hyrax/works_controller_behavior.rb b/app/controllers/concerns/hyrax/works_controller_behavior.rb index f5b51f64f..c006262d9 100644 --- a/app/controllers/concerns/hyrax/works_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/works_controller_behavior.rb @@ -505,8 +505,10 @@ def available_admin_sets def inject_show_theme_views if show_page_theme && show_page_theme != 'default_show' original_paths = view_paths - show_theme_view_path = Rails.root.join('app', 'views', "themes", show_page_theme.to_s) - prepend_view_path(show_theme_view_path) + Hyku::Application.theme_view_path_roots.each do |root| + show_theme_view_path = root.join('app', 'views', "themes", show_page_theme.to_s) + prepend_view_path(show_theme_view_path) + end yield # rubocop:disable Lint/UselessAssignment, Layout/SpaceAroundOperators, Style/RedundantParentheses # Do NOT change this line. This is calling the Rails view_paths=(paths) method and not a variable assignment. diff --git a/app/controllers/hyrax/contact_form_controller.rb b/app/controllers/hyrax/contact_form_controller.rb index 17f6cb614..17a74aea0 100644 --- a/app/controllers/hyrax/contact_form_controller.rb +++ b/app/controllers/hyrax/contact_form_controller.rb @@ -101,8 +101,10 @@ def collections(rows: 6) def inject_theme_views if home_page_theme && home_page_theme != 'default_home' original_paths = view_paths - home_theme_view_path = Rails.root.join('app', 'views', "themes", home_page_theme.to_s) - prepend_view_path(home_theme_view_path) + Hyku::Application.theme_view_path_roots.each do |root| + home_theme_view_path = root.join('app', 'views', "themes", home_page_theme.to_s) + prepend_view_path(home_theme_view_path) + end yield # rubocop:disable Lint/UselessAssignment, Layout/SpaceAroundOperators, Style/RedundantParentheses # Do NOT change this line. This is calling the Rails view_paths=(paths) method and not a variable assignment. diff --git a/app/controllers/hyrax/pages_controller.rb b/app/controllers/hyrax/pages_controller.rb index cdfd8d0a7..44e020fd5 100644 --- a/app/controllers/hyrax/pages_controller.rb +++ b/app/controllers/hyrax/pages_controller.rb @@ -101,8 +101,10 @@ def collections(rows: 6) def inject_theme_views if home_page_theme && home_page_theme != 'default_home' original_paths = view_paths - home_theme_view_path = Rails.root.join('app', 'views', "themes", home_page_theme.to_s) - prepend_view_path(home_theme_view_path) + Hyku::Application.theme_view_path_roots.each do |root| + home_theme_view_path = root.join('app', 'views', "themes", home_page_theme.to_s) + prepend_view_path(home_theme_view_path) + end yield # rubocop:disable Lint/UselessAssignment, Layout/SpaceAroundOperators, Style/RedundantParentheses # Do NOT change this method. This is an override of the view_paths= method and not a variable assignment. diff --git a/config/application.rb b/config/application.rb index c221d0090..37fb578f6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -34,6 +34,21 @@ def self.utf_8_encode(string) end class Application < Rails::Application + ## + # @return [Array] an array of strings in which we should be looking for theme view + # candidates. + # @see Hyrax::WorksControllerBehavior + # @see Hyrax::ContactFormController + # @see Hyrax::PagesController + # @see https://api.rubyonrails.org/classes/ActionView/ViewPaths.html#method-i-prepend_view_path + # + # @see .path_for + def self.theme_view_path_roots + returning_value = [Rails.root.to_s] + returning_value.push HykuKnapsack::Engine.root.to_s if defined?(HykuKnapsack) + returning_value + end + # Add this line to load the lib folder first because we need config.autoload_paths.unshift("#{Rails.root}/lib")