From ba0c58e79bb9553fd2c5420d4269270b49402e02 Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Mon, 16 Mar 2026 14:40:43 +0000 Subject: [PATCH 01/10] Fix image records in demo data --- plugins/ShinyCMS/lib/tasks/demo_site.rake | 2 ++ plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/plugins/ShinyCMS/lib/tasks/demo_site.rake b/plugins/ShinyCMS/lib/tasks/demo_site.rake index 999e9c15d..578c973ca 100644 --- a/plugins/ShinyCMS/lib/tasks/demo_site.rake +++ b/plugins/ShinyCMS/lib/tasks/demo_site.rake @@ -34,6 +34,8 @@ namespace :shinycms do load_demo_site_data_file + load_demo_site_extras + ShinyCMS::FeatureFlag.enable :user_login puts 'Loaded demo site data and created admin account.' diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index 9777ffac9..3fef8213d 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -139,5 +139,13 @@ def fix_primary_key_sequence( table_name ) COMMIT; SQL end + + def load_demo_site_extras + ActiveStorage::Attachment.all.each do |attached| + name = attached.filename.to_s + io = File.open( Rails.root.join( 'public', 'images', name ) ) + attached.record.image.attach io: , filename: name + end + end end end From 00481004c3a48d34608d8ac5c9361dc1f4a6bbb0 Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Mon, 16 Mar 2026 16:18:24 +0000 Subject: [PATCH 02/10] Fix missing var --- plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index 3fef8213d..94cb046bf 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -144,7 +144,7 @@ def load_demo_site_extras ActiveStorage::Attachment.all.each do |attached| name = attached.filename.to_s io = File.open( Rails.root.join( 'public', 'images', name ) ) - attached.record.image.attach io: , filename: name + attached.record.image.attach io: io, filename: name end end end From de49ac9e5988af11ea95be28725ac18cabe68c62 Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Mon, 16 Mar 2026 16:25:05 +0000 Subject: [PATCH 03/10] The open method is available via the Rails object --- plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index 94cb046bf..7e3d1c2ff 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -143,8 +143,8 @@ def fix_primary_key_sequence( table_name ) def load_demo_site_extras ActiveStorage::Attachment.all.each do |attached| name = attached.filename.to_s - io = File.open( Rails.root.join( 'public', 'images', name ) ) - attached.record.image.attach io: io, filename: name + file = Rails.root.join( 'public', 'images', name ).open + attached.record.image.attach io: file, filename: name end end end From a70219bb1ede1bdb4daf790a959a129e95218613 Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Mon, 16 Mar 2026 16:28:24 +0000 Subject: [PATCH 04/10] Use public_path method --- plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index 7e3d1c2ff..3ebd47c4a 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -143,7 +143,7 @@ def fix_primary_key_sequence( table_name ) def load_demo_site_extras ActiveStorage::Attachment.all.each do |attached| name = attached.filename.to_s - file = Rails.root.join( 'public', 'images', name ).open + file = Rails.public_path( 'public', 'images', name ).open attached.record.image.attach io: file, filename: name end end From 63caf4f8faf374f0e31a3b6b55d7a5096342d1c2 Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Thu, 19 Mar 2026 09:15:19 +0000 Subject: [PATCH 05/10] Fiddle with demo data tasks for rubocop --- plugins/ShinyCMS/lib/tasks/demo_site.rake | 8 ++------ plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/ShinyCMS/lib/tasks/demo_site.rake b/plugins/ShinyCMS/lib/tasks/demo_site.rake index 578c973ca..95850b520 100644 --- a/plugins/ShinyCMS/lib/tasks/demo_site.rake +++ b/plugins/ShinyCMS/lib/tasks/demo_site.rake @@ -24,9 +24,9 @@ namespace :shinycms do namespace :demo do include ShinyCMS::DemoSiteTask + # :nocov: desc 'ShinyCMS: reset database, create admin user, and load demo site data' task load: %i[ environment dotenv confirm db:reset shinycms:admin:get_admin_details ] do - # :nocov: prepare_admin_account_for_import( @shiny_admin ) ShinyCMS::Setting.set :theme_name, to: 'halcyonic' @@ -40,28 +40,24 @@ namespace :shinycms do puts 'Loaded demo site data and created admin account.' puts "You can log in as '#{@shiny_admin.username}' now." - # :nocov: end task confirm: %i[ environment dotenv ] do - # :nocov: $stdout.print 'Loading the demo site data wipes the database. Are you sure? (y/N) ' unless $stdin.gets.chomp.downcase.in? %w[ y yes ] puts 'Thank you. No action taken, database is unchanged.' exit end - # :nocov: end task export: %i[ environment dotenv ] do - # :nocov: prepare_for_export demo_data = munge_user_id_in create_statements_for_all models_with_demo_data write_demo_data_to_file( demo_data ) - # :nocov: end + # :nocov: end end diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index 3ebd47c4a..bd1cf89f8 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -141,7 +141,7 @@ def fix_primary_key_sequence( table_name ) end def load_demo_site_extras - ActiveStorage::Attachment.all.each do |attached| + ActiveStorage::Attachment.all.find_each do |attached| name = attached.filename.to_s file = Rails.public_path( 'public', 'images', name ).open attached.record.image.attach io: file, filename: name From e8f985fb4348a5fc6d14e7dc71c2fccc0d5da93a Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Thu, 19 Mar 2026 09:18:48 +0000 Subject: [PATCH 06/10] Remove superfluous .all --- plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index bd1cf89f8..fad95e897 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -141,7 +141,7 @@ def fix_primary_key_sequence( table_name ) end def load_demo_site_extras - ActiveStorage::Attachment.all.find_each do |attached| + ActiveStorage::Attachment.find_each do |attached| name = attached.filename.to_s file = Rails.public_path( 'public', 'images', name ).open attached.record.image.attach io: file, filename: name From 8531096386eb3161cc011e67bcc5bd4039548c6f Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Thu, 19 Mar 2026 09:30:36 +0000 Subject: [PATCH 07/10] Trim one line to appease rubocop --- plugins/ShinyCMS/lib/tasks/demo_site.rake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/ShinyCMS/lib/tasks/demo_site.rake b/plugins/ShinyCMS/lib/tasks/demo_site.rake index 95850b520..7e80d66ec 100644 --- a/plugins/ShinyCMS/lib/tasks/demo_site.rake +++ b/plugins/ShinyCMS/lib/tasks/demo_site.rake @@ -24,9 +24,9 @@ namespace :shinycms do namespace :demo do include ShinyCMS::DemoSiteTask - # :nocov: desc 'ShinyCMS: reset database, create admin user, and load demo site data' task load: %i[ environment dotenv confirm db:reset shinycms:admin:get_admin_details ] do + # :nocov: prepare_admin_account_for_import( @shiny_admin ) ShinyCMS::Setting.set :theme_name, to: 'halcyonic' @@ -38,26 +38,29 @@ namespace :shinycms do ShinyCMS::FeatureFlag.enable :user_login - puts 'Loaded demo site data and created admin account.' - puts "You can log in as '#{@shiny_admin.username}' now." + puts "Loaded demo site data and created admin account. You can log in as '#{@shiny_admin.username}' now." + # :nocov: end task confirm: %i[ environment dotenv ] do + # :nocov: $stdout.print 'Loading the demo site data wipes the database. Are you sure? (y/N) ' unless $stdin.gets.chomp.downcase.in? %w[ y yes ] puts 'Thank you. No action taken, database is unchanged.' exit end + # :nocov: end task export: %i[ environment dotenv ] do + # :nocov: prepare_for_export demo_data = munge_user_id_in create_statements_for_all models_with_demo_data write_demo_data_to_file( demo_data ) + # :nocov: end - # :nocov: end end From 00abf457826de927bc69c740a93a68145d66ef6a Mon Sep 17 00:00:00 2001 From: Denny <2025@denny.me> Date: Sun, 22 Mar 2026 08:11:14 +0000 Subject: [PATCH 08/10] Start using templates when rendering Shop pages --- .../shiny_shop/admin/templates_controller.rb | 2 +- .../app/controllers/shiny_shop/products_controller.rb | 11 ++++++++++- plugins/ShinyShop/app/models/shiny_shop/product.rb | 1 + .../views/shiny_shop/products/no-sidebar.html.erb | 8 ++++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/ShinyShop/app/controllers/shiny_shop/admin/templates_controller.rb b/plugins/ShinyShop/app/controllers/shiny_shop/admin/templates_controller.rb index 437452470..d95c81e90 100644 --- a/plugins/ShinyShop/app/controllers/shiny_shop/admin/templates_controller.rb +++ b/plugins/ShinyShop/app/controllers/shiny_shop/admin/templates_controller.rb @@ -58,7 +58,7 @@ def edit def update authorize @template - if sort_elements && @template.update( strong_params ) + if sort_elements && @template.update!( strong_params ) redirect_to shiny_shop.edit_template_path( @template ), notice: t( '.success' ) else flash.now[ :alert ] = t( '.failure' ) diff --git a/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb b/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb index 9d9c39bf5..64affa9a9 100644 --- a/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb +++ b/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb @@ -40,12 +40,21 @@ def show if just_purchased? confirm_order else - render 'show' + show_product end end private + # Render the product with the appropriate template + def show_product + if @product.template.file_exists? + render template: "shiny_shop/products/#{@product.template.filename}", locals: @product.elements_hash + else + render status: :failed_dependency, inline: I18n.t( 'shiny_shop.products.template_file_missing' ) + end + end + def find_section( path_parts, error: true ) section_scope = Section.top_level_sections diff --git a/plugins/ShinyShop/app/models/shiny_shop/product.rb b/plugins/ShinyShop/app/models/shiny_shop/product.rb index 2883df5ff..b1d266a5b 100644 --- a/plugins/ShinyShop/app/models/shiny_shop/product.rb +++ b/plugins/ShinyShop/app/models/shiny_shop/product.rb @@ -13,6 +13,7 @@ class Product < ApplicationRecord include ShinyCMS::HasPublicName include ShinyCMS::HasReadableName include ShinyCMS::HasSlug + include ShinyCMS::HasTemplate include ShinyCMS::ProvidesDemoSiteData diff --git a/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb b/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb index 919e60747..4b7e26e1e 100644 --- a/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb +++ b/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb @@ -9,8 +9,12 @@