gon 3.0.0 → 3.0.2
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 +4 -0
- data/README.md +21 -8
- data/lib/gon/base.rb +4 -2
- data/lib/gon/version.rb +1 -1
- data/spec/gon/basic_spec.rb +15 -0
- metadata +45 -15
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 get json without script tag (kudos to @afa):
|
86
|
+
|
87
|
+
``` erb
|
88
|
+
<head>
|
89
|
+
<title>some title</title>
|
90
|
+
<script><%= include_gon(:need_tag => false) %></script>
|
91
|
+
<!-- include your action js code with 'serverExports' namespace -->
|
92
|
+
...
|
93
|
+
```
|
94
|
+
|
85
95
|
You put something like this in the action of your controller:
|
86
96
|
|
87
97
|
``` ruby
|
@@ -302,21 +312,24 @@ wouldn't work. You can read about this in common usage above.
|
|
302
312
|
Now you can use gon for sending your data to js from anywhere!
|
303
313
|
|
304
314
|
It works just as simple `gon` but you need to write `Gon.global` instead of `gon` in your ruby code,
|
305
|
-
`gon.global` in javascript and it will not clear self after each request. All other things the same.
|
315
|
+
`gon.global` in javascript and it will not clear self after each request. All other things remain the same.
|
316
|
+
|
317
|
+
For example I want to set start data into gon, which will be there before I clear it.
|
318
|
+
|
319
|
+
Maybe some configuration data or url address which should be present on each page with `include_gon` helper in head.
|
306
320
|
|
307
|
-
|
321
|
+
Now with Gon.global it's easy!
|
308
322
|
|
309
|
-
`config/initializers/
|
323
|
+
`config/initializers/some_initializer.rb or any file where you can reach Gon constant`
|
310
324
|
|
311
325
|
```ruby
|
312
|
-
|
313
|
-
Gon.global.session = 'You can't see it I said'
|
326
|
+
Gon.global.variable = 'Some data'
|
314
327
|
```
|
315
328
|
|
316
329
|
`in some js which can reach window.gon variable`
|
317
330
|
|
318
331
|
```javascript
|
319
|
-
alert(gon.global.
|
332
|
+
alert(gon.global.variable)
|
320
333
|
```
|
321
334
|
|
322
335
|
Thats it!
|
@@ -326,13 +339,13 @@ Thats it!
|
|
326
339
|
Puts this line into `Gemfile` then run `$ bundle`:
|
327
340
|
|
328
341
|
``` ruby
|
329
|
-
gem 'gon', '3.0.
|
342
|
+
gem 'gon', '3.0.2'
|
330
343
|
```
|
331
344
|
|
332
345
|
Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
|
333
346
|
|
334
347
|
``` ruby
|
335
|
-
config.gem 'gon', :version => '3.0.
|
348
|
+
config.gem 'gon', :version => '3.0.2'
|
336
349
|
```
|
337
350
|
|
338
351
|
Or manually install gon gem: `$ gem install gon`
|
data/lib/gon/base.rb
CHANGED
@@ -8,7 +8,8 @@ module Gon
|
|
8
8
|
end
|
9
9
|
data = Gon.all_variables
|
10
10
|
namespace = options[:namespace] || 'gon'
|
11
|
-
|
11
|
+
need_tag = options[:need_tag].nil? || options[:need_tag]
|
12
|
+
start = "#{need_tag ? '<script>' : ''}window.#{namespace} = {};"
|
12
13
|
script = ''
|
13
14
|
|
14
15
|
if options[:camel_case]
|
@@ -21,7 +22,8 @@ module Gon
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
script = start + Gon::Escaper.escape(script)
|
25
|
+
script = start + Gon::Escaper.escape(script)
|
26
|
+
script << '</script>' if need_tag
|
25
27
|
script.html_safe
|
26
28
|
end
|
27
29
|
|
data/lib/gon/version.rb
CHANGED
data/spec/gon/basic_spec.rb
CHANGED
@@ -64,6 +64,21 @@ describe Gon do
|
|
64
64
|
'</script>'
|
65
65
|
end
|
66
66
|
|
67
|
+
it 'outputs correct js with an integer, camel-case and namespace' do
|
68
|
+
Gon.int_cased = 1
|
69
|
+
@base.include_gon(camel_case: true, namespace: 'camel_cased').should == \
|
70
|
+
'<script>window.camel_cased = {};' +
|
71
|
+
'camel_cased.intCased=1;' +
|
72
|
+
'</script>'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'outputs correct js with an integer and without tag' do
|
76
|
+
Gon.int = 1
|
77
|
+
@base.include_gon(need_tag: false).should == \
|
78
|
+
'window.gon = {};' +
|
79
|
+
'gon.int=1;'
|
80
|
+
end
|
81
|
+
|
67
82
|
end
|
68
83
|
|
69
84
|
it 'returns exception if try to set public method as variable' do
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: json
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rabl
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rspec
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: jbuilder
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rake
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
description: If you need to send some data to your js files and you don't want to
|
81
111
|
do this with long way trough views and parsing - use this force!
|
82
112
|
email:
|
@@ -133,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
163
|
version: '0'
|
134
164
|
requirements: []
|
135
165
|
rubyforge_project: gon
|
136
|
-
rubygems_version: 1.8.
|
166
|
+
rubygems_version: 1.8.24
|
137
167
|
signing_key:
|
138
168
|
specification_version: 3
|
139
169
|
summary: Get your Rails variables in your JS
|