gon 6.1.0 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9d24de7434f197bf9f86ea9ef17bbcf9ec585647
4
- data.tar.gz: 49a264791c39e669f5364b469c6c9c119372b504
2
+ SHA256:
3
+ metadata.gz: 3bdd0446070acfd94f0e8ef48b57eb1bfdf82179dca4cdd7a6e230d43ee9551b
4
+ data.tar.gz: 3dea439ff1cefa4edef65a9c39f2d0e505114140fcbf1a9effda085f04741e64
5
5
  SHA512:
6
- metadata.gz: f1f121380839a33259810a5c1a2e7a4a149b91521b6d7c9d6b4b5742bd02977ee33aec47e43f31c78adeabb1ba748f20fea0a786819d84ac6c6809e27c376d6d
7
- data.tar.gz: 65d68f8c2e182d32be8191f164b86917bf33d8d08f16fddceab7361acd0a3afe894933014cdc35296686b990bc0e7648f23268fe1d376f6f42c84fc70def1d99
6
+ metadata.gz: af0597738e9196231399b4c15e77358bb4e3e90cbfe26fefae9da4d70ae5c20982c15c424e34b37ed58cd05cf8e867f6756cfa83f8621eda301df266ab5ff251
7
+ data.tar.gz: 37a2e08e06f44c863bfce115e99c9628f798347b2db2579b491d38aa959b5e5ee076b9207ae02405e303b94c8952198becef9f2d24fce8f79bd7a0b5cf001339
@@ -0,0 +1 @@
1
+ tidelift: "rubygems/gon"
@@ -1,17 +1,14 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ env:
4
+ - "RABL_GEM=rabl"
5
+ - "RABL_GEM=rabl-rails"
6
+
3
7
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1
7
- - 2.2
8
- - 2.3.0
8
+ - 2.2.10
9
+ - 2.3.8
10
+ - 2.4.10
11
+ - 2.5.8
12
+ - 2.6.6
13
+ - 2.7.1
9
14
  - ruby-head
