gon 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gon might be problematic. Click here for more details.
- data/CHANGELOG.md +6 -1
- data/README.md +12 -2
- data/lib/gon/base.rb +9 -7
- data/lib/gon/helpers.rb +3 -0
- data/lib/gon/jbuilder.rb +8 -0
- data/lib/gon/version.rb +1 -1
- data/spec/gon/basic_spec.rb +13 -0
- data/spec/gon/jbuilder_spec.rb +5 -0
- data/spec/test_data/sample_with_helpers.json.jbuilder +1 -0
- metadata +4 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -82,6 +82,16 @@ You can change the namespace of the variables:
|
|
82
82
|
...
|
83
83
|
```
|
84
84
|
|
85
|
+
You can initialize window.gon = {}; on each request
|
86
|
+
|
87
|
+
``` erb
|
88
|
+
<head>
|
89
|
+
<title>some title</title>
|
90
|
+
<%= include_gon(:init => true) %>
|
91
|
+
<!-- include your action js code with 'serverExports' namespace -->
|
92
|
+
...
|
93
|
+
```
|
94
|
+
|
85
95
|
You can get json without script tag (kudos to @afa):
|
86
96
|
|
87
97
|
``` erb
|
@@ -339,13 +349,13 @@ Thats it!
|
|
339
349
|
Puts this line into `Gemfile` then run `$ bundle`:
|
340
350
|
|
341
351
|
``` ruby
|
342
|
-
gem 'gon', '3.0.
|
352
|
+
gem 'gon', '3.0.3'
|
343
353
|
```
|
344
354
|
|
345
355
|
Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
|
346
356
|
|
347
357
|
``` ruby
|
348
|
-
config.gem 'gon', :version => '3.0.
|
358
|
+
config.gem 'gon', :version => '3.0.3'
|
349
359
|
```
|
350
360
|
|
351
361
|
Or manually install gon gem: `$ gem install gon`
|
data/lib/gon/base.rb
CHANGED
@@ -12,13 +12,15 @@ module Gon
|
|
12
12
|
start = "#{need_tag ? '<script>' : ''}window.#{namespace} = {};"
|
13
13
|
script = ''
|
14
14
|
|
15
|
-
if
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
data/lib/gon/helpers.rb
CHANGED
data/lib/gon/jbuilder.rb
CHANGED
@@ -8,6 +8,8 @@ module Gon
|
|
8
8
|
raise 'You should provide :template when use rabl with global variables'
|
9
9
|
end
|
10
10
|
|
11
|
+
include_helpers
|
12
|
+
|
11
13
|
data = parse_jbuilder \
|
12
14
|
Gon::Base.get_template_path(options,'jbuilder'),
|
13
15
|
Gon::Base.get_controller(options)
|
@@ -17,6 +19,12 @@ module Gon
|
|
17
19
|
|
18
20
|
private
|
19
21
|
|
22
|
+
def include_helpers
|
23
|
+
unless self.class.include? ::ActionView::Helpers
|
24
|
+
self.class.send(:include, ::ActionView::Helpers)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
20
28
|
def parse_options_from(args)
|
21
29
|
if old_api? args
|
22
30
|
text = "[DEPRECATION] view_path argument is now optional. "
|
data/lib/gon/version.rb
CHANGED
data/spec/gon/basic_spec.rb
CHANGED
@@ -79,6 +79,19 @@ describe Gon do
|
|
79
79
|
'gon.int=1;'
|
80
80
|
end
|
81
81
|
|
82
|
+
|
83
|
+
it 'outputs correct js without variables, without tag and gon init' do
|
84
|
+
@base.include_gon(need_tag: false, init: true).should == \
|
85
|
+
'window.gon = {};'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'outputs correct js without variables, without tag and gon init' do
|
89
|
+
Gon.int = 1
|
90
|
+
@base.include_gon(need_tag: false, init: true).should == \
|
91
|
+
'window.gon = {};' +
|
92
|
+
'gon.int=1;'
|
93
|
+
end
|
94
|
+
|
82
95
|
end
|
83
96
|
|
84
97
|
it 'returns exception if try to set public method as variable' do
|
data/spec/gon/jbuilder_spec.rb
CHANGED
@@ -26,6 +26,11 @@ describe Gon do
|
|
26
26
|
Gon.objects.length.should == 2
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'render json from jbuilder template with helpers' do
|
30
|
+
Gon.jbuilder 'spec/test_data/sample_with_helpers.json.jbuilder', :controller => controller
|
31
|
+
Gon.date.should == 'about 6 hours'
|
32
|
+
end
|
33
|
+
|
29
34
|
it 'render json from jbuilder template with a partial' do
|
30
35
|
controller.view_paths << 'spec/test_data'
|
31
36
|
Gon.jbuilder 'spec/test_data/sample_with_partial.json.jbuilder', :controller => controller
|
@@ -0,0 +1 @@
|
|
1
|
+
json.date distance_of_time_in_words(20000)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- spec/test_data/_sample_partial.json.jbuilder
|
142
142
|
- spec/test_data/sample.json.jbuilder
|
143
143
|
- spec/test_data/sample.rabl
|
144
|
+
- spec/test_data/sample_with_helpers.json.jbuilder
|
144
145
|
- spec/test_data/sample_with_helpers.rabl
|
145
146
|
- spec/test_data/sample_with_partial.json.jbuilder
|
146
147
|
homepage: https://github.com/gazay/gon
|
@@ -176,5 +177,6 @@ test_files:
|
|
176
177
|
- spec/test_data/_sample_partial.json.jbuilder
|
177
178
|
- spec/test_data/sample.json.jbuilder
|
178
179
|
- spec/test_data/sample.rabl
|
180
|
+
- spec/test_data/sample_with_helpers.json.jbuilder
|
179
181
|
- spec/test_data/sample_with_helpers.rabl
|
180
182
|
- spec/test_data/sample_with_partial.json.jbuilder
|