@@ -7,29 +7,20 @@ def render_data(options)
77 if Gon . global . all_variables . present?
88 data [ :global ] = Gon . global . all_variables
99 end
10- namespace = options [ :namespace ] || 'gon'
11- need_tag = options [ :need_tag ] . nil? || options [ :need_tag ]
12-
13- need_type = !options [ :need_type ] . nil? || options [ :need_type ]
14- need_type ? type = '<script type="text/javascript">' : type = '<script>'
15-
16- start = "#{ need_tag ? type : '' } window.#{ namespace } = {};"
10+ namespace , tag , cameled = parse_options options
11+ start = "#{ tag if tag } window.#{ namespace } = {};"
1712 script = ''
1813
19- if data . present?
20- if options [ :camel_case ]
21- data . each do |key , val |
22- script << "#{ namespace } .#{ key . to_s . camelize ( :lower ) } =#{ val . to_json } ;"
23- end
14+ data . each do |key , val |
15+ if cameled
16+ script << "#{ namespace } .#{ key . to_s . camelize ( :lower ) } =#{ val . to_json } ;"
2417 else
25- data . each do |key , val |
26- script << "#{ namespace } .#{ key . to_s } =#{ val . to_json } ;"
27- end
18+ script << "#{ namespace } .#{ key . to_s } =#{ val . to_json } ;"
2819 end
2920 end
3021
3122 script = start + Gon ::Escaper . escape ( script )
32- script << '</script>' if need_tag
23+ script << '</script>' if tag
3324 script . html_safe
3425 end
3526
@@ -57,6 +48,16 @@ def get_template_path(options, extension)
5748
5849 private
5950
51+ def parse_options ( options )
52+ namespace = options [ :namespace ] || 'gon'
53+ need_tag = options [ :need_tag ] . nil? || options [ :need_tag ]
54+ need_type = options [ :need_type ] . present? && options [ :need_type ]
55+ cameled = options [ :camel_case ]
56+ tag = need_tag && ( need_type ? '<script type="text/javascript">' : '<script>' )
57+
58+ [ namespace , tag , cameled ]
59+ end
60+
6061 def right_extension? ( extension , template_path )
6162 File . extname ( template_path ) == ".#{ extension } "
6263 end
0 commit comments