diff --git a/lib/propshaft/helper.rb b/lib/propshaft/helper.rb index 0ce4c6b..75b54ca 100644 --- a/lib/propshaft/helper.rb +++ b/lib/propshaft/helper.rb @@ -3,5 +3,23 @@ module Helper 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. + def stylesheet_link_tag(*sources) + if sources.first == :all + super *all_stylesheets_paths + 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 + .assets(content_types: [ Mime::EXTENSION_LOOKUP["css"] ]) + .collect { |css| css.logical_path.to_s } + .sort + .uniq + end end end diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css deleted file mode 100644 index 0ebd7fe..0000000 --- a/test/dummy/app/assets/stylesheets/application.css +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS - * files in this directory. Styles in this file should be added after the last require_* statement. - * It is generally better to create a new file per style scope. - * - *= require_tree . - *= require_self - */ diff --git a/test/dummy/app/assets/stylesheets/goodbye.css b/test/dummy/app/assets/stylesheets/goodbye.css new file mode 100644 index 0000000..dbb3df6 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/goodbye.css @@ -0,0 +1,3 @@ +h2:after { + content: "Goodbye!"; +} diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index 17ad412..afec532 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -5,7 +5,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag "application" %> + <%= stylesheet_link_tag :all %> diff --git a/test/propshaft_integration_test.rb b/test/propshaft_integration_test.rb index ea56951..6ad87a1 100644 --- a/test/propshaft_integration_test.rb +++ b/test/propshaft_integration_test.rb @@ -3,8 +3,12 @@ class PropshaftIntegrationTest < ActionDispatch::IntegrationTest test "should be able to resolve real assets" do get sample_load_real_assets_url + assert_response :success + assert_select 'link[href="/assets/hello_world-4137140a1298c3924d5f7135617c23e23fb167a8.css"]' + assert_select 'link[href="/assets/goodbye-b1dc9940e9800d8bc96f7434617c043e58277419.css"]' + assert_select 'script[src="/assets/hello_world-888761f849ba63a95a56f6ef898a9eb70ca4c46e.js"]' end