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

Commit 3b70693

Browse files
committed
Use the require.config configuration passing style in preparation for improved almond.js support
1 parent ac678ee commit 3b70693

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +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).
15-
sub(/\.js$/,'').
16-
sub(base_url(name), '').
17-
sub(/\A\//, '')
14+
data['main'] = _javascript_path(name) \
15+
.sub(/\.js$/, '') \
16+
.sub(base_url(name), '') \
17+
.sub(/\A\//, '')
1818
end
1919

2020
data.merge!(yield controller) if block_given?
@@ -34,23 +34,29 @@ def requirejs_include_tag(name=nil, &block)
3434
html = ""
3535

3636
_once_guard do
37+
html.concat <<-HTML
38+
<script #{_requirejs_data(name, &block)} src="#{_javascript_path 'require.js'}"></script>
39+
HTML
40+
3741
unless requirejs.run_config.empty?
3842
run_config = requirejs.run_config.dup
43+
3944
unless _priority.empty?
4045
run_config = run_config.dup
4146
run_config[:priority] ||= []
4247
run_config[:priority].concat _priority
4348
end
49+
4450
if Rails.application.config.assets.digest
4551
modules = requirejs.build_config['modules'].map { |m| requirejs.module_name_for m }
4652

4753
# Generate digestified paths from the modules spec
4854
paths = {}
49-
modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/,'' }
55+
modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/, '' }
5056

5157
if run_config.has_key? 'paths'
5258
# Add paths for assets specified by full URL (on a CDN)
53-
run_config['paths'].each { |k,v| paths[k] = v if v =~ /^https?:/ }
59+
run_config['paths'].each { |k, v| paths[k] = v if v =~ /^https?:/ }
5460
end
5561

5662
# Override user paths, whose mappings are only relevant in dev mode
@@ -60,14 +66,10 @@ def requirejs_include_tag(name=nil, &block)
6066

6167
run_config['baseUrl'] = base_url(name)
6268
html.concat <<-HTML
63-
<script>var require = #{run_config.to_json};</script>
69+
<script>require.config(#{run_config.to_json});</script>
6470
HTML
6571
end
6672

67-
html.concat <<-HTML
68-
<script #{_requirejs_data(name, &block)} src="#{_javascript_path 'require.js'}"></script>
69-
HTML
70-
7173
html.html_safe
7274
end
7375
end

0 commit comments

Comments
 (0)