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.0"

Class Method Summary collapse

Class Method Details

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

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



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

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,
  )
end

.pipeline_css_compressor?Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/sasso/rails/engine.rb', line 60

def pipeline_css_compressor?
  ::Rails.application&.config&.assets&.css_compressor.present?
rescue StandardError
  false
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.



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

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

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