10
- - jruby-19mode # JRuby in 1.9 mode
11
- - rbx
12
- matrix:
13
- allow_failures:
14
- - rvm: rbx
15
- - rvm: ruby-head
16
- # uncomment this line if your project needs to run something other than `rake`:
17
- # script: bundle exec rspec spec
@@ -1,129 +1,264 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 6.0.1
4
-
5
- * Free dependencies
6
-
7
- ## 6.0.0
8
-
9
- * Refactoring
10
- * nonce option. Thanks to @joeljackson
11
- * Included rails url_helpers into jbuilder. Thanks to @razum2um
12
- * Welcome @takiy33 as contributor!
13
-
14
- ## 5.2.3
15
-
16
- * Coffescript implementation of watch.js. Thanks to @willcosgrove
17
- * unwatchAll function in watch.js. Thanks to @willcosgrove
18
-
19
- ## 5.2.2
20
-
21
- * add support for controller helper methods in jbuilder
22
-
23
- ## 5.2.1
24
-
25
- * fix for jbuilder module. Thanks to @jankovy
26
- * merge variable feature (for merge hash-like variables instead of overriding them). Thanks to @jalkoby
27
-
28
- ## 5.2.0
29
-
30
- * fix issue where include_gon would raise exception if the controller did not assign any gon variables. Thanks to @asalme
31
- * namespace_check option. Thanks to @tommyh
32
- * Only inject gon into ActionController::Base-like object in spec_helper. Thanks to @kevinoconnor7
33
- * AMD compatible version of including gon. Thanks to @vijoc
34
-
35
- ## 5.1.2
36
-
37
- * Clarifying helpers, dump gon#watch content to safe json before render. Thanks to @Strech
38
-
39
- ## 5.1.1
40
-
41
- * global_root option. Thanks to @rafaelliu
42
- * MultiJson support. Thanks to @Strech
43
-
44
- ## 5.1.0
45
-
46
- * Many fixes https://github.com/gazay/gon/compare/91845f3f0debd0cb8fa569aad65f5dc40a7e28e5...8dc7400fbb83ba5a086bd36c76342a393690d53f
47
- * Thanks to @Silex, @kilefritz, @irobayna, @kyrylo, @randoum, @jackquack, @tuvistavie, @Strech for awesome commits and help!
48
-
49
- ## 5.0.4
50
-
51
- * Fix check for get and assign variables for Gon.global
52
-
53
- ## 5.0.3
54
-
55
- * Revert changes in gemspec
56
-
57
- ## 5.0.2
58
-
59
- * Fix issue when there is no gon object for current thread and
60
- rendering include_gon (#108 part) (wasn't fixed) (@gregmolnar)
61
-
62
- ## 5.0.1
63
-
64
- * Fix issue when there is no gon object for current thread and
65
- rendering include_gon (#108 part)
66
-
67
- ## 5.0.0
68
-
69
- * Gon is threadsafe now! (@razum2um)
70
- * Camelcasing with depth (@MaxSchmeling)
71
- * Optional CDATA and style refactoring (@torbjon)
72
- * jBuilder supports not only String and Hash types of locals
73
- (@steakchaser)
74
- * Using ActionDispatch::Request#uuid instead of
75
- ActionDispatch::Request#id (@sharshenov)
76
-
77
- ## 4.1.1
78
-
79
- * Fixed critical XSS vulnerability https://github.com/gazay/gon/issues/84 (@vadimr & @Hebo)
80
-
81
- ## 4.1.0
82
-
83
- * Refactored script tag generation (@toothrot)
84
- * Stop support for MRI 1.8.7
85
- * Added rabl-rails support (@jtherrell)
86
- * Accepting locals in jbuilder templates
87
-
88
- ## 4.0.3
89
-
90
- * Added new method `Gon#push` for assign variables through Hash-like
91
- objects (@topdev)
92
- * Fixes for 1.8.7 compatibility.
93
- * !!!IMPORTANT!!! Last version with compatibility for MRI 1.8.7
94
-
95
- ## 4.0.2
96
-
97
- * Fixed gon.watch in JS without callback and options
98
-
99
- ## 4.0.1
100
-
101
- * Removed BlankSlate requirement *Peter Schröder*
102
- * Gon#set_variable and Gon#get_variable moved to public scope
103
- * Added option :locals to gon.rabl functionality
104
-
105
- ## 4.0.0
106
-
107
- * Added gon.watch functionality (thanks to @brainopia and @kossnocorp)
108
- * Compatibility with jbuilder paths for partial! method
109
- * Fixed some bugs
110
- * Little bit refactoring - Gon now is a class
111
-
112
- ## 3.0.3
113
-
114
- * Include ActionView::Helpers into Gon::JBuilder
115
- * Added init option (@torbjon)
116
-
117
- ## 3.0.2
118
-
119
- * Added need_tag option (@afa)
120
-
121
- ## 3.0.0
122
-
123
- * Almost all code refactored
124
- * Added Gon.global for using gon everywhere
125
- * Included ActionView::Helpers into Rabl::Engine
126
-
127
- ## 2.3.0
128
-
129
- * Don't really remember what was before this version
3
+ ## [Unreleased]
4
+
5
+ ## [6.4.0] - 2020-09-18
6
+ ### Security
7
+ - CVE-2020-25739: Enforce HTML entities escaping in gon output
8
+
9
+ ## [6.3.2] - 2019-11-18
10
+ ### Security
11
+ - Restrict possibility of vulnerable i18n legacy verision (0.3.6.pre)
12
+ installation
13
+
14
+ ## [6.3.1] - 2019-11-18
15
+ ### Changed
16
+ - ActionView::Base and ActionController::Base should be loaded inside
17
+ ActiveSupport.on_load hook. Thanks to @amatsuda
18
+ - Require Ruby >= 2.2.2 (activesupport). Thanks to @nicolasleger
19
+ - Update old_rails.rb to reflect GonHelpers -> ControllerHelpers name change.
20
+ Thanks to @etipton
21
+
22
+ ## [6.2.1] - 2018-07-11
23
+ ### Changed
24
+ - Update README: correct spelling mistake. Thanks to @EdwardBetts
25
+ - Autoload test classes only in test env. Thanks to @wilddima
26
+
27
+ ### Fixed
28
+ - Fix keys cache. Thanks to @ertrzyiks
29
+ - fixing tests by running with rabl and rabl-rails separately. Thanks to
30
+ @dsalahutdinov
31
+
32
+ ## [6.2.0] - 2017-10-04
33
+ ### Added
34
+ - Introduce keys cache. Thanks to @vlazar
35
+ - Add possibleErrorCallback to watch params. Thanks to @etagwerker
36
+
37
+ ### Changed
38
+ - Update readme with PhoenixGon hex link. Thanks to @khusnetdinov
39
+ - Fix code highlighting in README. Thanks to @ojab
40
+ - Refactoring: use attr_reader
41
+
42
+ ### Removed
43
+ - Remove unnecessary json dependency.
44
+ - Remove rubysl and rubinius-developer_tools gem.
45
+
46
+ ## [6.1.0] - 2016-07-11
47
+ ### Deprecated
48
+ - env is deprecated and will be removed from Rails 5.0. Thanks to @dlupu
49
+
50
+ ### Fixed
51
+ - fix merging routes bug. Thanks to @strikyflo
52
+ - Show what method was used in public methods error.
53
+
54
+ ### Changed
55
+ - Use 'need_tag' as option name to prevent calling 'tag' method. Thanks to
56
+ @june29
57
+ - Update README; comment out gon.clear from sample code. Thanks to
58
+ @speee-nakajima
59
+ - Update README; Replace the include_gon method with render_data method.
60
+ - Refactoring: use attr_accessor method.
61
+ - Refactoring: use attr_reader method.
62
+
63
+ ## [6.0.1] - 2015-07-22
64
+ ### Changed
65
+ - Free dependencies
66
+
67
+ ## [6.0.0] - 2015-07-22
68
+ ### Added
69
+ - nonce option. Thanks to @joeljackson
70
+
71
+ ### Changed
72
+ - Refactoring
73
+ - Included rails url_helpers into jbuilder. Thanks to @razum2um
74
+
75
+ ## [5.2.3] - 2014-11-03
76
+ ### Added
77
+ - Coffescript implementation of watch.js. Thanks to @willcosgrove
78
+ - unwatchAll function in watch.js. Thanks to @willcosgrove
79
+
80
+ ## [5.2.2] - 2014-10-31
81
+ ### Added
82
+ - support for controller helper methods in jbuilder
83
+
84
+ ## [5.2.1] - 2014-10-28
85
+ ### Added
86
+ - merge variable feature (for merge hash-like variables instead of overriding
87
+ them). Thanks to @jalkoby
88
+
89
+ ### Fixed
90
+ - fix for jbuilder module. Thanks to @jankovy
91
+
92
+ ## [5.2.0] - 2014-08-26
93
+ ### Added
94
+ - namespace_check option. Thanks to @tommyh
95
+ - AMD compatible version of including gon. Thanks to @vijoc
96
+
97
+ ### Changed
98
+ - Only inject gon into ActionController::Base-like object in spec_helper. Thanks
99
+ to @kevinoconnor7
100
+
101
+ ### Fixed
102
+ - fix issue where include_gon would raise exception if the controller did not
103
+ assign any gon variables. Thanks to @asalme
104
+
105
+ ## [5.1.2] - 2014-07-22
106
+ ### Changed
107
+ - Clarifying helpers, dump gon#watch content to safe json before render. Thanks
108
+ to @Strech
109
+
110
+ ## [5.1.1] - 2014-07-17
111
+ ### Added
112
+ - global_root option. Thanks to @rafaelliu
113
+ - MultiJson support. Thanks to @Strech
114
+
115
+ ## [5.1.0] - 2014-06-29
116
+ ### Fixed
117
+ - Many fixes. Thanks to @Silex, @kilefritz, @irobayna, @kyrylo, @randoum,
118
+ @jackquack, @tuvistavie, @Strech for awesome commits and help!
119
+
120
+ ## [5.0.4] - 2014-02-13
121
+ ### Fixed
122
+ - Fix check for get and assign variables for Gon.global
123
+
124
+ ## [5.0.3] - 2014-02-12
125
+ ### Removed
126
+ - Revert changes in gemspec
127
+
128
+ ## [5.0.2] - 2014-02-12
129
+ ### Fixed
130
+ - Fix issue when there is no gon object for current thread and rendering
131
+ include_gon (#108 part) (wasn't fixed) (@gregmolnar)
132
+
133
+ ## [5.0.1] - 2013-12-30
134
+ ### Fixed
135
+ - Fix issue when there is no gon object for current thread and rendering
136
+ include_gon (#108 part)
137
+
138
+ ## [5.0.0] - 2013-12-26
139
+ ### Changed
140
+ - Gon is threadsafe now! (@razum2um)
141
+ - Camelcasing with depth (@MaxSchmeling)
142
+ - Optional CDATA and style refactoring (@torbjon)
143
+ - jBuilder supports not only String and Hash types of locals (@steakchaser)
144
+ - Using ActionDispatch::Request#uuid instead of ActionDispatch::Request#id
145
+ (@sharshenov)
146
+
147
+ ## [4.1.1] - 2013-06-04
148
+ ### Fixed
149
+ - Fixed critical XSS vulnerability https://github.com/gazay/gon/issues/84
150
+ (@vadimr & @Hebo)
151
+
152
+ ## [4.1.0] - 2013-04-14
153
+ ### Added
154
+ - rabl-rails support (@jtherrell)
155
+
156
+ ### Changed
157
+ - Refactored script tag generation (@toothrot)
158
+ - Stop support for MRI 1.8.7
159
+ - Accepting locals in jbuilder templates
160
+
161
+ ## [4.0.3] - 2013-04-14
162
+ !!!IMPORTANT!!! Last version with compatibility for MRI 1.8.7
163
+
164
+ ### Added
165
+ - new method `Gon#push` for assign variables through Hash-like objects (@topdev)
166
+ ### Changed
167
+ - Fixes for 1.8.7 compatibility.
168
+
169
+ ## [4.0.2] - 2012-12-17
170
+ ### Fixed
171
+ - Fixed gon.watch in JS without callback and options
172
+
173
+ ## [4.0.1] - 2012-10-25
174
+ ### Added
175
+ - option :locals to gon.rabl functionality
176
+
177
+ ### Changed
178
+ - Gon#set_variable and Gon#get_variable moved to public scope
179
+
180
+ ### Removed
181
+ - BlankSlate requirement (@phoet)
182
+
183
+ ## [4.0.0] - 2012-07-23
184
+ ### Added
185
+ - gon.watch functionality (thanks to @brainopia and @kossnocorp)
186
+ - Compatibility with jbuilder paths for partial! method
187
+
188
+ ### Changed
189
+ - Little bit refactoring - Gon now is a class
190
+
191
+ ### Fixed
192
+ - Fixed some bugs
193
+
194
+ ## [3.0.5] - 2012-06-22
195
+ ### Added
196
+ - type text/javascript option (@torbjon)
197
+
198
+ ### Changed
199
+ - A litlle bit refactoring
200
+ - Made compatible with active support json encoding for escaping script tags
201
+
202
+ ### Fixed
203
+ - bug for init option
204
+ - clear if init true (@torbjon)
205
+
206
+ ## [3.0.4] - 2012-06-02
207
+ ### Fixed
208
+ - Fix bug with gon clear with global variables, bump version
209
+
210
+ ## [3.0.3] - 2012-05-22
211
+ ### Added
212
+ - init option (@torbjon)
213
+
214
+ ### Changed
215
+ - Include ActionView::Helpers into Gon::JBuilder
216
+
217
+ ## [3.0.2] - 2012-04-28
218
+ ### Added
219
+ - need_tag option (@afa)
220
+
221
+ ## [3.0.0] - 2012-04-17
222
+ ### Added
223
+ - Added Gon.global for using gon everywhere
224
+
225
+ ### Changed
226
+ - Almost all code refactored
227
+ - Included ActionView::Helpers into Rabl::Engine
228
+
229
+ ## [2.3.0] - 2012-04-09
230
+ ### Changed
231
+ - Don't really remember what was before this version
232
+
233
+ [Unreleased]: https://github.com/gazay/gon/compare/v6.3.2...master
234
+ [6.3.2]: https://github.com/gazay/gon/compare/v6.3.1...v6.3.2
235
+ [6.3.1]: https://github.com/gazay/gon/compare/v6.2.1...v6.3.1
236
+ [6.2.1]: https://github.com/gazay/gon/compare/v6.2.0...v6.2.1
237
+ [6.2.0]: https://github.com/gazay/gon/compare/v6.1.0...v6.2.0
238
+ [6.1.0]: https://github.com/gazay/gon/compare/v6.0.1...v6.1.0
239
+ [6.0.1]: https://github.com/gazay/gon/compare/v6.0.0...v6.0.1
240
+ [6.0.0]: https://github.com/gazay/gon/compare/v5.2.3...v6.0.0
241
+ [5.2.3]: https://github.com/gazay/gon/compare/v5.2.2...v5.2.3
242
+ [5.2.2]: https://github.com/gazay/gon/compare/v5.2.1...v5.2.2
243
+ [5.2.1]: https://github.com/gazay/gon/compare/v5.2.0...v5.2.1
244
+ [5.2.0]: https://github.com/gazay/gon/compare/v5.1.2...v5.2.0
245
+ [5.1.2]: https://github.com/gazay/gon/compare/v5.1.1...v5.1.2
246
+ [5.1.1]: https://github.com/gazay/gon/compare/v5.1.0...v5.1.1
247
+ [5.1.0]: https://github.com/gazay/gon/compare/v5.0.4...v5.1.0
248
+ [5.0.4]: https://github.com/gazay/gon/compare/v5.0.3...v5.0.4
249
+ [5.0.3]: https://github.com/gazay/gon/compare/v5.0.2...v5.0.3
250
+ [5.0.2]: https://github.com/gazay/gon/compare/v5.0.1...v5.0.2
251
+ [5.0.1]: https://github.com/gazay/gon/compare/v5.0.0...v5.0.1
252
+ [5.0.0]: https://github.com/gazay/gon/compare/v4.1.1...v5.0.0
253
+ [4.1.1]: https://github.com/gazay/gon/compare/v4.1.0...v4.1.1
254
+ [4.1.0]: https://github.com/gazay/gon/compare/v4.0.3...v4.1.0
255
+ [4.0.3]: https://github.com/gazay/gon/compare/v4.0.2...v4.0.3
256
+ [4.0.2]: https://github.com/gazay/gon/compare/v4.0.1...v4.0.2
257
+ [4.0.1]: https://github.com/gazay/gon/compare/v4.0.0...v4.0.1
258
+ [4.0.0]: https://github.com/gazay/gon/compare/v3.0.5...v4.0.0
259
+ [3.0.5]: https://github.com/gazay/gon/compare/v3.0.4...v3.0.5
260
+ [3.0.4]: https://github.com/gazay/gon/compare/v3.0.3...v3.0.4
261
+ [3.0.3]: https://github.com/gazay/gon/compare/v3.0.2...v3.0.3
262
+ [3.0.2]: https://github.com/gazay/gon/compare/v3.0.0...v3.0.2
263
+ [3.0.0]: https://github.com/gazay/gon/compare/v2.3.0...v3.0.0
264
+ [2.3.0]: https://github.com/gazay/gon/releases/tag/v2.3.0
data/Gemfile CHANGED
@@ -1,9 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gon.gemspec
4
- gemspec
4
+ gem ENV['RABL_GEM'] || 'rabl'
5
5
 
6
- platforms :rbx do
7
- gem 'rubysl', '~> 2.0'
8
- gem 'rubinius-developer_tools'
9
- end
6
+ gemspec
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2011-2016 gazay
3
+ Copyright (c) 2011-2019 Alexey Gaziev
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
@@ -16,6 +16,8 @@ For Sinatra available [gon-sinatra](https://github.com/gazay/gon-sinatra).
16
16
 
17
17
  For .Net MVC available port [NGon](https://github.com/brooklynDev/NGon).
18
18
 
19
+ For elixir Phoenix available [PhoenixGon](https://github.com/khusnetdinov/phoenix_gon).
20
+
19
21
  <a href="https://evilmartians.com/?utm_source=gon">
20
22
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
21
23
  </a>
@@ -38,14 +40,14 @@ you might be doing something like this:
38
40
  that) - you just use data from this js - OK.
39
41
  4. You can use your data in your js
40
42
 
41
- And everytime when you need to send some data from action to js you do this.
43
+ And every time when you need to send some data from action to js you do this.
42
44
 
43
45
  With gon you configure it firstly - just put in layout one tag, and add
44
46
  gem line to your Gemfile and do the following:
45
47
 
46
48
  1. Write variables by
47
49
 
48
- ``` ruby
50
+ ``` ruby
49
51
  gon.variable_name = variable_value
50
52
 
51
53
  # or new syntax
@@ -55,13 +57,13 @@ gem line to your Gemfile and do the following:
55
57
  })
56
58
 
57
59
  gon.push(any_object) # any_object with respond_to? :each_pair
58
- ```
60
+ ```
59
61
 
60
62
  2. In your js you get this by
61
63
 
62
- ``` js
64
+ ``` js
63
65
  gon.variable_name
64
- ```
66
+ ```
65
67
 
66
68
  3. profit?
67
69
 
@@ -235,3 +237,7 @@ Special thanks to @brainopia, @kossnocorp and @ai.
235
237
  ## License
236
238
 
237
239
  The MIT License
240
+
241
+ ## Security Contact
242
+
243
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
@@ -1,6 +1,6 @@
1
1
  gon._timers = {}
2
2
 
3
- gon.watch = (name, possibleOptions, possibleCallback) ->
3
+ gon.watch = (name, possibleOptions, possibleCallback, possibleErrorCallback) ->
4
4
  return unless $?
5
5
 
6
6
  if typeof possibleOptions == 'object'
@@ -10,9 +10,12 @@ gon.watch = (name, possibleOptions, possibleCallback) ->
10
10
  for key, value of possibleOptions
11
11
  options[key] = value
12
12
  callback = possibleCallback
13
+ errorCallback = possibleErrorCallback
13
14
  else
14
15
  options = gon.watchedVariables[name]
15
16
  callback = possibleOptions
17
+ errorCallback = possibleCallback
18
+
16
19
  performAjax = ->
17
20
  xhr = $.ajax
18
21
  type: options.type || 'GET'
@@ -21,7 +24,11 @@ gon.watch = (name, possibleOptions, possibleCallback) ->
21
24
  _method: options.method
22
25
  gon_return_variable: true
23
26
  gon_watched_variable: name
24
- xhr.done(callback)
27
+
28
+ if errorCallback
29
+ xhr.done(callback).fail(errorCallback);
30
+ else
31
+ xhr.done(callback)
25
32
 
26
33
  if options.interval
27
34
  timer = setInterval(performAjax, options.interval)
@@ -15,16 +15,17 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = '> 1.8.7'
19
- s.add_dependency 'actionpack', '>= 3.0'
18
+ s.required_ruby_version = '>= 2.2.0'
19
+ s.add_dependency 'actionpack', '>= 3.0.20'
20
+ s.add_dependency 'i18n', '>= 0.7'
20
21
  s.add_dependency 'request_store', '>= 1.0'
21
- s.add_dependency 'json'
22
22
  s.add_dependency 'multi_json'
23
23
  s.add_development_dependency 'rabl', '0.11.3'
24
24
  s.add_development_dependency 'rabl-rails'
25
25
  s.add_development_dependency 'rspec', '>= 3.0'
26
26
  s.add_development_dependency 'jbuilder'
27
- s.add_development_dependency 'railties', '>= 3.0'
27
+ s.add_development_dependency 'railties', '>= 3.0.20'
28
28
  s.add_development_dependency 'rake'
29
29
  s.add_development_dependency 'pry'
30
+ s.add_development_dependency 'pry-byebug'
30
31
  end
@@ -1,8 +1,8 @@
1
1
  // Generated by CoffeeScript 1.7.1
2
2
  gon._timers = {};
3
3
 
4
- gon.watch = function(name, possibleOptions, possibleCallback) {
5
- var callback, key, options, performAjax, timer, value, _base, _ref;
4
+ gon.watch = function(name, possibleOptions, possibleCallback, possibleErrorCallback) {
5
+ var callback, errorCallback, key, options, performAjax, timer, value, _base, _ref;
6
6
  if (typeof $ === "undefined" || $ === null) {
7
7
  return;
8
8
  }
@@ -18,9 +18,11 @@ gon.watch = function(name, possibleOptions, possibleCallback) {
18
18
  options[key] = value;
19
19
  }
20
20
  callback = possibleCallback;
21
+ errorCallback = possibleErrorCallback;
21
22
  } else {
22
23
  options = gon.watchedVariables[name];
23
24
  callback = possibleOptions;
25
+ errorCallback = possibleCallback;
24
26
  }
25
27
  performAjax = function() {
26
28
  var xhr;
@@ -33,7 +35,11 @@ gon.watch = function(name, possibleOptions, possibleCallback) {
33
35
  gon_watched_variable: name
34
36
  }
35
37
  });
36
- return xhr.done(callback);
38
+ if (errorCallback) {
39
+ return xhr.done(callback).fail(errorCallback);
40
+ } else {
41
+ return xhr.done(callback);
42
+ }
37
43
  };
38
44
  if (options.interval) {
39
45
  timer = setInterval(performAjax, options.interval);
@@ -50,7 +56,7 @@ gon.watch = function(name, possibleOptions, possibleCallback) {
50
56
  };
51
57
 
52
58
  gon.unwatch = function(name, fn) {
53
- var index, timer, _i, _len, _ref;
59
+ var _i, index, _len, _ref, timer;
54
60
  _ref = gon._timers[name];
55
61
  for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
56
62
  timer = _ref[index];
@@ -64,7 +70,7 @@ gon.unwatch = function(name, fn) {
64
70
  };
65
71
 
66
72
  gon.unwatchAll = function() {
67
- var timer, timers, variable, _i, _len, _ref;
73
+ var _i, _len, _ref, timer, timers, variable;
68
74
  _ref = gon._timers;
69
75
  for (variable in _ref) {
70
76
  timers = _ref[variable];
@@ -70,7 +70,7 @@ class Gon
70
70
  end
71
71
 
72
72
  def render_variable(_o, key, value)
73
- js_key = _o.cameled ? key.to_s.camelize(:lower) : key.to_s
73
+ js_key = convert_key(key, _o.cameled)
74
74
  if _o.amd
75
75
  "gon['#{js_key}']=#{to_json(value, _o.camel_depth)};"
76
76
  else
@@ -99,7 +99,7 @@ class Gon
99
99
  case value
100
100
  when Hash
101
101
  Hash[value.map { |k, v|
102
- [ k.to_s.camelize(:lower), convert_hash_keys(v, current_depth + 1, max_depth) ]
102
+ [ convert_key(k, true), convert_hash_keys(v, current_depth + 1, max_depth) ]
103
103
  }]
104
104
  when Enumerable
105
105
  value.map { |v| convert_hash_keys(v, current_depth + 1, max_depth) }
@@ -122,6 +122,11 @@ class Gon
122
122
  data.merge(Gon.all_variables)
123
123
  end
124
124
 
125
+ def convert_key(key, camelize)
126
+ cache = RequestStore.store[:gon_keys_cache] ||= {}
127
+ cache["#{key}_#{camelize}"] ||= camelize ? key.to_s.camelize(:lower) : key.to_s
128
+ end
129
+
125
130
  end
126
131
  end
127
132
  end
@@ -1,9 +1,10 @@
1
1
  require 'securerandom'
2
2
 
3
3
  class Gon
4
- module GonHelpers
4
+ module ControllerHelpers
5
5
  private
6
6
 
7
+ # override this since ActionDispatch::Request#uuid appears only in Rails 3.2.1
7
8
  def gon_request_uuid
8
9
  @gon_request_uuid ||= SecureRandom.uuid
9
10
  end
@@ -52,5 +52,9 @@ class Gon
52
52
  end
53
53
  end
54
54
 
55
- ActionView::Base.send :include, Gon::ViewHelpers
56
- ActionController::Base.send :include, Gon::ControllerHelpers
55
+ ActiveSupport.on_load :action_view do
56
+ ActionView::Base.send :include, Gon::ViewHelpers
57
+ end
58
+ ActiveSupport.on_load :action_controller do
59
+ ActionController::Base.send :include, Gon::ControllerHelpers
60
+ end
@@ -1,8 +1,23 @@
1
1
  class Gon
2
2
  module JsonDumper
3
+ # Taken from ERB::Util
4
+ JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
5
+ JSON_ESCAPE = {
6
+ "&" => '\u0026',
7
+ ">" => '\u003e',
8
+ "<" => '\u003c',
9
+ "\u2028" => '\u2028',
10
+ "\u2029" => '\u2029'
11
+ }
12
+
3
13
  def self.dump(object)
4
- MultiJson.dump object,
14
+ dumped_json = MultiJson.dump object,
5
15
  mode: :compat, escape_mode: :xss_safe, time_format: :ruby
16
+ escape(dumped_json)
17
+ end
18
+
19
+ def self.escape(json)
20
+ json.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
6
21
  end
7
22
  end
8
23
  end
@@ -1,6 +1,6 @@
1
1
  class Gon
2
2
  class Request
3
- attr_reader :env
3
+ attr_reader :env, :gon
4
4
  attr_accessor :id
5
5
 
6
6
  def initialize(environment)
@@ -8,10 +8,6 @@ class Gon
8
8
  @gon = {}
9
9
  end
10
10
 
11
- def gon
12
- @gon
13
- end
14
-
15
11
  def clear
16
12
  @gon = {}
17
13
  end
@@ -5,7 +5,7 @@ class Gon
5
5
 
6
6
  module ClassMethods
7
7
  module GonSession
8
- def process(*)
8
+ def process(*, **)
9
9
  # preload threadlocal & store controller instance
10
10
  if controller.is_a? ActionController::Base
11
11
  controller.gon
@@ -24,7 +24,7 @@ class Gon
24
24
  end
25
25
  end
26
26
 
27
- if defined?(ActionController::TestCase::Behavior)
27
+ if ENV['RAILS_ENV'] == 'test' && defined?(ActionController::TestCase::Behavior)
28
28
  ActionController::TestCase::Behavior.send :include, Gon::SpecHelper::Rails
29
29
  end
30
30
 
@@ -1,3 +1,3 @@
1
1
  class Gon
2
- VERSION = '6.1.0'
2
+ VERSION = '6.4.0'
3
3
  end
@@ -159,6 +159,16 @@ describe Gon do
159
159
  )
160
160
  end
161
161
 
162
+ it 'outputs correct key with camel_case option set alternately ' do
163
+ Gon.test_hash = 1
164
+ @base.include_gon(camel_case: true)
165
+
166
+ expect(@base.include_gon(camel_case: false)).to eq(
167
+ wrap_script('window.gon={};' +
168
+ 'gon.test_hash=1;')
169
+ )
170
+ end
171
+
162
172
  it 'outputs correct js with an integer and without tag' do
163
173
  Gon.int = 1
164
174
  expect(@base.include_gon(need_tag: false)).to eq( \
@@ -291,17 +301,4 @@ describe Gon do
291
301
  expect { Gon.jbuilder :template => 'spec/test_data/sample.json.jbuilder', :controller => controller }.not_to raise_error
292
302
  end
293
303
  end
294
-
295
- def request
296
- @request ||= double 'request', :env => {}
297
- end
298
-
299
- def wrap_script(content, cdata=true)
300
- script = "<script>"
301
- script << "\n//<![CDATA[\n" if cdata
302
- script << content
303
- script << "\n//]]>\n" if cdata
304
- script << '</script>'
305
- end
306
-
307
304
  end
@@ -143,13 +143,4 @@ describe Gon::Global do
143
143
  end
144
144
 
145
145
  end
146
-
147
- after(:all) do
148
- Gon.global.clear
149
- end
150
-
151
- def request
152
- @request ||= double 'request', :env => {}
153
- end
154
-
155
146
  end
@@ -1,9 +1,4 @@
1
1
  describe Gon do
2
-
3
- before(:all) do
4
- ensure_rabl_is_loaded
5
- end
6
-
7
2
  describe '.rabl' do
8
3
 
9
4
  before :each do
@@ -2,7 +2,7 @@ class GonTestWorker
2
2
  include Gon::ControllerHelpers
3
3
 
4
4
  def request
5
- @request ||= ActionDispatch::TestRequest.new
5
+ @request ||= ActionDispatch::TestRequest.create
6
6
  end
7
7
 
8
8
  def env
@@ -14,50 +14,6 @@ end
14
14
  require 'gon'
15
15
 
16
16
  require 'jbuilder'
17
- require 'rabl'
18
- require 'rabl-rails'
19
-
20
- # rabl has a conflict with rabl-rails as rabl-rails causes Rails
21
- # to be defined. In order to run all specs at once, we'll need to
22
- # load/unload rabl and rabl-rails whenever we switch from testing
23
- # one to another.
24
- def ensure_rabl_is_loaded
25
- Object.send(:remove_const, :RablRails) if defined? RablRails
26
- Object.send(:remove_const, :Rails) if defined? Rails
27
- unless defined? Rabl
28
- load 'rabl.rb'
29
- load 'rabl/version.rb'
30
- load 'rabl/helpers.rb'
31
- load 'rabl/sources.rb'
32
- load 'rabl/partials.rb'
33
- load 'rabl/multi_builder.rb'
34
- load 'rabl/builder.rb'
35
- load 'rabl/engine.rb'
36
- load 'rabl/configuration.rb'
37
- load 'rabl/renderer.rb'
38
- load 'rabl/cache_engine.rb'
39
- end
40
- end
41
-
42
- # Unloads rabl and loads rabl-rails.
43
- def ensure_rabl_rails_is_loaded
44
- Object.send(:remove_const, :Rabl) if defined? Rabl
45
- unless defined? RablRails
46
- load 'rabl-rails/renderer.rb'
47
- load 'rabl-rails/helpers.rb'
48
- load 'rabl-rails/configuration.rb'
49
- load 'rabl-rails/nodes/node.rb'
50
- load 'rabl-rails/nodes/attribute.rb'
51
- load 'rabl-rails/compiler.rb'
52
- load 'rabl-rails/renderers/hash.rb'
53
- load 'rabl-rails/renderers/json.rb'
54
- load 'rabl-rails/renderers/xml.rb'
55
- load 'rabl-rails/renderers/plist.rb'
56
- load 'rabl-rails.rb'
57
- load 'rabl-rails/template.rb'
58
- load 'rabl-rails/library.rb'
59
- end
60
- end
61
17
 
62
18
  RSpec.configure do |config|
63
19
  config.before(:each) do
@@ -66,3 +22,15 @@ RSpec.configure do |config|
66
22
  allow(Gon).to receive(:current_gon).and_return(@request)
67
23
  end
68
24
  end
25
+
26
+ def request
27
+ @request ||= double 'request', :env => {}
28
+ end
29
+
30
+ def wrap_script(content, cdata=true)
31
+ script = "<script>"
32
+ script << "\n//<![CDATA[\n" if cdata
33
+ script << content
34
+ script << "\n//]]>\n" if cdata
35
+ script << '</script>'
36
+ end
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.1.0
4
+ version: 6.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: 3.0.20
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: 3.0.20
27
27
  - !ruby/object:Gem::Dependency
28
- name: request_store
28
+ name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '0.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '0.7'
41
41
  - !ruby/object:Gem::Dependency
42
- name: json
42
+ name: request_store
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: multi_json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '3.0'
131
+ version: 3.0.20
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '3.0'
138
+ version: 3.0.20
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry-byebug
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description: If you need to send some data to your js files and you don't want to
168
182
  do this with long way trough views and parsing - use this force!
169
183
  email:
@@ -172,6 +186,7 @@ executables: []
172
186
  extensions: []
173
187
  extra_rdoc_files: []
174
188
  files:
189
+ - ".github/FUNDING.yml"
175
190
  - ".gitignore"
176
191
  - ".travis.yml"
177
192
  - CHANGELOG.md
@@ -203,8 +218,7 @@ files:
203
218
  - spec/gon/basic_spec.rb
204
219
  - spec/gon/global_spec.rb
205
220
  - spec/gon/jbuilder_spec.rb
206
- - spec/gon/rabl_with_rabl_rails_spec.rb
207
- - spec/gon/rabl_with_rabl_spec.rb
221
+ - spec/gon/rabl_spec.rb
208
222
  - spec/gon/templates_spec.rb
209
223
  - spec/gon/thread_spec.rb
210
224
  - spec/gon/watch_spec.rb
@@ -230,17 +244,16 @@ require_paths:
230
244
  - lib
231
245
  required_ruby_version: !ruby/object:Gem::Requirement
232
246
  requirements:
233
- - - ">"
247
+ - - ">="
234
248
  - !ruby/object:Gem::Version
235
- version: 1.8.7
249
+ version: 2.2.0
236
250
  required_rubygems_version: !ruby/object:Gem::Requirement
237
251
  requirements:
238
252
  - - ">="
239
253
  - !ruby/object:Gem::Version
240
254
  version: '0'
241
255
  requirements: []
242
- rubyforge_project:
243
- rubygems_version: 2.5.1
256
+ rubygems_version: 3.1.2
244
257
  signing_key:
245
258
  specification_version: 4
246
259
  summary: Get your Rails variables in your JS
@@ -1,63 +0,0 @@
1
- describe Gon do
2
-
3
- before(:all) do
4
- ensure_rabl_rails_is_loaded
5
- RablRails.configuration.cache_templates = false
6
- end
7
-
8
- describe '.rabl with rabl-rails gem' do
9
-
10
- before :each do
11
- Gon.clear
12
- controller.instance_variable_set('@objects', objects)
13
- controller.request = ActionDispatch::TestRequest.new
14
- end
15
-
16
- let(:controller) { ActionController::Base.new }
17
- let(:objects) { [1, 2] }
18
-
19
- context 'render template with deprecation' do
20
- it 'still works' do
21
- Gon.rabl 'spec/test_data/sample_rabl_rails.rabl', :controller => controller
22
- expect(Gon.objects.length).to eq(2)
23
- end
24
- end
25
-
26
- context 'option locals' do
27
- it 'works without locals object properly' do
28
- Gon.rabl(
29
- :template =>'spec/test_data/sample_rabl_rails.rabl',
30
- :controller => controller
31
- )
32
- expect(Gon.objects.map { |it| it['inspect'] }).to eq(%w(1 2))
33
- end
34
-
35
- it 'works with different locals object' do
36
- Gon.rabl(
37
- :template => 'spec/test_data/sample_rabl_rails.rabl',
38
- :controller => controller,
39
- :locals => { :objects => [3, 4] }
40
- )
41
- expect(Gon.objects.map { |it| it['inspect'] }).to eq(%w(3 4))
42
- end
43
- end
44
-
45
- it 'works if rabl-rails is included' do
46
- Gon.rabl :template => 'spec/test_data/sample_rabl_rails.rabl', :controller => controller
47
- expect(Gon.objects.length).to eq(2)
48
- end
49
-
50
- it 'works with ActionView::Helpers' do
51
- Gon.rabl :template =>'spec/test_data/sample_with_helpers_rabl_rails.rabl', :controller => controller
52
- expect(Gon.objects.first['time_ago']).to eq('about 6 hours')
53
- end
54
-
55
- it 'raise exception if rabl or rabl-rails is not included' do
56
- Object.send :remove_const, :RablRails # ensure_rabl_rails_is_loaded method already removed Rabl
57
- expect { Gon.rabl :template => 'spec/test_data/sample.rabl', :controller => controller}.to raise_error(RuntimeError)
58
- ensure_rabl_rails_is_loaded # load up rabl-rails again, we're not done testing
59
- end
60
-
61
- end
62
-
63
- end