@@ -33,34 +33,42 @@ def requirejs_include_tag(name=nil, &block)
33
33
34
34
html = ""
35
35
36
- if controller . requirejs_included
37
- raise Requirejs ::MultipleIncludeError , "Only one requirejs_include_tag allowed per page."
38
- end
39
-
40
- unless requirejs . run_config . empty?
41
- run_config = requirejs . run_config
42
- if Rails . application . config . assets . digest
43
- modules = requirejs . build_config [ 'modules' ] . map { |m | requirejs . module_name_for m }
36
+ _once_guard do
37
+ unless requirejs . run_config . empty?
38
+ run_config = requirejs . run_config
39
+ if Rails . application . config . assets . digest
40
+ modules = requirejs . build_config [ 'modules' ] . map { |m | requirejs . module_name_for m }
44
41
45
- # Generate digestified paths from the modules spec
46
- paths = { }
47
- modules . each { |m | paths [ m ] = javascript_path ( m ) . sub /\. js$/ , '' }
42
+ # Generate digestified paths from the modules spec
43
+ paths = { }
44
+ modules . each { |m | paths [ m ] = javascript_path ( m ) . sub /\. js$/ , '' }
48
45
49
- # Override uesr paths, whose mappings are only relevant in dev mode
50
- # and in the build_config.
51
- run_config [ 'paths' ] = paths
46
+ # Override uesr paths, whose mappings are only relevant in dev mode
47
+ # and in the build_config.
48
+ run_config [ 'paths' ] = paths
49
+ end
50
+ html . concat <<-HTML
51
+ < script > var require = #{ run_config . to_json } ;</ script>
52
+ HTML
52
53
end
54
+
53
55
html . concat <<-HTML
54
- < script > var require = #{ run_config . to_json } ; </ script>
56
+ < script #{ _requirejs_data ( name , & block ) } src=" #{ javascript_path 'require.js' } " > </ script>
55
57
HTML
58
+
59
+ html . html_safe
60
+ end
61
+ end
62
+
63
+ def _once_guard
64
+ if defined? ( controller ) && controller . requirejs_included
65
+ raise Requirejs ::MultipleIncludeError , "Only one requirejs_include_tag allowed per page."
56
66
end
57
67
58
- html . concat <<-HTML
59
- < script #{ _requirejs_data ( name , &block ) } src="#{ javascript_path 'require.js' } "> </ script>
60
- HTML
68
+ retval = yield
61
69
62
- controller . requirejs_included = true
63
- html . html_safe
70
+ controller . requirejs_included = true if defined? ( controller )
71
+ retval
64
72
end
65
73
66
74
def _almond_include_tag ( name , &block )
0 commit comments