Class: Tramway::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Tramway::Generators::InstallGenerator
- Includes:
- InstallGeneratorHelpers
- Defined in:
- lib/generators/tramway/install/install_generator.rb
Overview
Running ‘rails generate tramway:install` will invoke this generator
Instance Method Summary collapse
-
#ensure_agents_file ⇒ Object
rubocop:disable Metrics/MethodLength.
- #ensure_dependencies ⇒ Object
- #ensure_importmap_pin ⇒ Object
- #ensure_stimulus_controller_registration ⇒ Object
- #ensure_tailwind_application_stylesheet ⇒ Object
- #ensure_tailwind_safelist ⇒ Object
-
#with_agents_update_fallback ⇒ Object
rubocop:enable Metrics/MethodLength.
Instance Method Details
#ensure_agents_file ⇒ Object
rubocop:disable Metrics/MethodLength
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/generators/tramway/install/install_generator.rb', line 240 def ensure_agents_file with_agents_update_fallback do if File.exist?(project_tramway_agents_path) say_status(:info, "Skipping AGENTS.md update because #{project_tramway_agents_path} exists.") return end say_status( :info, "Tramway will replace the content between \"#{agents_section_start}\" and " \ "\"#{agents_section_end}\" in AGENTS.md." ) return create_file(agents_file_path, "#{agents_template}\n") unless File.exist?(agents_file_path) content = File.read(agents_file_path) updated = replace_agents_section(content) return if updated == content File.write(agents_file_path, updated, mode: 'w:UTF-8') end end |
#ensure_dependencies ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/generators/tramway/install/install_generator.rb', line 270 def ensure_dependencies missing_dependencies = gem_dependencies.reject do |dependency| gemfile_contains?(dependency[:name]) end return if missing_dependencies.empty? append_to_file 'Gemfile', <<~GEMS # Tramway dependencies #{missing_dependencies.pluck(:declaration).join("\n")} GEMS end |
#ensure_importmap_pin ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/generators/tramway/install/install_generator.rb', line 313 def ensure_importmap_pin return unless File.exist?(importmap_path) content = File.read(importmap_path) missing_pins = importmap_tramway_pins.reject { |pin| content.include?(pin) } return if missing_pins.empty? File.open(importmap_path, 'a') do |file| file.write("\n") unless content.empty? || content.end_with?("\n") file.write("#{missing_pins.join("\n")}\n") end end |
#ensure_stimulus_controller_registration ⇒ Object
326 327 328 329 330 331 332 333 334 335 |
# File 'lib/generators/tramway/install/install_generator.rb', line 326 def ensure_stimulus_controller_registration return unless File.exist?(controllers_index_path) content = File.read(controllers_index_path) updated = append_missing_imports(content) updated = append_missing_registrations(updated) return if updated == content File.write(controllers_index_path, updated) end |
#ensure_tailwind_application_stylesheet ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/generators/tramway/install/install_generator.rb', line 298 def ensure_tailwind_application_stylesheet path = tailwind_application_stylesheet_path FileUtils.mkdir_p(File.dirname(path)) return create_file(path, "#{tailwind_css_import_line}\n") unless File.exist?(path) content = File.read(path) return if content.include?(tailwind_css_import_line) File.open(path, 'a') do |file| file.write("\n") unless content.empty? || content.end_with?("\n") file.write("#{tailwind_css_import_line}\n") end end |
#ensure_tailwind_safelist ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/generators/tramway/install/install_generator.rb', line 285 def ensure_tailwind_safelist return create_tailwind_config unless File.exist?(tailwind_config_path) source_entries = extract_safelist_entries(File.read(gem_tailwind_config_path)) target_content = File.read(tailwind_config_path) target_entries = extract_safelist_entries(target_content) missing_entries = source_entries - target_entries return if missing_entries.empty? File.write(tailwind_config_path, insert_entries(target_content, missing_entries)) end |
#with_agents_update_fallback ⇒ Object
rubocop:enable Metrics/MethodLength
264 265 266 267 268 |
# File 'lib/generators/tramway/install/install_generator.rb', line 264 def with_agents_update_fallback yield rescue StandardError => e say_status(:warning, "Skipping AGENTS.md update: #{e.}") end |