lib/generators/phlex/install/install_generator.rb in phlex-rails-1.2.2 vs lib/generators/phlex/install/install_generator.rb in phlex-rails-2.0.0.beta1
- old
+ new
@@ -3,58 +3,52 @@
module Phlex::Generators
class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)
APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb")
- TAILWIND_CONFIGURATION_PATH = Rails.root.join("tailwind.config.js")
- def autoload_components
- return unless APPLICATION_CONFIGURATION_PATH.exist?
+ def configure_tailwind
+ if tailwind_configuration_path
+ insert_into_file tailwind_configuration_path, after: "content: [" do
+ "\n './app/views/**/*.rb', // Phlex views" \
+ "\n './app/components/**/*.rb', // Phlex components" \
+ end
+ end
+ end
- inject_into_class(
- APPLICATION_CONFIGURATION_PATH,
- "Application",
- %( config.autoload_paths << "\#{root}/app/views/components"\n)
- )
+ def create_application_component
+ template "base_component.rb.erb", Rails.root.join("app/components/base.rb")
end
- def autoload_layouts
- return unless APPLICATION_CONFIGURATION_PATH.exist?
+ def create_application_view
+ template "base_view.rb.erb", Rails.root.join("app/views/base.rb")
+ end
- inject_into_class(
- APPLICATION_CONFIGURATION_PATH,
- "Application",
- %( config.autoload_paths << "\#{root}/app/views/layouts"\n)
- )
+ def create_hello_component
+ template "hello_component.rb.erb", Rails.root.join("app/components/hello.rb")
end
- def autoload_views
- return unless APPLICATION_CONFIGURATION_PATH.exist?
-
- inject_into_class(
- APPLICATION_CONFIGURATION_PATH,
- "Application",
- %( config.autoload_paths << "\#{root}/app/views"\n)
- )
+ def create_initializer
+ template "phlex.rb.erb", Rails.root.join("config/initializers/phlex.rb")
end
- def configure_tailwind
- return unless TAILWIND_CONFIGURATION_PATH.exist?
+ private
- insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do
- "\n './app/views/**/*.rb'," \
+ def tailwind_configuration_path
+ if tailwind_configuration_files.any?
+ Pathname.new(
+ tailwind_configuration_files.first,
+ )
end
end
- def create_application_component
- template "application_component.rb", Rails.root.join("app/views/components/application_component.rb")
- end
-
- def create_application_layout
- template "application_layout.rb", Rails.root.join("app/views/layouts/application_layout.rb")
- end
-
- def create_application_view
- template "application_view.rb", Rails.root.join("app/views/application_view.rb")
+ def tailwind_configuration_files
+ Dir.glob(
+ [
+ "#{Rails.root}/tailwind.config.js",
+ "#{Rails.root}/app/**/tailwind.config.js",
+ "#{Rails.root}/config/**/tailwind.config.js",
+ ],
+ )
end
end
end