Module: Sasso::Rails

Defined in:
lib/sasso/rails.rb,
lib/sasso/rails/engine.rb,
lib/sasso/rails/version.rb,
lib/sasso/rails/compiler.rb

Defined Under Namespace

Classes: Compiler, Engine

Constant Summary collapse

VERSION =

Versioned INDEPENDENTLY of both the sasso gem and the sasso crate. The gemspec pins the engine gem with a range (sasso >= 0.1.1, < 1), so a compiler bump does not force a lockstep release of this integration gem.

"0.1.6"

Class Method Summary collapse

Class Method Details

.compiler(app = ::Rails.application) ⇒ Object

Build a Compiler from the running app's config + root.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sasso/rails/engine.rb', line 36

def compiler(app = ::Rails.application)
  cfg = app.config.sasso
  Compiler.new(
    root:       app.root,
    builds:     cfg.builds,
    style:      style_for(cfg.style),
    load_paths: cfg.load_paths,
    source_dir: cfg.source_dir,
    build_dir:  cfg.build_dir,
    source_map: source_map_for(cfg.source_map),
  )
end

.pipeline_css_compressor?Boolean

Returns:



73
74
75
76
77
# File 'lib/sasso/rails/engine.rb', line 73

def pipeline_css_compressor?
  ::Rails.application&.config&.assets&.css_compressor.present?
rescue StandardError
  false
end

.source_map_for(configured) ⇒ Object

Generate source maps outside production by default (debugging aid); an explicit config.sasso.source_map (true/false) always wins. Off in production by default to avoid shipping .map sidecars + the asset-digest interaction unless opted in.



53
54
55
56
57
# File 'lib/sasso/rails/engine.rb', line 53

def source_map_for(configured)
  return configured ? true : false unless configured.nil?

  !::Rails.env.production?
end

.style_for(configured) ⇒ Object

Default to compressed CSS in production (smaller payload), expanded elsewhere (readable). An explicit config.sasso.style always wins.

If the asset pipeline has its own CSS compressor (a Sprockets app that set config.assets.css_compressor), stay :expanded and let the pipeline compress, avoiding wasteful double-minification. Propshaft sets no compressor, so production stays :compressed on the default Rails 8 path.



66
67
68
69
70
71
# File 'lib/sasso/rails/engine.rb', line 66

def style_for(configured)
  return configured.to_sym if configured
  return :expanded if pipeline_css_compressor?

  ::Rails.env.production? ? :compressed : :expanded
end