From e6f4c0f8a5721ddf6e9e82147478de56a328d2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Fri, 26 May 2023 11:09:30 +0200 Subject: [PATCH] Allow overriding admin component templates Unfortunately, view_component doesn't allow overriding templates from the host application by just having the same relative path [1]. For now, we'll use the inline templates feature from v3 [2] so that host applications can override only the template while still inheriting the rest of view logic. [1] - https://github.com/ViewComponent/view_component/issues/411 [2] - https://viewcomponent.org/guide/templates.html#inline --- admin/app/components/solidus_admin/base_component.rb | 2 ++ admin/app/components/solidus_admin/main_nav_component.rb | 9 +++++++++ .../main_nav_component/main_nav_component.html.erb | 7 ------- .../components/solidus_admin/main_nav_item_component.rb | 6 ++++++ .../main_nav_item_component.html.erb | 1 - 5 files changed, 17 insertions(+), 8 deletions(-) delete mode 100644 admin/app/components/solidus_admin/main_nav_component/main_nav_component.html.erb delete mode 100644 admin/app/components/solidus_admin/main_nav_item_component/main_nav_item_component.html.erb diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index 366a409d14d..905a95bcac9 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -3,6 +3,8 @@ module SolidusAdmin # BaseComponent is the base class for all components in Solidus Admin. class BaseComponent < ViewComponent::Base + include ViewComponent::InlineTemplate + def container SolidusAdmin::Container end diff --git a/admin/app/components/solidus_admin/main_nav_component.rb b/admin/app/components/solidus_admin/main_nav_component.rb index 6c474eae1b5..48ef0d4c85c 100644 --- a/admin/app/components/solidus_admin/main_nav_component.rb +++ b/admin/app/components/solidus_admin/main_nav_component.rb @@ -3,5 +3,14 @@ module SolidusAdmin # Renders the main navigation of Solidus Admin. class MainNavComponent < BaseComponent + erb_template <<~ERB + + ERB end end diff --git a/admin/app/components/solidus_admin/main_nav_component/main_nav_component.html.erb b/admin/app/components/solidus_admin/main_nav_component/main_nav_component.html.erb deleted file mode 100644 index 3990d5136ad..00000000000 --- a/admin/app/components/solidus_admin/main_nav_component/main_nav_component.html.erb +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/admin/app/components/solidus_admin/main_nav_item_component.rb b/admin/app/components/solidus_admin/main_nav_item_component.rb index 60aad72d732..7f430080213 100644 --- a/admin/app/components/solidus_admin/main_nav_item_component.rb +++ b/admin/app/components/solidus_admin/main_nav_item_component.rb @@ -11,5 +11,11 @@ def initialize(item:) @item = item super end + + erb_template <<~ERB + + <%= item.title %> + + ERB end end diff --git a/admin/app/components/solidus_admin/main_nav_item_component/main_nav_item_component.html.erb b/admin/app/components/solidus_admin/main_nav_item_component/main_nav_item_component.html.erb deleted file mode 100644 index 9088e39f9ad..00000000000 --- a/admin/app/components/solidus_admin/main_nav_item_component/main_nav_item_component.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= item.title %>