gon 6.0.1 → 6.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/Rakefile +1 -1
- data/gon.gemspec +1 -0
- data/lib/gon.rb +1 -1
- data/lib/gon/base.rb +3 -4
- data/lib/gon/helpers.rb +1 -1
- data/lib/gon/jbuilder.rb +1 -1
- data/lib/gon/jbuilder/parser.rb +6 -6
- data/lib/gon/request.rb +4 -13
- data/lib/gon/version.rb +1 -1
- data/spec/gon/basic_spec.rb +31 -90
- data/spec/gon/global_spec.rb +0 -2
- data/spec/gon/jbuilder_spec.rb +0 -2
- data/spec/gon/rabl_with_rabl_rails_spec.rb +0 -2
- data/spec/gon/rabl_with_rabl_spec.rb +0 -2
- data/spec/gon/templates_spec.rb +0 -2
- data/spec/gon/thread_spec.rb +0 -2
- data/spec/gon/watch_spec.rb +2 -4
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d24de7434f197bf9f86ea9ef17bbcf9ec585647
|
4
|
+
data.tar.gz: 49a264791c39e669f5364b469c6c9c119372b504
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f121380839a33259810a5c1a2e7a4a149b91521b6d7c9d6b4b5742bd02977ee33aec47e43f31c78adeabb1ba748f20fea0a786819d84ac6c6809e27c376d6d
|
7
|
+
data.tar.gz: 65d68f8c2e182d32be8191f164b86917bf33d8d08f16fddceab7361acd0a3afe894933014cdc35296686b990bc0e7648f23268fe1d376f6f42c84fc70def1d99
|
data/.travis.yml
CHANGED
@@ -3,12 +3,15 @@ sudo: false
|
|
3
3
|
rvm:
|
4
4
|
- 1.9.3
|
5
5
|
- 2.0.0
|
6
|
-
- 2.1
|
7
|
-
- 2.2
|
6
|
+
- 2.1
|
7
|
+
- 2.2
|
8
|
+
- 2.3.0
|
9
|
+
- ruby-head
|
8
10
|
- jruby-19mode # JRuby in 1.9 mode
|
9
11
|
- rbx
|
10
12
|
matrix:
|
11
13
|
allow_failures:
|
12
14
|
- rvm: rbx
|
15
|
+
- rvm: ruby-head
|
13
16
|
# uncomment this line if your project needs to run something other than `rake`:
|
14
17
|
# script: bundle exec rspec spec
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2011-
|
3
|
+
Copyright (c) 2011-2016 gazay
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
6
|
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
![Gon. You should try this. If you look closer - you will see an elephant.](https://github.com/gazay/gon/raw/master/doc/logo_small.png)
|
6
6
|
|
7
|
-
[![Build Status](https://
|
7
|
+
[![Build Status](https://travis-ci.org/gazay/gon.svg?branch=master)](https://travis-ci.org/gazay/gon) [![CodeClimate](https://codeclimate.com/github/gazay/gon/badges/gpa.svg)](https://codeclimate.com/github/gazay/gon)
|
8
8
|
|
9
9
|
If you need to send some data to your js files and you don't want to do this with long way through views and parsing - use this force!
|
10
10
|
|
@@ -78,21 +78,21 @@ in modern web applications!
|
|
78
78
|
``` erb
|
79
79
|
<head>
|
80
80
|
<title>some title</title>
|
81
|
-
<%=
|
81
|
+
<%= Gon::Base.render_data %>
|
82
82
|
<!-- include your action js code -->
|
83
83
|
...
|
84
84
|
```
|
85
85
|
|
86
|
-
For rails
|
86
|
+
For rails 3:
|
87
87
|
``` erb
|
88
|
-
<%=
|
88
|
+
<%= include_gon %>
|
89
89
|
...
|
90
90
|
```
|
91
91
|
|
92
92
|
|
93
93
|
|
94
94
|
You can pass some [options](https://github.com/gazay/gon/wiki/Options)
|
95
|
-
to `
|
95
|
+
to `render_data` method.
|
96
96
|
|
97
97
|
You put something like this in the action of your controller:
|
98
98
|
|
@@ -109,7 +109,7 @@ gon.your_hash = @your_hash
|
|
109
109
|
gon.all_variables # > {:your_int => 123, :your_other_int => 468, :your_array => [1, 2, 123], :your_hash => {'a' => 1, 'b' => 2}}
|
110
110
|
gon.your_array # > [1, 2, 123]
|
111
111
|
|
112
|
-
gon.clear # gon.all_variables now is {}
|
112
|
+
# gon.clear # gon.all_variables now is {}
|
113
113
|
```
|
114
114
|
|
115
115
|
Access the variables from your JavaScript file:
|
data/Rakefile
CHANGED
data/gon.gemspec
CHANGED
data/lib/gon.rb
CHANGED
@@ -36,7 +36,7 @@ class Gon
|
|
36
36
|
def method_missing(method, *args, &block)
|
37
37
|
if method.to_s =~ /=$/
|
38
38
|
if public_method_name?(method)
|
39
|
-
raise
|
39
|
+
raise "You can't use Gon public methods for storing data: #{method}"
|
40
40
|
end
|
41
41
|
if self == Gon && !current_gon
|
42
42
|
raise 'Assign request-specific gon variables only through `gon` helper, not through Gon constant'
|
data/lib/gon/base.rb
CHANGED
@@ -23,7 +23,7 @@ class Gon
|
|
23
23
|
|
24
24
|
script = formatted_data(_o)
|
25
25
|
script = Gon::Escaper.escape_unicode(script)
|
26
|
-
script = Gon::Escaper.javascript_tag(script, _o.type, _o.cdata, _o.nonce) if _o.
|
26
|
+
script = Gon::Escaper.javascript_tag(script, _o.type, _o.cdata, _o.nonce) if _o.need_tag
|
27
27
|
|
28
28
|
script.html_safe
|
29
29
|
end
|
@@ -36,9 +36,8 @@ class Gon
|
|
36
36
|
VALID_OPTION_DEFAULTS.each do |opt_name, default|
|
37
37
|
_o.send("#{opt_name}=", options.fetch(opt_name, default))
|
38
38
|
end
|
39
|
-
_o.watch
|
40
|
-
_o.
|
41
|
-
_o.cameled = _o.camel_case
|
39
|
+
_o.watch = options[:watch] || !Gon.watch.all_variables.empty?
|
40
|
+
_o.cameled = _o.camel_case
|
42
41
|
|
43
42
|
_o
|
44
43
|
end
|
data/lib/gon/helpers.rb
CHANGED
data/lib/gon/jbuilder.rb
CHANGED
@@ -24,7 +24,7 @@ class Gon
|
|
24
24
|
|
25
25
|
def valid_options?(options, global)
|
26
26
|
if global && !options[:template]
|
27
|
-
raise 'You should provide :template when use
|
27
|
+
raise 'You should provide :template when use jbuilder with global variables'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
data/lib/gon/jbuilder/parser.rb
CHANGED
@@ -3,13 +3,13 @@ class Gon
|
|
3
3
|
class Parser
|
4
4
|
include ::ActionView::Helpers
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :template_location, :controller, :_controller_name, :locals
|
7
7
|
|
8
8
|
def initialize(parse_params)
|
9
|
-
@
|
10
|
-
@controller
|
11
|
-
@_controller_name
|
12
|
-
@locals
|
9
|
+
@template_location = parse_params[:template_path]
|
10
|
+
@controller = parse_params[:controller]
|
11
|
+
@_controller_name = parse_params[:controller_name]
|
12
|
+
@locals = parse_params[:locals] || {}
|
13
13
|
end
|
14
14
|
|
15
15
|
def parse!
|
@@ -19,7 +19,7 @@ class Gon
|
|
19
19
|
locals['__controller'] = controller
|
20
20
|
wrap_locals_in_methods locals
|
21
21
|
|
22
|
-
partials = find_partials(File.readlines(
|
22
|
+
partials = find_partials(File.readlines(template_location))
|
23
23
|
source = partials.join('')
|
24
24
|
|
25
25
|
parse_source source, controller
|
data/lib/gon/request.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
class Gon
|
2
2
|
class Request
|
3
|
+
attr_reader :env
|
4
|
+
attr_accessor :id
|
5
|
+
|
3
6
|
def initialize(environment)
|
4
|
-
@
|
7
|
+
@env = environment
|
5
8
|
@gon = {}
|
6
9
|
end
|
7
10
|
|
8
|
-
def env
|
9
|
-
@request_env
|
10
|
-
end
|
11
|
-
|
12
|
-
def id
|
13
|
-
@request_id
|
14
|
-
end
|
15
|
-
|
16
|
-
def id=(request_id)
|
17
|
-
@request_id = request_id
|
18
|
-
end
|
19
|
-
|
20
11
|
def gon
|
21
12
|
@gon
|
22
13
|
end
|
data/lib/gon/version.rb
CHANGED
data/spec/gon/basic_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Gon do
|
4
2
|
|
5
3
|
before(:each) do
|
@@ -97,33 +95,26 @@ describe Gon do
|
|
97
95
|
|
98
96
|
it 'outputs correct js with an integer' do
|
99
97
|
Gon.int = 1
|
100
|
-
expect(@base.include_gon).to eq(
|
101
|
-
|
102
|
-
|
103
|
-
'gon.int=1;' +
|
104
|
-
"\n//]]>\n" +
|
105
|
-
'</script>')
|
98
|
+
expect(@base.include_gon).to eq(wrap_script(
|
99
|
+
'window.gon={};' +
|
100
|
+
'gon.int=1;'))
|
106
101
|
end
|
107
102
|
|
108
103
|
it 'outputs correct js with a string' do
|
109
104
|
Gon.str = %q(a'b"c)
|
110
|
-
expect(@base.include_gon).to eq(
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
"\n//]]>\n" +
|
115
|
-
'</script>')
|
105
|
+
expect(@base.include_gon).to eq(wrap_script(
|
106
|
+
'window.gon={};' +
|
107
|
+
%q(gon.str="a'b\"c";))
|
108
|
+
)
|
116
109
|
end
|
117
110
|
|
118
111
|
it 'outputs correct js with a script string' do
|
119
112
|
Gon.str = %q(</script><script>alert('!')</script>)
|
120
113
|
escaped_str = "\\u003c/script\\u003e\\u003cscript\\u003ealert('!')\\u003c/script\\u003e"
|
121
|
-
expect(@base.include_gon).to eq(
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
"\n//]]>\n" +
|
126
|
-
'</script>')
|
114
|
+
expect(@base.include_gon).to eq(wrap_script(
|
115
|
+
'window.gon={};' +
|
116
|
+
%Q(gon.str="#{escaped_str}";))
|
117
|
+
)
|
127
118
|
end
|
128
119
|
|
129
120
|
it 'outputs correct js with an integer and type' do
|
@@ -138,49 +129,33 @@ describe Gon do
|
|
138
129
|
|
139
130
|
it 'outputs correct js with an integer, camel-case and namespace' do
|
140
131
|
Gon.int_cased = 1
|
141
|
-
expect(@base.include_gon(camel_case: true, namespace: 'camel_cased')).to eq(
|
142
|
-
'
|
143
|
-
|
144
|
-
'window.camel_cased={};' +
|
145
|
-
'camel_cased.intCased=1;' +
|
146
|
-
"\n//]]>\n" +
|
147
|
-
'</script>'
|
132
|
+
expect(@base.include_gon(camel_case: true, namespace: 'camel_cased')).to eq(
|
133
|
+
wrap_script('window.camel_cased={};' +
|
134
|
+
'camel_cased.intCased=1;')
|
148
135
|
)
|
149
136
|
end
|
150
137
|
|
151
138
|
it 'outputs correct js with camel_depth = :recursive' do
|
152
139
|
Gon.test_hash = { test_depth_one: { test_depth_two: 1 } }
|
153
|
-
expect(@base.include_gon(camel_case: true, camel_depth: :recursive)).to eq(
|
154
|
-
'
|
155
|
-
"
|
156
|
-
'window.gon={};' +
|
157
|
-
'gon.testHash={"testDepthOne":{"testDepthTwo":1}};' +
|
158
|
-
"\n//]]>\n" +
|
159
|
-
'</script>'
|
140
|
+
expect(@base.include_gon(camel_case: true, camel_depth: :recursive)).to eq(
|
141
|
+
wrap_script('window.gon={};' +
|
142
|
+
'gon.testHash={"testDepthOne":{"testDepthTwo":1}};')
|
160
143
|
)
|
161
144
|
end
|
162
145
|
|
163
146
|
it 'outputs correct js with camel_depth = 2' do
|
164
147
|
Gon.test_hash = { test_depth_one: { test_depth_two: 1 } }
|
165
|
-
expect(@base.include_gon(camel_case: true, camel_depth: 2)).to eq(
|
166
|
-
'
|
167
|
-
"
|
168
|
-
'window.gon={};' +
|
169
|
-
'gon.testHash={"testDepthOne":{"test_depth_two":1}};' +
|
170
|
-
"\n//]]>\n" +
|
171
|
-
'</script>'
|
148
|
+
expect(@base.include_gon(camel_case: true, camel_depth: 2)).to eq(
|
149
|
+
wrap_script('window.gon={};' +
|
150
|
+
'gon.testHash={"testDepthOne":{"test_depth_two":1}};')
|
172
151
|
)
|
173
152
|
end
|
174
153
|
|
175
154
|
it 'outputs correct js for an array with camel_depth = :recursive' do
|
176
155
|
Gon.test_hash = { test_depth_one: [{ test_depth_two: 1 }, { test_depth_two: 2 }] }
|
177
156
|
expect(@base.include_gon(camel_case: true, camel_depth: :recursive)).to eq( \
|
178
|
-
'
|
179
|
-
"
|
180
|
-
'window.gon={};' +
|
181
|
-
'gon.testHash={"testDepthOne":[{"testDepthTwo":1},{"testDepthTwo":2}]};' +
|
182
|
-
"\n//]]>\n" +
|
183
|
-
'</script>'
|
157
|
+
wrap_script('window.gon={};' +
|
158
|
+
'gon.testHash={"testDepthOne":[{"testDepthTwo":1},{"testDepthTwo":2}]};')
|
184
159
|
)
|
185
160
|
end
|
186
161
|
|
@@ -217,44 +192,25 @@ describe Gon do
|
|
217
192
|
|
218
193
|
it 'outputs correct js without cdata, without type, gon init and an integer' do
|
219
194
|
Gon.int = 1
|
220
|
-
expect(@base.include_gon(cdata: false, type: false)).to eq(
|
221
|
-
|
195
|
+
expect(@base.include_gon(cdata: false, type: false)).to eq(
|
196
|
+
wrap_script(
|
222
197
|
"\n" +
|
223
198
|
'window.gon={};' +
|
224
199
|
'gon.int=1;' +
|
225
|
-
"\n"
|
226
|
-
'</script>'
|
200
|
+
"\n", false)
|
227
201
|
)
|
228
202
|
end
|
229
203
|
|
230
204
|
it 'outputs correct js with type text/javascript' do
|
231
|
-
expect(@base.include_gon(need_type: true, init: true)).to eq(
|
232
|
-
'<script>' +
|
233
|
-
"\n//<![CDATA[\n" +
|
234
|
-
'window.gon={};'\
|
235
|
-
"\n//]]>\n" +
|
236
|
-
'</script>'
|
237
|
-
)
|
205
|
+
expect(@base.include_gon(need_type: true, init: true)).to eq(wrap_script('window.gon={};'))
|
238
206
|
end
|
239
207
|
|
240
208
|
it 'outputs correct js with namespace check' do
|
241
|
-
expect(@base.include_gon(namespace_check: true)).to eq(
|
242
|
-
'<script>' +
|
243
|
-
"\n//<![CDATA[\n" +
|
244
|
-
'window.gon=window.gon||{};'\
|
245
|
-
"\n//]]>\n" +
|
246
|
-
'</script>'
|
247
|
-
)
|
209
|
+
expect(@base.include_gon(namespace_check: true)).to eq(wrap_script('window.gon=window.gon||{};'))
|
248
210
|
end
|
249
211
|
|
250
212
|
it 'outputs correct js without namespace check' do
|
251
|
-
expect(@base.include_gon(namespace_check: false)).to eq(
|
252
|
-
'<script>' +
|
253
|
-
"\n//<![CDATA[\n" +
|
254
|
-
'window.gon={};'\
|
255
|
-
"\n//]]>\n" +
|
256
|
-
'</script>'
|
257
|
-
)
|
213
|
+
expect(@base.include_gon(namespace_check: false)).to eq(wrap_script('window.gon={};'))
|
258
214
|
end
|
259
215
|
|
260
216
|
context "without a current_gon instance" do
|
@@ -273,18 +229,11 @@ describe Gon do
|
|
273
229
|
end
|
274
230
|
|
275
231
|
it 'outputs correct js with init' do
|
276
|
-
expect(@base.include_gon(init: true)).to eq(
|
277
|
-
'<script>' +
|
278
|
-
"\n//<![CDATA[\n" +
|
279
|
-
'window.gon={};'\
|
280
|
-
"\n//]]>\n" +
|
281
|
-
'</script>'
|
282
|
-
)
|
232
|
+
expect(@base.include_gon(init: true)).to eq(wrap_script('window.gon={};'))
|
283
233
|
end
|
284
234
|
|
285
235
|
end
|
286
236
|
|
287
|
-
|
288
237
|
end
|
289
238
|
|
290
239
|
describe '#include_gon_amd' do
|
@@ -336,16 +285,8 @@ describe Gon do
|
|
336
285
|
|
337
286
|
let(:controller) { ActionController::Base.new }
|
338
287
|
|
339
|
-
it 'should be able to handle
|
340
|
-
|
341
|
-
allow(Gon).to receive(:constants) { constants_as_strings }
|
342
|
-
expect { Gon.rabl :template => 'spec/test_data/sample.rabl', :controller => controller }.not_to raise_error
|
343
|
-
expect { Gon.jbuilder :template => 'spec/test_data/sample.json.jbuilder', :controller => controller }.not_to raise_error
|
344
|
-
end
|
345
|
-
|
346
|
-
it 'should be able to handle ruby 1.9+ style constants array (symbols)' do
|
347
|
-
constants_as_symbols = Gon.constants.map(&:to_sym)
|
348
|
-
allow(Gon).to receive(:constants) { constants_as_symbols }
|
288
|
+
it 'should be able to handle constants array (symbols)' do
|
289
|
+
allow(Gon).to receive(:constants) { Gon.constants }
|
349
290
|
expect { Gon.rabl :template => 'spec/test_data/sample.rabl', :controller => controller }.not_to raise_error
|
350
291
|
expect { Gon.jbuilder :template => 'spec/test_data/sample.json.jbuilder', :controller => controller }.not_to raise_error
|
351
292
|
end
|
data/spec/gon/global_spec.rb
CHANGED
data/spec/gon/jbuilder_spec.rb
CHANGED
data/spec/gon/templates_spec.rb
CHANGED
data/spec/gon/thread_spec.rb
CHANGED
data/spec/gon/watch_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Gon::Watch do
|
4
2
|
|
5
3
|
let(:controller) { ActionController::Base.new }
|
@@ -13,7 +11,7 @@ describe Gon::Watch do
|
|
13
11
|
env['REQUEST_METHOD'] = 'GET'
|
14
12
|
|
15
13
|
Gon::Watch.clear
|
16
|
-
Gon.send(:current_gon).instance_variable_set(:@
|
14
|
+
Gon.send(:current_gon).instance_variable_set(:@env, env)
|
17
15
|
Gon.send(:current_gon).env['action_controller.instance'] = controller
|
18
16
|
Gon.clear
|
19
17
|
end
|
@@ -45,7 +43,7 @@ describe Gon::Watch do
|
|
45
43
|
|
46
44
|
describe 'Render concrete variable' do
|
47
45
|
before do
|
48
|
-
env = Gon.send(:current_gon).
|
46
|
+
env = Gon.send(:current_gon).env
|
49
47
|
env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
50
48
|
|
51
49
|
allow(controller).to receive_messages(request: ActionDispatch::Request.new(env))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gazay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
description: If you need to send some data to your js files and you don't want to
|
154
168
|
do this with long way trough views and parsing - use this force!
|
155
169
|
email:
|
@@ -226,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
240
|
version: '0'
|
227
241
|
requirements: []
|
228
242
|
rubyforge_project:
|
229
|
-
rubygems_version: 2.
|
243
|
+
rubygems_version: 2.5.1
|
230
244
|
signing_key:
|
231
245
|
specification_version: 4
|
232
246
|
summary: Get your Rails variables in your JS
|