10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/helpers/requirejs_helper.rb', line 10
def requirejs_include_tag(name=nil, &block)
requirejs = Rails.application.config.requirejs
if requirejs.loader == :almond
name = requirejs.module_name_for(requirejs.build_config['modules'][0])
return almond_include_tag(name, &block)
end
html = ""
once_guard do
rjs_attributes = {
src: javascript_path("require")
}
rjs_attributes = rjs_attributes.merge(Hash[block.call(controller).map do |key, value|
["data-#{key}", value]
end]) \
if block
html.concat(content_tag(:script, "", rjs_attributes))
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 }
paths = {}
modules.each { |m| paths[m] = javascript_path(m).sub /\.js$/, '' }
if run_config.has_key? 'paths'
run_config['paths'].each do |k, v|
paths[k] = v if v.is_a?(Array) || v =~ /^https?:/
end
end
run_config['paths'] = paths
end
run_config['baseUrl'] = base_url(name)
html.concat(content_tag(:script) do
script = "require.config(#{run_config.to_json});"
script.concat(" require([#{name.dump}]);") \
if name
script.html_safe
end)
end
html.html_safe
end
end
|