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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Improve code for section type paths.
Matthew Kennedyca2b684f7bae
diff --git a/backend/app/helpers/spree/admin/cms_page_helper.rb b/backend/app/helpers/spree/admin/cms_page_helper.rbindex f373f8c13e..3ddcc35fa5 100644--- a/backend/app/helpers/spree/admin/cms_page_helper.rb+++ b/backend/app/helpers/spree/admin/cms_page_helper.rb@@ -56,7 +56,7 @@ module Spreeformatted_types = []Spree::CmsPage::PAGE_TYPES.each do |type|- last_word = type.split('::', 4).last+ last_word = type.split('::', 10).lastreadable_type = last_word.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')formatted_types << [readable_type, type]end@@ -65,12 +65,12 @@ module Spreeenddef humanize_cms_type(obj)- last_word = obj.type.split('::', 4).last+ last_word = obj.type.split('::', 10).lastlast_word.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')enddef parametize_cms_type(obj)- last_word = obj.type.split('::', 4).last+ last_word = obj.type.split('::', 10).lastlast_word.parameterize(separator: '_')endenddiff --git a/backend/app/helpers/spree/admin/cms_section_helper.rb b/backend/app/helpers/spree/admin/cms_section_helper.rbindex 5f3dc7c400..f1981020ac 100644--- a/backend/app/helpers/spree/admin/cms_section_helper.rb+++ b/backend/app/helpers/spree/admin/cms_section_helper.rb@@ -5,7 +5,7 @@ module Spreeformatted_types = []Spree::CmsSection::TYPES.each do |type|- last_word = type.split('::', 4).last+ last_word = type.split('::', 10).lastreadable_type = last_word.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')formatted_types << [readable_type, type]enddiff --git a/backend/app/helpers/spree/admin/menu_helper.rb b/backend/app/helpers/spree/admin/menu_helper.rbindex 752cb1d1fd..bbd6718e85 100644--- a/backend/app/helpers/spree/admin/menu_helper.rb+++ b/backend/app/helpers/spree/admin/menu_helper.rb@@ -25,7 +25,7 @@ module SpreeSpree::MenuItem::LINKED_RESOURCE_TYPE.each do |resource_type|formatted = if Spree::MenuItem::DYNAMIC_RESOURCE_TYPE.include? resource_type- str = resource_type.split('::', 3).last+ str = resource_type.split('::', 10).lastif str.starts_with?('Cms')str.slice(3, 100)elsediff --git a/backend/app/views/spree/admin/cms_pages/sections/_featured_atricle.html.erb b/backend/app/views/spree/admin/cms_pages/sections/_featured_atricle.html.erbdeleted file mode 100644index 6742da5baa..0000000000--- a/backend/app/views/spree/admin/cms_pages/sections/_featured_atricle.html.erb+++ /dev/null@@ -1,22 +0,0 @@-<div class="<%= width %>" data-section-id="<%= section.id %>">- <div class="row m-0 p-0 py-3 mb-3 border bg-white">- <div class="col" style="width:30px; max-width: 70px; text-align: center;">- <span class="move-handle"><%= svg_icon(name: 'sort.svg', width: '20', height: '20') %></span>- </div>- <div class="col text-center">- <div>Name: <%= section.name %></div>- <div>Type: <%= section.type %></div>- <div class="m-auto" style="width:50px;">- <% if section.icon.present? %>- <div class="cms_section_preview_image_holder">- <%= image_tag main_app.url_for(section.icon.attachment) %>- </div>- <% end %>- </div>- </div>- <div class="col actions" style="width:30px; max-width: 70px; text-align: center;">- <%= link_to_edit(section, no_text: true, url: spree.edit_admin_cms_page_cms_section_path(@cms_page, section)) %>- <%= link_to_delete(section, no_text: true, url: spree.admin_cms_page_cms_section_path(@cms_page, section)) if can?(:destroy, section) %>- </div>- </div>-</div>diff --git a/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb b/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erbdeleted file mode 100644index 0cc7c6d60b..0000000000--- a/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb+++ /dev/null@@ -1,22 +0,0 @@-<div class="<%= width %>" data-section-id="<%= section.id %>">- <div class="row m-0 p-0 py-3 mb-3 border bg-white">- <div class="col" style="width:30px; max-width: 70px; text-align: center;">- <span class="move-handle"><%= svg_icon(name: 'sort.svg', width: '20', height: '20') %></span>- </div>- <div class="col text-center">- <div>Name: <%= section.name %></div>- <div>Type: <%= humanize_cms_type(section) %></div>- <div class="m-auto" style="width:50px;">- <% if section.icon.present? %>- <div class="cms_section_preview_image_holder">- <%= image_tag main_app.url_for(section.icon.attachment) %>- </div>- <% end %>- </div>- </div>- <div class="col actions" style="width:30px; max-width: 70px; text-align: center;">- <%= link_to_edit(section, no_text: true, url: spree.edit_admin_cms_page_cms_section_path(@cms_page, section)) %>- <%= link_to_delete(section, no_text: true, url: spree.admin_cms_page_cms_section_path(@cms_page, section)) if can?(:destroy, section) %>- </div>- </div>-</div>diff --git a/backend/app/views/spree/admin/cms_pages/sections/_promo.html.erb b/backend/app/views/spree/admin/cms_pages/sections/_promo.html.erbdeleted file mode 100644index 6829f78149..0000000000--- a/backend/app/views/spree/admin/cms_pages/sections/_promo.html.erb+++ /dev/null@@ -1,22 +0,0 @@-<div class="<%= width %>" data-section-id="<%= section.id %>">- <div class="row m-0 p-0 py-3 mb-3 border bg-white">- <div class="col p-0 cms_section_action_col">- <span class="move-handle"><%= svg_icon(name: 'sort.svg', width: '20', height: '20') %></span>- </div>- <div class="col text-center p-0">- <div>Name: <%= section.name %></div>- <div>Type: <%= section.type %></div>- <div class="m-auto" style="width:50px;">- <% if section.icon.present? %>- <div class="cms_section_preview_image_holder">- <%= image_tag main_app.url_for(section.icon.attachment) %>- </div>- <% end %>- </div>- </div>- <div class="col p-0 actions cms_section_action_col">- <%= link_to_edit(section, no_text: true, url: spree.edit_admin_cms_page_cms_section_path(@cms_page, section)) %>- <%= link_to_delete(section, no_text: true, url: spree.admin_cms_page_cms_section_path(@cms_page, section)) if can?(:destroy, section) %>- </div>- </div>-</div>diff --git a/backend/app/views/spree/admin/cms_pages/sections/_text_block.html.erb b/backend/app/views/spree/admin/cms_pages/sections/_text_block.html.erbdeleted file mode 100644index 73e319cc46..0000000000--- a/backend/app/views/spree/admin/cms_pages/sections/_text_block.html.erb+++ /dev/null@@ -1,22 +0,0 @@-<div class="<%= width %>" data-section-id="<%= section.id %>">- <div class="row m-0 p-0 py-3 mb-3 border bg-white">- <div class="col p-0 cms_section_action_col">- <span class="move-handle"><%= svg_icon(name: 'sort.svg', width: '20', height: '20') %></span>- </div>- <div class="col text-center p-0">- <div>Name: <%= section.name %></div>- <div>Type: <%= section.type %></div>- <div class="m-auto">- <% if section.icon.present? %>- <div class="cms_section_preview_image_holder">- <%= image_tag main_app.url_for(section.icon.attachment) %>- </div>- <% end %>- </div>- </div>- <div class="col p-0 actions cms_section_action_col">- <%= link_to_edit(section, no_text: true, url: spree.edit_admin_cms_page_cms_section_path(@cms_page, section)) %>- <%= link_to_delete(section, no_text: true, url: spree.admin_cms_page_cms_section_path(@cms_page, section)) if can?(:destroy, section) %>- </div>- </div>-</div>diff --git a/backend/app/views/spree/admin/cms_sections/_form.html.erb b/backend/app/views/spree/admin/cms_sections/_form.html.erbindex 665db9debb..488ba712c9 100644--- a/backend/app/views/spree/admin/cms_sections/_form.html.erb+++ b/backend/app/views/spree/admin/cms_sections/_form.html.erb@@ -57,7 +57,7 @@<% if @cms_section.type.present? %><div class="row"><div class="col-12">- <%= render "spree/admin/cms_sections/types/#{@cms_section.type.parameterize(separator: '_')}", f: f %>+ <%= render "spree/admin/cms_sections/types/#{spree_resource_path(@cms_section)}", f: f %></div></div><% end %>diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_carousel.html.erb b/backend/app/views/spree/admin/cms_sections/types/_carousel.html.erbsimilarity index 100%rename from backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_carousel.html.erbrename to backend/app/views/spree/admin/cms_sections/types/_carousel.html.erbdiff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_categorybannersquare.html.erb b/backend/app/views/spree/admin/cms_sections/types/_category_banner_square.html.erbsimilarity index 100%rename from backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_categorybannersquare.html.erbrename to backend/app/views/spree/admin/cms_sections/types/_category_banner_square.html.erbdiff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featuredarticle.html.erb b/backend/app/views/spree/admin/cms_sections/types/_featured_article.html.erbsimilarity index 100%rename from backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featuredarticle.html.erbrename to backend/app/views/spree/admin/cms_sections/types/_featured_article.html.erbdiff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb b/backend/app/views/spree/admin/cms_sections/types/_hero.html.erbsimilarity index 100%rename from backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erbrename to backend/app/views/spree/admin/cms_sections/types/_hero.html.erbdiff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb b/backend/app/views/spree/admin/cms_sections/types/_promo.html.erbsimilarity index 100%rename from backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erbrename to backend/app/views/spree/admin/cms_sections/types/_promo.html.erbdiff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex 00b0e0c75c..b8f98150ff 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -18,6 +18,12 @@ module Spreeend.sort_by { |c| c.name.parameterize }end+ def spree_resource_path(resource)+ last_word = resource.class.name.split('::', 10).last++ last_word.underscore.humanize.parameterize(separator: '_')+ end+def display_price(product_or_variant)product_or_variant.price_in(current_currency).diff --git a/frontend/app/helpers/spree/cms_pages_helper.rb b/frontend/app/helpers/spree/cms_pages_helper.rbindex e39152823b..fea5193001 100644--- a/frontend/app/helpers/spree/cms_pages_helper.rb+++ b/frontend/app/helpers/spree/cms_pages_helper.rb@@ -5,8 +5,6 @@ module Spreeenddef build_section(section)- preview_type = section.type.parameterize(separator: '_')-if section.full_width_on_smallcase section.widthwhen 'Half'@@ -47,10 +45,10 @@ module Spreeendend- render "spree/shared/cms/sections/#{preview_type}", section: section,- width: css_width,- boundary: boundary,- element: element+ render "spree/shared/cms/sections/#{spree_resource_path(section)}", section: section,+ width: css_width,+ boundary: boundary,+ element: elementendendenddiff --git a/frontend/app/views/spree/home/index.html.erb b/frontend/app/views/spree/home/index.html.erbindex 56e57a5ae6..b2b6072f7f 100644--- a/frontend/app/views/spree/home/index.html.erb+++ b/frontend/app/views/spree/home/index.html.erb@@ -3,6 +3,8 @@<% if @homepage %><div class="container"><div id="featurePageContent" class="row">++<% @homepage.cms_sections.each do |section| %><%= build_section(section) %><% end %>diff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb b/frontend/app/views/spree/shared/cms/sections/_carousel.html.erbsimilarity index 100%rename from frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erbrename to frontend/app/views/spree/shared/cms/sections/_carousel.html.erbdiff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_categorybannersquare.html.erb b/frontend/app/views/spree/shared/cms/sections/_category_banner_square.html.erbsimilarity index 100%rename from frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_categorybannersquare.html.erbrename to frontend/app/views/spree/shared/cms/sections/_category_banner_square.html.erbdiff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featuredarticle.html.erb b/frontend/app/views/spree/shared/cms/sections/_featured_article.html.erbsimilarity index 100%rename from frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featuredarticle.html.erbrename to frontend/app/views/spree/shared/cms/sections/_featured_article.html.erbdiff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb b/frontend/app/views/spree/shared/cms/sections/_hero.html.erbsimilarity index 100%rename from frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erbrename to frontend/app/views/spree/shared/cms/sections/_hero.html.erbdiff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb b/frontend/app/views/spree/shared/cms/sections/_promo.html.erbsimilarity index 100%rename from frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erbrename to frontend/app/views/spree/shared/cms/sections/_promo.html.erb