Skip to content

Commit

Permalink
Allow overriding admin component templates
Browse files Browse the repository at this point in the history
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] - ViewComponent/view_component#411
[2] - https://viewcomponent.org/guide/templates.html#inline
  • Loading branch information
waiting-for-dev authored and elia committed Jun 9, 2023
1 parent 0be4f8f commit e6f4c0f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions admin/app/components/solidus_admin/main_nav_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
module SolidusAdmin
# Renders the main navigation of Solidus Admin.
class MainNavComponent < BaseComponent
erb_template <<~ERB
<nav>
<%=
render component("main_nav_item").with_collection(
container.all("main_nav").sort_by(&:position)
)
%>
</nav>
ERB
end
end

This file was deleted.

6 changes: 6 additions & 0 deletions admin/app/components/solidus_admin/main_nav_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ def initialize(item:)
@item = item
super
end

erb_template <<~ERB
<a href="#">
<%= item.title %>
</a>
ERB
end
end

This file was deleted.

0 comments on commit e6f4c0f

Please sign in to comment.