app/helpers/requirejs_helper.rb in requirejs-rails-0.9.3 vs app/helpers/requirejs_helper.rb in requirejs-rails-0.9.4
- old
+ new
@@ -9,14 +9,14 @@
def _requirejs_data(name, &block)
{}.tap do |data|
if name
name += ".js" unless name =~ /\.js$/
- data['main'] = _javascript_path(name).
- sub(/\.js$/,'').
- sub(base_url(name), '').
- sub(/\A\//, '')
+ data['main'] = _javascript_path(name) \
+ .sub(/\.js$/, '') \
+ .sub(base_url(name), '') \
+ .sub(/\A\//, '')
end
data.merge!(yield controller) if block_given?
end.map do |k, v|
%Q{data-#{k}="#{v}"}
@@ -32,42 +32,44 @@
end
html = ""
_once_guard do
+ html.concat <<-HTML
+ <script #{_requirejs_data(name, &block)} src="#{_javascript_path 'require.js'}"></script>
+ HTML
+
unless requirejs.run_config.empty?
run_config = requirejs.run_config.dup
+
unless _priority.empty?
run_config = run_config.dup
run_config[:priority] ||= []
run_config[:priority].concat _priority
end
+
if Rails.application.config.assets.digest
modules = requirejs.build_config['modules'].map { |m| requirejs.module_name_for m }
# Generate digestified paths from the modules spec
paths = {}
- modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/,'' }
+ modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/, '' }
if run_config.has_key? 'paths'
# Add paths for assets specified by full URL (on a CDN)
- run_config['paths'].each { |k,v| paths[k] = v if v =~ /^https?:/ }
+ run_config['paths'].each { |k, v| paths[k] = v if v =~ /^https?:/ }
end
# Override user paths, whose mappings are only relevant in dev mode
# and in the build_config.
run_config['paths'] = paths
end
run_config['baseUrl'] = base_url(name)
html.concat <<-HTML
- <script>var require = #{run_config.to_json};</script>
+ <script>require.config(#{run_config.to_json});</script>
HTML
end
-
- html.concat <<-HTML
- <script #{_requirejs_data(name, &block)} src="#{_javascript_path 'require.js'}"></script>
- HTML
html.html_safe
end
end