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
Add WYSIWYG editor to taxon description. (#11193)
Matthew Kennedy31c80f075634
diff --git a/backend/app/views/spree/admin/taxons/_form.html.erb b/backend/app/views/spree/admin/taxons/_form.html.erbindex 58571a1b1d..90882a8620 100644--- a/backend/app/views/spree/admin/taxons/_form.html.erb+++ b/backend/app/views/spree/admin/taxons/_form.html.erb@@ -39,7 +39,7 @@<%= f.field_container :description, class: ['form-group'] do %><%= f.label :description, Spree.t(:description) %>- <%= f.text_area :description, class: 'form-control', rows: 6 %>+ <%= f.text_area :description, class: "form-control #{'spree-rte' if taxon_wysiwyg_editor_enabled? }", rows: 20 %><% end %><%= f.field_container :meta_title, class: ['form-group'] do %>diff --git a/backend/spec/features/admin/products/edit/products_spec.rb b/backend/spec/features/admin/products/edit/products_spec.rbindex df7e6e02bb..a6b7549ebc 100644--- a/backend/spec/features/admin/products/edit/products_spec.rb+++ b/backend/spec/features/admin/products/edit/products_spec.rb@@ -3,7 +3,7 @@ require 'spec_helper'describe 'Product Details', type: :feature, js: true dostub_authorization!- context 'editing a product with wysiwyg disabled' do+ context 'editing a product with WYSIWYG disabled' dobefore doSpree::Config.product_wysiwyg_editor_enabled = falsecreate(:product, name: 'Bún thịt nướng', sku: 'A100', description: 'lorem ipsum', available_on: '2013-08-14 01:02:03')@@ -13,13 +13,13 @@ describe 'Product Details', type: :feature, js: true doafter { Spree::Config.product_wysiwyg_editor_enabled = true }- it 'lists the product description in standard input' do+ it 'displays the product description as a standard input field' doexpect(page).to have_field(id: 'product_description', with: 'lorem ipsum')expect(page).not_to have_css('#product_description_ifr')endend- context 'editing a product with wysiwyg editer on' do+ context 'editing a product with WYSIWYG editer enabled' dobefore doSpree::Config.product_wysiwyg_editor_enabled = truecreate(:product, name: 'Bún thịt nướng', sku: 'A100', description: 'lorem ipsum', available_on: '2013-08-14 01:02:03')@@ -27,11 +27,11 @@ describe 'Product Details', type: :feature, js: true dowithin_row(1) { click_icon :edit }end- it 'lists the product details' do+ it 'displays the product details with a WYSIWYG editor for the product description input' doexpect(page).to have_css('.content-header h1', text: 'Products / Bún thịt nướng')expect(page).to have_field(id: 'product_name', with: 'Bún thịt nướng')expect(page).to have_field(id: 'product_slug', with: 'bun-th-t-n-ng')- expect(page).not_to have_field(id: 'product_description', with: 'lorem ipsum')+ expect(page).not_to have_field(id: 'product_description')expect(page).to have_css('#product_description_ifr')expect(page).to have_field(id: 'product_price', with: '19.99')expect(page).to have_field(id: 'product_cost_price', with: '17.00')diff --git a/backend/spec/features/admin/taxons_spec.rb b/backend/spec/features/admin/taxons_spec.rbindex b2eed30d4d..19abdd4a7c 100644--- a/backend/spec/features/admin/taxons_spec.rb+++ b/backend/spec/features/admin/taxons_spec.rb@@ -6,11 +6,32 @@ describe 'Taxonomies and taxons', type: :feature, js: true dolet(:taxonomy) { create(:taxonomy, name: 'Hello') }let(:file_path) { Rails.root + '../../spec/support/ror_ringer.jpeg' }+ context 'when WYSIWYG editor is in enabled' do+ it 'displays the WYSIWYG editor for the taxon description input' do+ visit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root.id)++ expect(page).not_to have_css('#taxon_description')+ expect(page).to have_css('#taxon_description_ifr')+ end+ end++ context 'when WYSIWYG editor is disabled' do+ before { Spree::Config.taxon_wysiwyg_editor_enabled = false }++ after { Spree::Config.taxon_wysiwyg_editor_enabled = true }++ it 'displays the taxon description as a standard input field' do+ visit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root.id)++ expect(page).to have_css('#taxon_description')+ expect(page).not_to have_css('#taxon_description_ifr')+ end+ end+it 'admin should be able to edit taxon' dovisit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root_id)fill_in 'taxon_name', with: 'Shirt'- fill_in 'taxon_description', with: 'Discover our new rails shirts'fill_in 'permalink_part', with: 'shirt-rails'click_button 'Update'@@ -21,7 +42,6 @@ describe 'Taxonomies and taxons', type: :feature, js: true dovisit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root_id)fill_in 'taxon_name', with: ''- fill_in 'taxon_description', with: 'Discover our new rails shirts'fill_in 'permalink_part', with: 'shirt-rails'click_button 'Update'diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex 265388f8c2..4884d8dc6f 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -239,5 +239,9 @@ module Spreetag('meta', name: 'robots', content: current_store.seo_robots)end++ def taxon_wysiwyg_editor_enabled?+ Spree::Config[:taxon_wysiwyg_editor_enabled]+ endendenddiff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rbindex 0f83004b3e..a9c22c641f 100644--- a/core/app/models/spree/app_configuration.rb+++ b/core/app/models/spree/app_configuration.rb@@ -64,6 +64,7 @@ module Spreepreference :show_products_without_price, :boolean, default: falsepreference :show_raw_product_description, :boolean, default: falsepreference :tax_using_ship_address, :boolean, default: true+ preference :taxon_wysiwyg_editor_enabled, :boolean, default: truepreference :track_inventory_levels, :boolean, default: true # Determines whether to track on_hand values for variants / products.# Store credits configurationsdiff --git a/frontend/app/views/spree/taxons/_header.html.erb b/frontend/app/views/spree/taxons/_header.html.erbindex 4046fc4a65..3c6f3d36c0 100644--- a/frontend/app/views/spree/taxons/_header.html.erb+++ b/frontend/app/views/spree/taxons/_header.html.erb@@ -3,7 +3,12 @@<%= @taxon.name %></div><% unless @taxon.description.blank? %>- <div class="py-3 py-md-0 taxon-description"><%= @taxon.description %></div>+ <div class="py-3 py-md-0 taxon-description">+ <% if taxon_wysiwyg_editor_enabled? %>+ <%= raw @taxon.description %>+ <% else %>+ <%= @taxon.description %>+ <% end %><% end %><% if @taxon.icon&.attachment %><div class="d-none d-md-block pt-4 taxon-icon">diff --git a/frontend/spec/features/taxons_spec.rb b/frontend/spec/features/taxons_spec.rbindex 77b0e1e9fc..fe5a90c087 100644--- a/frontend/spec/features/taxons_spec.rb+++ b/frontend/spec/features/taxons_spec.rb@@ -4,7 +4,7 @@ describe 'viewing products', type: :feature, inaccessible: true dolet(:store) { Spree::Store.default }let!(:taxonomy) { create(:taxonomy, name: 'Category', store: store) }let!(:super_clothing) { taxonomy.root.children.create(name: 'Super Clothing', taxonomy_id: taxonomy.id) }- let!(:t_shirts) { super_clothing.children.create(name: 'T-Shirts', taxonomy_id: taxonomy.id) }+ let!(:t_shirts) { super_clothing.children.create(name: 'T-Shirts', taxonomy_id: taxonomy.id, description: '<h1>Super T-shirts</h1><table style="border-collapse: collapse; width: 100%;" border="1"><tbody><tr><td style="width: 98.66353978300181%;">I can display html tables.</td></tr></tbody></table>') }let(:metas) { { meta_description: 'Brand new Ruby on Rails TShirts', meta_title: 'Ruby On Rails TShirt', meta_keywords: 'ror, tshirt, ruby' } }let(:store_name) { store.name.to_s }@@ -44,6 +44,29 @@ describe 'viewing products', type: :feature, inaccessible: true doendend+ describe 'viewing taxon when WYSIWYG is enabled' do+ before do+ visit '/t/category/super-clothing/t-shirts'+ end++ it 'renders the html tables in the taxon description' do+ expect(page).to have_selector 'table'+ end+ end++ describe 'viewing taxon when WYSIWYG is disabled' do+ before do+ Spree::Config.taxon_wysiwyg_editor_enabled = false+ visit '/t/category/super-clothing/t-shirts'+ end++ after { Spree::Config.taxon_wysiwyg_editor_enabled = true }++ it 'strips out the html tables tags from the description' do+ expect(page).not_to have_selector 'table'+ end+ end+describe 'meta tags and title' doit 'displays metas' dot_shirts.update metas