Class: Sasso::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
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

Instance Method Details

#add_watch_to_procfileObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/sasso/install/install_generator.rb', line 40

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_cssObject

Compile once so ‘app/assets/builds/application.css` exists and the first page load (stylesheet_link_tag “application”) doesn’t 404.



55
56
57
# File 'lib/generators/sasso/install/install_generator.rb', line 55

def build_initial_css
  rails_command "sasso:build"
end

#create_stylesheetObject



12
13
14
# File 'lib/generators/sasso/install/install_generator.rb', line 12

def create_stylesheet
  template "application.scss", "app/assets/stylesheets/application.scss"
end

#ensure_builds_directoryObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/sasso/install/install_generator.rb', line 16

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

Sprockets-only apps must link the builds directory in the manifest; Propshaft discovers it automatically, so guard on the manifest existing.



31
32
33
34
35
36
37
38
# File 'lib/generators/sasso/install/install_generator.rb', line 31

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


59
60
61
62
63
64
65
66
67
# File 'lib/generators/sasso/install/install_generator.rb', line 59

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