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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49bbd37ca002bfe5ab03c2111b7c6635620f3342
4
- data.tar.gz: 0a29853548280edadca2e8ed3b0ba1e939ad6596
3
+ metadata.gz: 9d24de7434f197bf9f86ea9ef17bbcf9ec585647
4
+ data.tar.gz: 49a264791c39e669f5364b469c6c9c119372b504
5
5
  SHA512:
6
- metadata.gz: 86a60a2c6136688ef3852c3d73a58829eb13b9ee5f7e950df9791487ae8e33e17b103db1eed5385fd132506cc658c073f675ee770de583e616d9d335e8ad0bb2
7
- data.tar.gz: 057fe2177ded2db7b2cd6038e01c0759e9ca5ec648f186ff8d16443c2274620243c78545f6fd7dbfee4162f15acaef75c4ea041e5f7f25f8276798ef258d4da3
6
+ metadata.gz: f1f121380839a33259810a5c1a2e7a4a149b91521b6d7c9d6b4b5742bd02977ee33aec47e43f31c78adeabb1ba748f20fea0a786819d84ac6c6809e27c376d6d
7
+ data.tar.gz: 65d68f8c2e182d32be8191f164b86917bf33d8d08f16fddceab7361acd0a3afe894933014cdc35296686b990bc0e7648f23268fe1d376f6f42c84fc70def1d99
@@ -3,12 +3,15 @@ sudo: false
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.6
7
- - 2.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-2015 gazay
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://secure.travis-ci.org/gazay/gon.png)](http://travis-ci.org/gazay/gon) [![CodeClimate](https://codeclimate.com/github/gazay/gon/badges/gpa.svg)](https://codeclimate.com/github/gazay/gon)
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
- <%= include_gon %>
81
+ <%= Gon::Base.render_data %>
82
82
  <!-- include your action js code -->
83
83
  ...
84
84
  ```
85
85
 
86
- For rails 4:
86
+ For rails 3:
87
87
  ``` erb
88
- <%= Gon::Base.render_data %>
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 `include_gon` method.
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
@@ -6,5 +6,5 @@ task :default => :spec
6
6
 
7
7
  require 'rspec/core/rake_task'
8
8
  RSpec::Core::RakeTask.new do |t|
9
- t.rspec_opts = ["--color", '--format doc']
9
+ t.rspec_opts = ["--color", '--format doc', '--require spec_helper']
10
10
  end
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'jbuilder'
27
27
  s.add_development_dependency 'railties', '>= 3.0'
28
28
  s.add_development_dependency 'rake'
29
+ s.add_development_dependency 'pry'
29
30
  end
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 'You can\'t use Gon public methods for storing data'
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'
@@ -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.tag
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 = options[:watch] || !Gon.watch.all_variables.empty?
40
- _o.tag = _o.need_tag
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
@@ -29,7 +29,7 @@ class Gon
29
29
  module ControllerHelpers
30
30
  def gon
31
31
  if wrong_gon_request?
32
- gon_request = Request.new(env)
32
+ gon_request = Request.new(request.env)
33
33
  gon_request.id = gon_request_uuid
34
34
  RequestStore.store[:gon] = gon_request
35
35
  end
@@ -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 rabl with global variables'
27
+ raise 'You should provide :template when use jbuilder with global variables'
28
28
  end
29
29
  end
30
30
 
@@ -3,13 +3,13 @@ class Gon
3
3
  class Parser
4
4
  include ::ActionView::Helpers
5
5
 
6
- attr_accessor :template_path, :controller, :_controller_name, :locals
6
+ attr_accessor :template_location, :controller, :_controller_name, :locals
7
7
 
8
8
  def initialize(parse_params)
9
- @template_path = parse_params[:template_path]
10
- @controller = parse_params[:controller]
11
- @_controller_name = parse_params[:controller_name]
12
- @locals = parse_params[: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(template_path))
22
+ partials = find_partials(File.readlines(template_location))
23
23
  source = partials.join('')
24
24
 
25
25
  parse_source source, controller
@@ -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
- @request_env = environment
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
@@ -1,3 +1,3 @@
1
1
  class Gon
2
- VERSION = '6.0.1'
2
+ VERSION = '6.1.0'
3
3
  end
@@ -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('<script>' +
101
- "\n//<![CDATA[\n" +
102
- 'window.gon={};' +
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('<script>' +
111
- "\n//<![CDATA[\n" +
112
- 'window.gon={};' +
113
- %q(gon.str="a'b\"c";) +
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('<script>' +
122
- "\n//<![CDATA[\n" +
123
- 'window.gon={};' +
124
- %Q(gon.str="#{escaped_str}";) +
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
- '<script>' +
143
- "\n//<![CDATA[\n" +
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
- '<script>' +
155
- "\n//<![CDATA[\n" +
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
- '<script>' +
167
- "\n//<![CDATA[\n" +
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
- '<script>' +
179
- "\n//<![CDATA[\n" +
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
- '<script>' +
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 ruby 1.8.7 style constants array (strings)' do
340
- constants_as_strings = Gon.constants.map(&:to_s)
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
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Gon::Global do
4
2
 
5
3
  before(:each) do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Gon do
4
2
 
5
3
  describe '.jbuilder' do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Gon do
4
2
 
5
3
  before(:all) do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Gon do
4
2
 
5
3
  before(:all) do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Gon do
4
2
 
5
3
  describe '.template_path' do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  class GonTestWorker
4
2
  include Gon::ControllerHelpers
5
3
 
@@ -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(:@request_env, env)
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).instance_variable_get(:@request_env)
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.1
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: 2015-07-28 00:00:00.000000000 Z
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.4.5
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