Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 756ad50

Browse files
committed
Support custom Sprocket manifests
This change adds support for Rails 4 apps that have set their manifest to a custom one. In Rails 4, if `config.assets.manifest` is set, it must include the manifest's filename. For example: config.assets.manifest = "public/assets/manifest-foo.json" Note that while it's invalid for the manifest option to not include the filename in Rails 4, we are more forgiving and also accept values that don't contain the filename, in order to preserve backwards compatibility with previous requirejs-rails versions and Rails 3 apps.
1 parent a4b6359 commit 756ad50

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/requirejs/rails/engine.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ class Engine < ::Rails::Engine
3636
end
3737
end
3838

39-
manifest_directory = config.assets.manifest || File.join(::Rails.public_path, config.assets.prefix)
39+
manifest_directory = if config.assets.manifest
40+
File.basename(config.assets.manifest) =~ /\./ ? File.dirname(config.assets.manifest) : config.assets.manifest
41+
else
42+
File.join(::Rails.public_path, config.assets.prefix)
43+
end
44+
4045
manifest_path = File.join(manifest_directory, "rjs_manifest.yml")
4146
config.requirejs.manifest_path = Pathname.new(manifest_path)
4247
end
@@ -53,8 +58,7 @@ class Engine < ::Rails::Engine
5358
if ::Rails::VERSION::MAJOR >= 4
5459
config.after_initialize do |app|
5560
config = app.config
56-
rails_manifest_path = File.join(app.root, 'public', config.assets.prefix)
57-
rails_manifest = ::Sprockets::Manifest.new(app.assets, rails_manifest_path)
61+
rails_manifest = ::Sprockets::Manifest.new(app.assets, config.assets.manifest)
5862
if config.requirejs.manifest_path.exist? && rails_manifest
5963
rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
6064
rails_manifest.assets.merge!(rjs_digests)

0 commit comments

Comments
 (0)