Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SP-103] Register custom fragments in the admin panel forms #307

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/helpers/spree/admin/extension_partials_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Spree
module Admin
module ExtensionPartialsHelper
def render_matching(pattern:nil, locals: {})
old_path = Dir.pwd
rendered = ''
return rendered if pattern.nil?

view_paths.paths.each do |view_path|
Dir.chdir(view_path)
result = Dir['spree/admin/extension/**/*'].select do |path|
!File.directory?(path) && File.basename(path, '.html.erb') =~ /^_.+/
end

result.map! { |path| path.gsub(File.basename(path), File.basename(path, '.html.erb')[1..-1]) }
result.each do |path|
if path.match(/.+\/#{pattern}\/.+/)
rendered += render partial: path, locals: locals
end
end
end
Dir.chdir(old_path)
rendered
end
end
end
end
19 changes: 10 additions & 9 deletions app/views/spree/admin/products/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
<% product_actions.items.each do |action| %>
<% next unless action.available?(current_ability) %>
<%= button_link_to(
Spree.t(action.label_translation_key),
action.url(@product),
class: action.classes,
icon: action.icon_key,
id: action.id,
target: action.target,
data: action.data_attributes
) %>
Spree.t(action.label_translation_key),
action.url(@product),
class: action.classes,
icon: action.icon_key,
id: action.id,
target: action.target,
data: action.data_attributes
) %>
<% end if product_actions&.items %>
<% end %>

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

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