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

Commit d86fb5c

Browse files
committed
Merge pull request #74 from juwalter/master
Allows use of Sprockets manifest path for rjs_manifest.yml
2 parents d477ee5 + 546c0a9 commit d86fb5c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def _requirejs_data(name, &block)
1111
{}.tap do |data|
1212
if name
1313
name += ".js" unless name =~ /\.js$/
14-
data['main'] = _javascript_path(name).sub(/\.js$/,'')
14+
data['main'] = _javascript_path(name).
15+
sub(/\.js$/,'').
16+
sub(baseUrl(name), '').
17+
sub(/\A\//, '')
1518
end
1619

1720
data.merge!(yield controller) if block_given?
@@ -54,6 +57,8 @@ def requirejs_include_tag(name=nil, &block)
5457
# and in the build_config.
5558
run_config['paths'] = paths
5659
end
60+
61+
run_config['baseUrl'] = baseUrl(name)
5762
html.concat <<-HTML
5863
<script>var require = #{run_config.to_json};</script>
5964
HTML
@@ -89,4 +94,11 @@ def _javascript_path(name)
8994
"/assets/#{name}"
9095
end
9196
end
97+
98+
def baseUrl(js_asset)
99+
js_asset_path = javascript_path(js_asset)
100+
uri = URI.parse(js_asset_path)
101+
asset_host = uri.host && js_asset_path.sub(uri.request_uri, '')
102+
[asset_host, Rails.application.config.assets.prefix].join
103+
end
92104
end

lib/requirejs/rails/engine.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Engine < ::Rails::Engine
2121

2222
config.assets.precompile += config.requirejs.precompile
2323

24-
manifest_path = File.join(::Rails.public_path, config.assets.prefix, "rjs_manifest.yml")
24+
manifest_directory = config.assets.manifest || File.join(::Rails.public_path, config.assets.prefix)
25+
manifest_path = File.join(manifest_directory, "rjs_manifest.yml")
2526
config.requirejs.manifest_path = Pathname.new(manifest_path)
2627
end
2728

0 commit comments

Comments
 (0)