gon 6.1.0 → 6.2.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: 9d24de7434f197bf9f86ea9ef17bbcf9ec585647
4
- data.tar.gz: 49a264791c39e669f5364b469c6c9c119372b504
3
+ metadata.gz: c19eee4ca6c0cff3ee98d241cec763d760538dde
4
+ data.tar.gz: e8a58a191ac62e622c5f172c879a693852fce131
5
5
  SHA512:
6
- metadata.gz: f1f121380839a33259810a5c1a2e7a4a149b91521b6d7c9d6b4b5742bd02977ee33aec47e43f31c78adeabb1ba748f20fea0a786819d84ac6c6809e27c376d6d
7
- data.tar.gz: 65d68f8c2e182d32be8191f164b86917bf33d8d08f16fddceab7361acd0a3afe894933014cdc35296686b990bc0e7648f23268fe1d376f6f42c84fc70def1d99
6
+ metadata.gz: bac0b2f0b276f6e22a0a4f5e1d7820d2789410f980b02f329a6e1a713ace8c18c85e9c1211eab634193b5e54cc0c54c3a2728b47ef7a3568866a5cfa92a5616e
7
+ data.tar.gz: 1fdd5df1b97870e96dfc7b357aa5af95406b7e8b574b9c811b7a43d79a8637af1fc9716e8e0ff1e45718b261b718dec8c3a18253a3f59e309b7465490b90c55e
@@ -1,17 +1,8 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1
7
- - 2.2
8
- - 2.3.0
4
+ - 2.3.3
5
+ - 2.4.0
9
6
  - 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
7
  # uncomment this line if your project needs to run something other than `rake`:
17
8
  # script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -2,8 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gon.gemspec
4
4
  gemspec
5
-
6
- platforms :rbx do
7
- gem 'rubysl', '~> 2.0'
8
- gem 'rubinius-developer_tools'
9
- end
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>
@@ -45,7 +47,7 @@ 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
 
@@ -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)
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.required_ruby_version = '> 1.8.7'
19
19
  s.add_dependency 'actionpack', '>= 3.0'
20
20
  s.add_dependency 'request_store', '>= 1.0'
21
- s.add_dependency 'json'
22
21
  s.add_dependency 'multi_json'
23
22
  s.add_development_dependency 'rabl', '0.11.3'
24
23
  s.add_development_dependency 'rabl-rails'
@@ -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 ? key.to_s.camelize(:lower) : key.to_s
128
+ end
129
+
125
130
  end
126
131
  end
127
132
  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
@@ -1,3 +1,3 @@
1
1
  class Gon
2
- VERSION = '6.1.0'
2
+ VERSION = '6.2.0'
3
3
  end
@@ -291,17 +291,4 @@ describe Gon do
291
291
  expect { Gon.jbuilder :template => 'spec/test_data/sample.json.jbuilder', :controller => controller }.not_to raise_error
292
292
  end
293
293
  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
294
  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
@@ -10,7 +10,7 @@ describe Gon do
10
10
  before :each do
11
11
  Gon.clear
12
12
  controller.instance_variable_set('@objects', objects)
13
- controller.request = ActionDispatch::TestRequest.new
13
+ controller.request = ActionDispatch::TestRequest.create
14
14
  end
15
15
 
16
16
  let(:controller) { ActionController::Base.new }
@@ -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
@@ -66,3 +66,15 @@ RSpec.configure do |config|
66
66
  allow(Gon).to receive(:current_gon).and_return(@request)
67
67
  end
68
68
  end
69
+
70
+ def request
71
+ @request ||= double 'request', :env => {}
72
+ end
73
+
74
+ def wrap_script(content, cdata=true)
75
+ script = "<script>"
76
+ script << "\n//<![CDATA[\n" if cdata
77
+ script << content
78
+ script << "\n//]]>\n" if cdata
79
+ script << '</script>'
80
+ 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.2.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: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
- - !ruby/object:Gem::Dependency
42
- name: json
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: multi_json
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -240,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
226
  version: '0'
241
227
  requirements: []
242
228
  rubyforge_project:
243
- rubygems_version: 2.5.1
229
+ rubygems_version: 2.5.2.1
244
230
  signing_key:
245
231
  specification_version: 4
246
232
  summary: Get your Rails variables in your JS