Skip to content

Commit

Permalink
Include only app/assets/stylesheets when using stylesheet_link_tag :all
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoprietog committed May 16, 2024
1 parent ee55138 commit 9e645e6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/propshaft/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def load_path
@load_path ||= Propshaft::LoadPath.new(config.paths, version: config.version)
end

def application_stylesheets_load_path
@application_stylesheets_load_path ||= Propshaft::LoadPath.new([File.join(Rails.root, "app", "assets", "stylesheets")], version: config.version)
end

def resolver
@resolver ||= if manifest_path.exist?
Propshaft::Resolver::Static.new manifest_path: manifest_path, prefix: config.prefix
Expand Down
8 changes: 4 additions & 4 deletions lib/propshaft/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ def compute_asset_path(path, options = {})
# Add an option to call `stylesheet_link_tag` with `:all` to include every css file found on the load path.
def stylesheet_link_tag(*sources, **options)
if sources.first == :all
super(*all_stylesheets_paths, **options)
super(*all_application_stylesheets_paths, **options)
else
super
end
end

# Returns a sorted and unique array of logical paths for all stylesheets in the load path.
def all_stylesheets_paths
Rails.application.assets.load_path
# Returns a sorted and unique array of logical paths for all stylesheets only in the application stylesheets load path.
def all_application_stylesheets_paths
Rails.application.assets.application_stylesheets_load_path
.assets(content_types: [ Mime::EXTENSION_LOOKUP["css"] ])
.collect { |css| css.logical_path.to_s }
.sort
Expand Down
1 change: 1 addition & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.assets.paths << File.join(Rails.root, "vendor", "stylesheets")
end
end
Empty file.
1 change: 1 addition & 0 deletions test/propshaft_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class PropshaftIntegrationTest < ActionDispatch::IntegrationTest

assert_select 'link[href="/assets/hello_world-4137140a.css"][data-custom-attribute="true"]'
assert_select 'link[href="/assets/goodbye-b1dc9940.css"][data-custom-attribute="true"]'
assert_select 'link[href="/assets/library-356a192b.css"][data-custom-attribute="true"]', 0

assert_select 'script[src="/assets/hello_world-888761f8.js"]'
end
Expand Down

0 comments on commit 9e645e6

Please sign in to comment.