File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,15 @@ def render_data(options)
1212 start = "#{ need_tag ? '<script>' : '' } window.#{ namespace } = {};"
1313 script = ''
1414
15- if options [ :camel_case ]
16- data . each do |key , val |
17- script << "#{ namespace } .#{ key . to_s . camelize ( :lower ) } =#{ val . to_json } ;"
18- end
19- else
20- data . each do |key , val |
21- script << "#{ namespace } .#{ key . to_s } =#{ val . to_json } ;"
15+ if data . present?
16+ if options [ :camel_case ]
17+ data . each do |key , val |
18+ script << "#{ namespace } .#{ key . to_s . camelize ( :lower ) } =#{ val . to_json } ;"
19+ end
20+ else
21+ data . each do |key , val |
22+ script << "#{ namespace } .#{ key . to_s } =#{ val . to_json } ;"
23+ end
2224 end
2325 end
2426
Original file line number Diff line number Diff line change 8181
8282
8383 it 'outputs correct js without variables, without tag and gon init' do
84+ @base . include_gon ( need_tag : false , init : true ) . should == 'window.gon = {};'
85+ end
86+
87+ it 'outputs correct js without variables, without tag and gon init' do
88+ Gon . int = 1
8489 @base . include_gon ( need_tag : false , init : true ) . should == \
85- 'window.gon = {};'
90+ 'window.gon = {};' +
91+ 'gon.int=1;'
8692 end
8793
8894 end
You can’t perform that action at this time.
0 commit comments