Skip to content

Commit

Permalink
Match path fix for tabs in Solidus < 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pelargir committed Jul 17, 2019
1 parent 3d6151c commit 26e806c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
29 changes: 29 additions & 0 deletions config/initializers/solidus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# In versions of Solidus prior to 2.8, we override this class to
# add the match_path option to the initializer. (Version 2.8 has
# this option already.) This option is used in the tabs partial
# to configure the paths for which a given tab is active.
#
if Spree.solidus_gem_version < Gem::Version.new('2.8')
Spree::BackendConfiguration::MenuItem.class_eval do
attr_reader :match_path

def initialize(
sections,
icon,
condition: nil,
label: nil,
partial: nil,
url: nil,
match_path: nil
)

@condition = condition || -> { true }
@sections = sections
@icon = icon
@label = label || sections.first
@partial = partial
@url = url
@match_path = match_path
end
end
end
9 changes: 9 additions & 0 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class Engine < ::Rails::Engine
end
end
end

# In versions of Solidus prior to 2.8, we override the tabs partial
# to pass a match_path value to each tab. (Version 2.8 is already
# passing this option.) This option is used to configure the paths
# for which a given tab is active.
#
if Spree.solidus_gem_version < Gem::Version.new('2.8')
paths['app/views'] << 'lib/match_path'
end
end
end
end
3 changes: 2 additions & 1 deletion lib/generators/alchemy/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def inject_admin_tab
\ label: :cms,
\ condition: -> { can?(:index, :alchemy_admin_dashboard) },
\ partial: 'spree/admin/shared/alchemy_sub_menu',
\ url: '/admin/pages'
\ url: '/admin/pages',
\ match_path: '/pages'
\ )
ADMIN_TAB
end
Expand Down
15 changes: 15 additions & 0 deletions lib/match_path/spree/admin/shared/_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% Spree::Backend::Config.menu_items.each do |menu_item| %>
<% if instance_exec(&menu_item.condition) %>
<%=
tab(
*menu_item.sections,
icon: menu_item.icon,
label: menu_item.label,
url: menu_item.url.is_a?(Symbol) ? spree.public_send(menu_item.url) : menu_item.url,
match_path: menu_item.match_path
) do
%>
<%- render partial: menu_item.partial if menu_item.partial %>
<%- end %>
<% end %>
<% end %>

0 comments on commit 26e806c

Please sign in to comment.