Skip to content

Commit 4d1b565

Browse files
committed
Create 'extension partials' helper, present with an example
1 parent 808c4ac commit 4d1b565

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Spree
2+
module Admin
3+
module ExtensionPartialsHelper
4+
def render_matching(pattern:nil, locals: {})
5+
old_path = Dir.pwd
6+
rendered = ''
7+
return rendered if pattern.nil?
8+
9+
view_paths.paths.each do |view_path|
10+
Dir.chdir(view_path)
11+
result = Dir['spree/admin/extension/**/*'].select do |path|
12+
!File.directory?(path) && File.basename(path, '.html.erb') =~ /^_.+/
13+
end
14+
15+
result.map! { |path| path.gsub(File.basename(path), File.basename(path, '.html.erb')[1..-1]) }
16+
result.each do |path|
17+
if path.match(/.+\/#{pattern}\/.+/)
18+
rendered += render partial: path, locals: locals
19+
end
20+
end
21+
end
22+
Dir.chdir(old_path)
23+
rendered
24+
end
25+
end
26+
end
27+
end

app/views/spree/admin/products/edit.html.erb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
<% product_actions.items.each do |action| %>
33
<% next unless action.available?(current_ability) %>
44
<%= button_link_to(
5-
Spree.t(action.label_translation_key),
6-
action.url(@product),
7-
class: action.classes,
8-
icon: action.icon_key,
9-
id: action.id,
10-
target: action.target,
11-
data: action.data_attributes
12-
) %>
5+
Spree.t(action.label_translation_key),
6+
action.url(@product),
7+
class: action.classes,
8+
icon: action.icon_key,
9+
id: action.id,
10+
target: action.target,
11+
data: action.data_attributes
12+
) %>
1313
<% end if product_actions&.items %>
1414
<% end %>
1515

16-
<%= render partial: 'spree/admin/shared/product_tabs', locals: {current: :details} %>
16+
<%= render partial: 'spree/admin/shared/product_tabs', locals: { current: :details } %>
1717
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @product } %>
1818

1919
<%= form_for [:admin, @product], method: :put, html: { multipart: true } do |f| %>
2020
<fieldset>
2121
<%= render partial: 'form', locals: { f: f } %>
22+
<%= render_matching pattern: 'products/edit', locals: { f: f } %>
2223
<%= render partial: 'spree/admin/shared/edit_resource_links' %>
2324
</fieldset>
2425
<% end %>

0 commit comments

Comments
 (0)