Module: Propshaft::Helper

Defined in:
lib/propshaft/helper.rb

Instance Method Summary collapse

Instance Method Details

#all_stylesheets_pathsObject

Returns a sorted and unique array of logical paths for all stylesheets in the load path.



21
22
23
# File 'lib/propshaft/helper.rb', line 21

def all_stylesheets_paths
  Rails.application.assets.load_path.asset_paths_by_type("css")
end

#app_stylesheets_pathsObject

Returns a sorted and unique array of logical paths for all stylesheets in app/assets/*/.css.



26
27
28
# File 'lib/propshaft/helper.rb', line 26

def app_stylesheets_paths
  Rails.application.assets.load_path.asset_paths_by_glob("#{Rails.root.join("app/assets")}/**/*.css")
end

#compute_asset_path(path, options = {}) ⇒ Object



3
4
5
# File 'lib/propshaft/helper.rb', line 3

def compute_asset_path(path, options = {})
  Rails.application.assets.resolver.resolve(path) || raise(MissingAssetError.new(path))
end

Add an option to call ‘stylesheet_link_tag` with `:all` to include every css file found on the load path or `:app` to include css files found in `Rails.root(“app/assets/*/.css”)`, which will exclude lib/ and plugins.



9
10
11
12
13
14
15
16
17
18
# File 'lib/propshaft/helper.rb', line 9

def stylesheet_link_tag(*sources, **options)
  case sources.first
  when :all
    super(*all_stylesheets_paths , **options)
  when :app
    super(*app_stylesheets_paths , **options)
  else
    super
  end
end