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.

Add `rails g spree:storefront:theme ThemeName` generator to create … (#12470)

Damian Legawiec964b469e9ba0
diff --git a/storefront/lib/generators/spree/storefront/theme/templates/model.rb.tt b/storefront/lib/generators/spree/storefront/theme/templates/model.rb.tt
new file mode 100644
index 0000000000..af56d79a1c
--- /dev/null
+++ b/storefront/lib/generators/spree/storefront/theme/templates/model.rb.tt
@@ -0,0 +1,12 @@
+module Spree
+ module Themes
+ class <%= class_name %> < Default
+ def self.metadata
+ {
+ authors: ['Your Name'],
+ license: 'MIT',
+ }
+ end
+ end
+ end
+end
diff --git a/storefront/lib/generators/spree/storefront/theme/theme_generator.rb b/storefront/lib/generators/spree/storefront/theme/theme_generator.rb
new file mode 100644
index 0000000000..14fc349600
--- /dev/null
+++ b/storefront/lib/generators/spree/storefront/theme/theme_generator.rb
@@ -0,0 +1,41 @@
+require 'rails/generators'
+
+module Spree
+ module Storefront
+ module Generators
+ class ThemeGenerator < Rails::Generators::Base
+ argument :name, type: :string, default: 'my_theme'
+
+ def self.source_paths
+ [
+ File.expand_path('templates', __dir__),
+ File.expand_path('../../../../../app/views', __dir__)
+ ]
+ end
+
+ def copy_theme
+ empty_directory "app/models/spree/themes"
+ template "model.rb.tt", "app/models/spree/themes/#{file_name}.rb"
+
+ empty_directory "app/views/themes"
+
+ directory "themes/default", "app/views/themes/#{file_name}"
+
+ append_to_file "config/initializers/spree.rb", after: "Rails.application.config.after_initialize do\n" do
+ " Rails.application.config.spree.themes << Spree::Themes::#{class_name}\n"
+ end
+ end
+
+ no_tasks do
+ def class_name
+ name.classify
+ end
+
+ def file_name
+ name.underscore
+ end
+ end
+ end
+ end
+ end
+end