Class: Sasso::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sasso::Generators::InstallGenerator
- Defined in:
- lib/generators/sasso/install/install_generator.rb
Overview
‘bin/rails sasso:install` — scaffolds the entrypoint + build dir and wires a dev watch process, mirroring the dartsass/tailwindcss install flow.
Instance Method Summary collapse
- #add_watch_to_procfile ⇒ Object
-
#build_initial_css ⇒ Object
Compile once so ‘app/assets/builds/application.css` exists and the first page load (stylesheet_link_tag “application”) doesn’t 404.
- #create_stylesheet ⇒ Object
- #ensure_builds_directory ⇒ Object
-
#link_builds_in_sprockets_manifest ⇒ Object
Sprockets-only apps must link the builds directory in the manifest; Propshaft discovers it automatically, so guard on the manifest existing.
-
#link_stylesheet_in_layout ⇒ Object
Rails 8 layouts default to ‘stylesheet_link_tag :app`, which looks for “app.css” and won’t pick up our compiled “application.css”.
- #print_instructions ⇒ Object
-
#remove_default_application_css ⇒ Object
A fresh Propshaft/Sprockets app ships app/assets/stylesheets/application.css.
Instance Method Details
#add_watch_to_procfile ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/sasso/install/install_generator.rb', line 63 def add_watch_to_procfile procfile = "Procfile.dev" full = File.join(destination_root, procfile) if File.exist?(full) append_to_file procfile, "css: bin/rails sasso:watch\n" unless File.read(full).include?("sasso:watch") else create_file procfile, <<~PROCFILE web: bin/rails server css: bin/rails sasso:watch PROCFILE end end |
#build_initial_css ⇒ Object
Compile once so ‘app/assets/builds/application.css` exists and the first page load (stylesheet_link_tag “application”) doesn’t 404.
78 79 80 |
# File 'lib/generators/sasso/install/install_generator.rb', line 78 def build_initial_css rails_command "sasso:build" end |
#create_stylesheet ⇒ Object
22 23 24 |
# File 'lib/generators/sasso/install/install_generator.rb', line 22 def create_stylesheet template "application.scss", "app/assets/stylesheets/application.scss" end |
#ensure_builds_directory ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/sasso/install/install_generator.rb', line 39 def ensure_builds_directory create_file "app/assets/builds/.keep" unless File.exist?(builds_keep_path) rules = "/app/assets/builds/*\n!/app/assets/builds/.keep\n" if File.exist?(gitignore_path) # Idempotent: skip if already present (re-running the installer). append_to_file ".gitignore", rules unless File.read(gitignore_path).include?("/app/assets/builds/") else # No .gitignore at all — create one so generated CSS isn't committed. create_file ".gitignore", rules end end |
#link_builds_in_sprockets_manifest ⇒ Object
Sprockets-only apps must link the builds directory in the manifest; Propshaft discovers it automatically, so guard on the manifest existing.
54 55 56 57 58 59 60 61 |
# File 'lib/generators/sasso/install/install_generator.rb', line 54 def link_builds_in_sprockets_manifest manifest = "app/assets/config/manifest.js" full = File.join(destination_root, manifest) return unless File.exist?(full) return if File.read(full).include?("link_tree ../builds") append_to_file manifest, %(//= link_tree ../builds\n) end |
#link_stylesheet_in_layout ⇒ Object
Rails 8 layouts default to ‘stylesheet_link_tag :app`, which looks for “app.css” and won’t pick up our compiled “application.css”. Point it at the entrypoint we build. No-op if the layout is missing or already links “application” (so a customized layout is left alone).
30 31 32 33 34 35 36 37 |
# File 'lib/generators/sasso/install/install_generator.rb', line 30 def link_stylesheet_in_layout layout = "app/views/layouts/application.html.erb" full = File.join(destination_root, layout) return unless File.exist?(full) return if File.read(full).include?('stylesheet_link_tag "application"') gsub_file layout, /stylesheet_link_tag\s+:app\b/, 'stylesheet_link_tag "application"' end |
#print_instructions ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/generators/sasso/install/install_generator.rb', line 82 def print_instructions say "" say "sasso-rails installed.", :green say " • Edit app/assets/stylesheets/application.scss" say " • Reference it with: <%= stylesheet_link_tag \"application\" %>" say " • Build once: bin/rails sasso:build" say " • Watch in dev: bin/rails sasso:watch" say " (or ./bin/dev, if your app has a Procfile.dev runner like foreman)" end |
#remove_default_application_css ⇒ Object
A fresh Propshaft/Sprockets app ships app/assets/stylesheets/application.css. Our compiled output is app/assets/builds/application.css — both resolve to the logical path “application.css” on the asset load path, which collides. The build dir owns the compiled CSS now (the cssbundling convention), so drop the default stub.
17 18 19 20 |
# File 'lib/generators/sasso/install/install_generator.rb', line 17 def remove_default_application_css default = "app/assets/stylesheets/application.css" remove_file default if File.exist?(File.join(destination_root, default)) end |