Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Implement automatic DOM IDs and CSS classes for sections/blocks/links (#12538)

Damian Legawiecbf164fc847e6
diff --git a/storefront/app/helpers/spree/page_helper.rb b/storefront/app/helpers/spree/page_helper.rb
index 39d3d5cd02..ff026255f3 100644
--- a/storefront/app/helpers/spree/page_helper.rb
+++ b/storefront/app/helpers/spree/page_helper.rb
@@ -17,11 +17,14 @@ module Spree
variables[:section] = section
variables[:loaded] = true
+ css_id = "section-#{section.id}"
+ css_class = "section-#{section.class.name.demodulize.underscore.dasherize}"
+
if page_builder_enabled?
- turbo_frame_tag("section-#{section.id}") do
+ turbo_frame_tag(css_id, class: css_class) do
content_tag(:div,
data: {
- editor_id: "section-#{section.id}",
+ editor_id: css_id,
editor_name: section.name,
editor_link: spree.edit_admin_page_section_path(section)
}
@@ -35,11 +38,13 @@ module Spree
path = section.lazy_path(variables)
- turbo_frame_tag("section-#{section.id}", src: path, loading: 'eager') do
+ turbo_frame_tag(css_id, src: path, loading: 'eager', class: css_class) do
render('/' + section.to_partial_path, **variables)
end
else
- render('/' + section.to_partial_path, **variables)
+ content_tag(:div, id: css_id, class: css_class) do
+ render('/' + section.to_partial_path, **variables)
+ end
end
rescue ActionView::MissingTemplate, ActionView::Template::Error => e
raise e unless Rails.env.production?
diff --git a/storefront/app/helpers/spree/theme_helper.rb b/storefront/app/helpers/spree/theme_helper.rb
index 0b6c2a53f1..1de489bfd2 100644
--- a/storefront/app/helpers/spree/theme_helper.rb
+++ b/storefront/app/helpers/spree/theme_helper.rb
@@ -138,6 +138,8 @@ module Spree
editor_parent_id: "section-#{block.section_id}",
editor_link: spree.respond_to?(:edit_admin_page_section_block_path) ? spree.edit_admin_page_section_block_path(block.section, block) : nil
},
+ id: "block-#{block.id}",
+ class: "block-#{block.class.name.demodulize.underscore.dasherize}",
style: block_styles(block, allowed_styles: allowed_styles),
width_desktop: has_width_desktop
}.compact_blank
@@ -167,7 +169,9 @@ module Spree
when :block
spree.edit_admin_page_link_path(link, block_id: link.parent_id)
end
- }
+ },
+ id: "link-#{link.id}",
+ class: "link-#{link.class.name.demodulize.underscore.dasherize}"
}
else
{}