gon 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -25
- data/lib/gon/base.rb +23 -25
- data/lib/gon/env_finder.rb +5 -8
- data/lib/gon/escaper.rb +6 -8
- data/lib/gon/helpers.rb +4 -4
- data/lib/gon/jbuilder/parser.rb +17 -16
- data/lib/gon/jbuilder.rb +6 -8
- data/lib/gon/json_dumper.rb +14 -8
- data/lib/gon/rabl.rb +9 -37
- data/lib/gon/spec_helpers.rb +2 -3
- data/lib/gon/version.rb +1 -1
- data/lib/gon/watch.rb +2 -4
- data/lib/gon.rb +4 -12
- metadata +14 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f0c0df899115e3ec1c09be0ce2db0e5b4b56e486f14c9d1b2e75ab01beb90d5
|
|
4
|
+
data.tar.gz: 5d1bfc691aa203e67ce96aed85cf5c885e01d25649d98cba690a81e7cdf1f2de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1987b4f6e3dfc27b6f35909228fc1b013919b0265796c9323eaafaa4b5972ab31d173f3abbbd38749fa6a578125564576fc3e77355f723c371f5380fe031106e
|
|
7
|
+
data.tar.gz: e182033d36b2db82d9de4cff42f3cf4569a1d84ec547a7ede568c1d271e3294bb4f45fd3cd4e32fad1e15c99f846215c7b8261a9755fcf2c036db5374427145b
|
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@ If you need to send some data to your js files and you don't want to do this wit
|
|
|
6
6
|
|
|
7
7
|
Now you can easily renew data in your variables through ajax with [gon.watch](https://github.com/gazay/gon/wiki/Usage-gon-watch)!
|
|
8
8
|
|
|
9
|
-
With [Jbuilder](https://github.com/rails/jbuilder)
|
|
9
|
+
With [Jbuilder](https://github.com/rails/jbuilder) and [Rabl](https://github.com/nesquena/rabl) support!
|
|
10
10
|
|
|
11
11
|
For Sinatra available [gon-sinatra](https://github.com/gazay/gon-sinatra).
|
|
12
12
|
|
|
@@ -179,30 +179,6 @@ Profit of using Rabl with gon:
|
|
|
179
179
|
[Instruction](https://github.com/gazay/gon/wiki/Usage-with-rabl) for
|
|
180
180
|
usage gon with Rabl.
|
|
181
181
|
|
|
182
|
-
## Usage with Rabl-Rails
|
|
183
|
-
`gon.rabl` works with [rabl-rails](https://github.com/ccocchi/rabl-rails). Learn to write RABL the rabl-rails way [here](https://github.com/ccocchi/rabl-rails).
|
|
184
|
-
|
|
185
|
-
Add gon and rabl-rails to your environment:
|
|
186
|
-
```ruby
|
|
187
|
-
gem 'gon'
|
|
188
|
-
gem 'rabl-rails'
|
|
189
|
-
```
|
|
190
|
-
Define a rabl template using rabl-rails syntax:
|
|
191
|
-
```rabl
|
|
192
|
-
#app/views/users/show.rabl
|
|
193
|
-
object :@user
|
|
194
|
-
attributes :id, :name, :email, :location
|
|
195
|
-
```
|
|
196
|
-
Call gon.rabl in your controller
|
|
197
|
-
|
|
198
|
-
```ruby
|
|
199
|
-
#app/controllers/users_controller.rb
|
|
200
|
-
def show
|
|
201
|
-
@user = User.find(params[:id])
|
|
202
|
-
gon.rabl
|
|
203
|
-
end
|
|
204
|
-
```
|
|
205
|
-
|
|
206
182
|
## Usage with Jbuilder
|
|
207
183
|
|
|
208
184
|
Use gon with [Jbuilder](https://github.com/rails/jbuilder) as with [Rabl](https://guthub.com/nesquena/rabl):
|
data/lib/gon/base.rb
CHANGED
|
@@ -3,24 +3,23 @@
|
|
|
3
3
|
class Gon
|
|
4
4
|
module Base
|
|
5
5
|
VALID_OPTION_DEFAULTS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
namespace: 'gon',
|
|
7
|
+
camel_case: false,
|
|
8
|
+
camel_depth: 1,
|
|
9
|
+
watch: false,
|
|
10
|
+
need_tag: true,
|
|
11
|
+
type: false,
|
|
12
|
+
cdata: true,
|
|
13
|
+
global_root: 'global',
|
|
14
|
+
namespace_check: false,
|
|
15
|
+
amd: false,
|
|
16
|
+
nonce: nil
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
Option = Struct.new(:cameled, *VALID_OPTION_DEFAULTS.keys)
|
|
20
20
|
private_constant :Option
|
|
21
21
|
|
|
22
22
|
class << self
|
|
23
|
-
|
|
24
23
|
def render_data(options = {})
|
|
25
24
|
_o = define_options(options)
|
|
26
25
|
|
|
@@ -50,8 +49,8 @@ class Gon
|
|
|
50
49
|
before, after = render_wrap(_o)
|
|
51
50
|
script << before
|
|
52
51
|
|
|
53
|
-
script << gon_variables(_o.global_root)
|
|
54
|
-
|
|
52
|
+
script << gon_variables(_o.global_root)
|
|
53
|
+
.map { |key, val| render_variable(_o, key, val) }.join
|
|
55
54
|
script << (render_watch(_o) || '')
|
|
56
55
|
|
|
57
56
|
script << after
|
|
@@ -62,7 +61,7 @@ class Gon
|
|
|
62
61
|
if _o.amd
|
|
63
62
|
["define('#{_o.namespace}',[],function(){var gon={};", 'return gon;});']
|
|
64
63
|
else
|
|
65
|
-
before =
|
|
64
|
+
before =
|
|
66
65
|
if _o.namespace_check
|
|
67
66
|
"window.#{_o.namespace}=window.#{_o.namespace}||{};"
|
|
68
67
|
else
|
|
@@ -82,12 +81,12 @@ class Gon
|
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
def render_watch(_o)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
return unless _o.watch and Gon::Watch.all_variables.present?
|
|
85
|
+
|
|
86
|
+
if _o.amd
|
|
87
|
+
Gon.watch.render_amd
|
|
88
|
+
else
|
|
89
|
+
Gon.watch.render
|
|
91
90
|
end
|
|
92
91
|
end
|
|
93
92
|
|
|
@@ -101,9 +100,9 @@ class Gon
|
|
|
101
100
|
|
|
102
101
|
case value
|
|
103
102
|
when Hash
|
|
104
|
-
Hash[value.map
|
|
105
|
-
[
|
|
106
|
-
|
|
103
|
+
Hash[value.map do |k, v|
|
|
104
|
+
[convert_key(k, true), convert_hash_keys(v, current_depth + 1, max_depth)]
|
|
105
|
+
end]
|
|
107
106
|
when Enumerable
|
|
108
107
|
value.map { |v| convert_hash_keys(v, current_depth + 1, max_depth) }
|
|
109
108
|
else
|
|
@@ -129,7 +128,6 @@ class Gon
|
|
|
129
128
|
cache = Current.gon_keys_cache ||= {}
|
|
130
129
|
cache["#{key}_#{camelize}"] ||= camelize ? key.to_s.camelize(:lower) : key.to_s
|
|
131
130
|
end
|
|
132
|
-
|
|
133
131
|
end
|
|
134
132
|
end
|
|
135
133
|
end
|
data/lib/gon/env_finder.rb
CHANGED
|
@@ -6,15 +6,14 @@ class Gon
|
|
|
6
6
|
ENV_RESPONSE_KEY = 'action_controller.rescue.response'
|
|
7
7
|
|
|
8
8
|
class << self
|
|
9
|
-
|
|
10
9
|
def controller_env(options = {})
|
|
11
10
|
options[:controller] ||
|
|
12
11
|
(
|
|
13
|
-
current_gon &&
|
|
14
|
-
current_gon.env[ENV_CONTROLLER_KEY] ||
|
|
15
|
-
current_gon.env[ENV_RESPONSE_KEY]
|
|
16
|
-
instance_variable_get('@template')
|
|
17
|
-
instance_variable_get('@controller')
|
|
12
|
+
(current_gon &&
|
|
13
|
+
current_gon.env[ENV_CONTROLLER_KEY]) ||
|
|
14
|
+
current_gon.env[ENV_RESPONSE_KEY]
|
|
15
|
+
.instance_variable_get('@template')
|
|
16
|
+
.instance_variable_get('@controller')
|
|
18
17
|
)
|
|
19
18
|
end
|
|
20
19
|
|
|
@@ -41,8 +40,6 @@ class Gon
|
|
|
41
40
|
def current_gon
|
|
42
41
|
Current.gon
|
|
43
42
|
end
|
|
44
|
-
|
|
45
43
|
end
|
|
46
|
-
|
|
47
44
|
end
|
|
48
45
|
end
|
data/lib/gon/escaper.rb
CHANGED
|
@@ -6,18 +6,17 @@ class Gon
|
|
|
6
6
|
extend ActionView::Helpers::TagHelper
|
|
7
7
|
|
|
8
8
|
class << self
|
|
9
|
-
|
|
10
9
|
def escape_unicode(javascript)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
return unless javascript
|
|
11
|
+
|
|
12
|
+
result = escape_line_separator(javascript)
|
|
13
|
+
javascript.html_safe? ? result.html_safe : result
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def javascript_tag(content, type, cdata, nonce)
|
|
18
17
|
options = {}
|
|
19
|
-
options.merge!(
|
|
20
|
-
options.merge!(
|
|
18
|
+
options.merge!({ type: 'text/javascript' }) if type
|
|
19
|
+
options.merge!({ nonce: nonce }) if nonce
|
|
21
20
|
|
|
22
21
|
content_tag(:script, javascript_cdata_section(content, cdata).html_safe, options)
|
|
23
22
|
end
|
|
@@ -35,7 +34,6 @@ class Gon
|
|
|
35
34
|
def escape_line_separator(javascript)
|
|
36
35
|
javascript.gsub(/\\u2028/u, '
')
|
|
37
36
|
end
|
|
38
|
-
|
|
39
37
|
end
|
|
40
38
|
end
|
|
41
39
|
end
|
data/lib/gon/helpers.rb
CHANGED
|
@@ -13,8 +13,8 @@ class Gon
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def include_gon_amd(options={})
|
|
17
|
-
Gon::Base.render_data(options.merge({amd: true}))
|
|
16
|
+
def include_gon_amd(options = {})
|
|
17
|
+
Gon::Base.render_data(options.merge({ amd: true }))
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
private
|
|
@@ -55,8 +55,8 @@ class Gon
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
ActiveSupport.on_load :action_view do
|
|
58
|
-
ActionView::Base.
|
|
58
|
+
ActionView::Base.include Gon::ViewHelpers
|
|
59
59
|
end
|
|
60
60
|
ActiveSupport.on_load :action_controller do
|
|
61
|
-
ActionController::Base.
|
|
61
|
+
ActionController::Base.include Gon::ControllerHelpers
|
|
62
62
|
end
|
data/lib/gon/jbuilder/parser.rb
CHANGED
|
@@ -29,7 +29,7 @@ class Gon
|
|
|
29
29
|
|
|
30
30
|
def assign_controller_variables(controller)
|
|
31
31
|
controller.instance_variables.each do |name|
|
|
32
|
-
|
|
32
|
+
instance_variable_set \
|
|
33
33
|
name,
|
|
34
34
|
controller.instance_variable_get(name)
|
|
35
35
|
end
|
|
@@ -37,23 +37,23 @@ class Gon
|
|
|
37
37
|
|
|
38
38
|
def eval_controller_helpers(controller)
|
|
39
39
|
controller._helper_methods.each do |meth|
|
|
40
|
-
self.class.class_eval <<-
|
|
40
|
+
self.class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
|
41
41
|
def #{meth}(*args, &blk) # def current_user(*args, &blk)
|
|
42
42
|
__controller.send(%(#{meth}), *args, &blk) # controller.send(:current_user, *args, &blk)
|
|
43
43
|
end # end
|
|
44
|
-
|
|
44
|
+
RUBY_EVAL
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
def eval_controller_url_helpers(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
def eval_controller_url_helpers(_controller)
|
|
49
|
+
return unless defined?(Rails) && Rails.respond_to?(:application)
|
|
50
|
+
|
|
51
|
+
Rails.application.routes.url_helpers.instance_methods.each do |meth|
|
|
52
|
+
self.class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
|
52
53
|
def #{meth}(*args, &blk) # def user_path(*args, &blk)
|
|
53
54
|
__controller.send(%(#{meth}), *args, &blk) # controller.send(:user_path, *args, &blk)
|
|
54
55
|
end # end
|
|
55
|
-
|
|
56
|
-
end
|
|
56
|
+
RUBY_EVAL
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -61,7 +61,7 @@ class Gon
|
|
|
61
61
|
locals.each do |name, value|
|
|
62
62
|
self.class.class_eval do
|
|
63
63
|
define_method "#{name}" do
|
|
64
|
-
|
|
64
|
+
value
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -87,18 +87,19 @@ class Gon
|
|
|
87
87
|
def set_options_from_hash(options_hash)
|
|
88
88
|
options = eval "{#{options_hash}}"
|
|
89
89
|
options.each do |name, val|
|
|
90
|
-
|
|
91
|
-
eval "def #{name}; self.instance_variable_get('@' + '#{name
|
|
90
|
+
instance_variable_set("@#{name}", val)
|
|
91
|
+
eval "def #{name}; self.instance_variable_get('@' + '#{name}'); end"
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def parse_path(path)
|
|
96
96
|
return path if File.exist?(path)
|
|
97
97
|
if (splitted = path.split('/')).blank?
|
|
98
|
-
|
|
98
|
+
raise 'Something wrong with partial path in your jbuilder templates'
|
|
99
99
|
elsif splitted.size == 1
|
|
100
|
-
|
|
100
|
+
splitted.shift(@_controller_name)
|
|
101
101
|
end
|
|
102
|
+
|
|
102
103
|
construct_path(splitted)
|
|
103
104
|
end
|
|
104
105
|
|
|
@@ -112,7 +113,8 @@ class Gon
|
|
|
112
113
|
def path_with_ext(path)
|
|
113
114
|
return path if File.exist?(path)
|
|
114
115
|
return "#{path}.jbuilder" if File.exist?("#{path}.jbuilder")
|
|
115
|
-
|
|
116
|
+
|
|
117
|
+
"#{path}.json.jbuilder" if File.exist?("#{path}.json.jbuilder")
|
|
116
118
|
end
|
|
117
119
|
|
|
118
120
|
def find_partials(lines = [])
|
|
@@ -124,7 +126,6 @@ class Gon
|
|
|
124
126
|
end
|
|
125
127
|
end.flatten
|
|
126
128
|
end
|
|
127
|
-
|
|
128
129
|
end
|
|
129
130
|
end
|
|
130
131
|
end
|
data/lib/gon/jbuilder.rb
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
class Gon
|
|
4
4
|
module Jbuilder
|
|
5
5
|
class << self
|
|
6
|
-
|
|
7
6
|
def handler(args, global = false)
|
|
8
7
|
options = parse_options_from args
|
|
9
8
|
valid_options? options, global
|
|
@@ -25,19 +24,19 @@ class Gon
|
|
|
25
24
|
private
|
|
26
25
|
|
|
27
26
|
def valid_options?(options, global)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
return unless global && !options[:template]
|
|
28
|
+
|
|
29
|
+
raise 'You should provide :template when use jbuilder with global variables'
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
def parse_options_from(args)
|
|
34
33
|
if old_api? args
|
|
35
|
-
text = +
|
|
36
|
-
text <<
|
|
34
|
+
text = +'[DEPRECATION] view_path argument is now optional. '
|
|
35
|
+
text << 'If you need to specify it, '
|
|
37
36
|
text << "please use gon.jbuilder(:template => 'path')"
|
|
38
37
|
warn text
|
|
39
38
|
|
|
40
|
-
args.extract_options!.merge(:
|
|
39
|
+
args.extract_options!.merge(template: args[0])
|
|
41
40
|
elsif new_api? args
|
|
42
41
|
args.first
|
|
43
42
|
else
|
|
@@ -52,7 +51,6 @@ class Gon
|
|
|
52
51
|
def new_api?(args)
|
|
53
52
|
args.first.is_a? Hash
|
|
54
53
|
end
|
|
55
|
-
|
|
56
54
|
end
|
|
57
55
|
end
|
|
58
56
|
end
|
data/lib/gon/json_dumper.rb
CHANGED
|
@@ -5,20 +5,26 @@ class Gon
|
|
|
5
5
|
# Taken from ERB::Util
|
|
6
6
|
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
|
7
7
|
JSON_ESCAPE = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
'&' => '\u0026',
|
|
9
|
+
'>' => '\u003e',
|
|
10
|
+
'<' => '\u003c',
|
|
11
11
|
"\u2028" => '\u2028',
|
|
12
12
|
"\u2029" => '\u2029'
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
def self.dump(object)
|
|
16
|
-
|
|
16
|
+
multi_json = defined?(MultiJSON) ? MultiJSON : MultiJson
|
|
17
|
+
adapter = multi_json.adapter
|
|
18
|
+
options = if defined?(multi_json::Adapters::Oj) && adapter == multi_json::Adapters::Oj
|
|
19
|
+
{ mode: :compat, escape_mode: :xss_safe, time_format: :ruby }
|
|
20
|
+
else
|
|
21
|
+
{}
|
|
22
|
+
end
|
|
17
23
|
dumped_json = if defined?(MultiJSON)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
MultiJSON.generate(object, options)
|
|
25
|
+
else
|
|
26
|
+
MultiJson.dump(object, options)
|
|
27
|
+
end
|
|
22
28
|
|
|
23
29
|
escape(dumped_json)
|
|
24
30
|
end
|
data/lib/gon/rabl.rb
CHANGED
|
@@ -6,20 +6,13 @@ begin
|
|
|
6
6
|
require 'rabl' # use rabl gem if it's available
|
|
7
7
|
rescue LoadError
|
|
8
8
|
end
|
|
9
|
-
begin
|
|
10
|
-
require 'rabl-rails' # use rabl-rails gem if it's available
|
|
11
|
-
rescue LoadError
|
|
12
|
-
end
|
|
13
9
|
|
|
14
10
|
class Gon
|
|
15
11
|
module Rabl
|
|
16
12
|
class << self
|
|
17
|
-
|
|
18
13
|
def handler(args, global = false)
|
|
19
14
|
options = parse_options_from args, global
|
|
20
|
-
if global && !options[:template]
|
|
21
|
-
raise 'You should provide :template when use rabl with global variables'
|
|
22
|
-
end
|
|
15
|
+
raise 'You should provide :template when use rabl with global variables' if global && !options[:template]
|
|
23
16
|
|
|
24
17
|
data = parse_rabl \
|
|
25
18
|
Gon::EnvFinder.template_path(options, 'rabl'),
|
|
@@ -32,46 +25,26 @@ class Gon
|
|
|
32
25
|
private
|
|
33
26
|
|
|
34
27
|
def parse_rabl(rabl_path, controller, locals)
|
|
35
|
-
|
|
36
|
-
parse_with_rabl rabl_path, controller, locals
|
|
37
|
-
elsif defined? ::RablRails
|
|
38
|
-
parse_with_rabl_rails rabl_path, controller, locals
|
|
39
|
-
else
|
|
40
|
-
raise 'rabl or rabl-rails must be required in order to use gon.rabl'
|
|
41
|
-
end
|
|
42
|
-
end
|
|
28
|
+
raise 'rabl must be required in order to use gon.rabl' unless defined? ::Rabl
|
|
43
29
|
|
|
44
|
-
def parse_with_rabl(rabl_path, controller, locals)
|
|
45
30
|
locals ||= {}
|
|
46
31
|
source = File.read(rabl_path)
|
|
47
32
|
include_helpers
|
|
48
|
-
rabl_engine = ::Rabl::Engine.new(source, :
|
|
33
|
+
rabl_engine = ::Rabl::Engine.new(source, format: 'json', template: rabl_path)
|
|
49
34
|
output = rabl_engine.render(controller, locals)
|
|
50
35
|
JSON.parse(output)
|
|
51
36
|
end
|
|
52
37
|
|
|
53
|
-
def parse_with_rabl_rails(rabl_path, controller, locals)
|
|
54
|
-
locals ||= {}
|
|
55
|
-
source = File.read(rabl_path)
|
|
56
|
-
original_formats = controller.formats
|
|
57
|
-
controller.formats = [:json]
|
|
58
|
-
view_context = controller.send(:view_context)
|
|
59
|
-
locals.each { |k, v| view_context.assigns[k.to_s] = v }
|
|
60
|
-
output = RablRails::Library.instance.get_rendered_template(source, view_context)
|
|
61
|
-
controller.formats = original_formats
|
|
62
|
-
JSON.parse(output)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
38
|
def parse_options_from(args, global)
|
|
66
39
|
if old_api? args
|
|
67
40
|
unless global
|
|
68
|
-
text = +
|
|
69
|
-
text <<
|
|
41
|
+
text = +'[DEPRECATION] view_path argument is now optional. '
|
|
42
|
+
text << 'If you need to specify it, '
|
|
70
43
|
text << "please use gon.rabl(:template => 'path')"
|
|
71
44
|
warn text
|
|
72
45
|
end
|
|
73
46
|
|
|
74
|
-
args.extract_options!.merge(:
|
|
47
|
+
args.extract_options!.merge(template: args[0])
|
|
75
48
|
elsif new_api? args
|
|
76
49
|
args.first
|
|
77
50
|
else
|
|
@@ -80,9 +53,9 @@ class Gon
|
|
|
80
53
|
end
|
|
81
54
|
|
|
82
55
|
def include_helpers
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
56
|
+
return if ::Rabl::Engine.include? ::ActionView::Helpers
|
|
57
|
+
|
|
58
|
+
::Rabl::Engine.include ::ActionView::Helpers
|
|
86
59
|
end
|
|
87
60
|
|
|
88
61
|
def old_api?(args)
|
|
@@ -92,7 +65,6 @@ class Gon
|
|
|
92
65
|
def new_api?(args)
|
|
93
66
|
args.first.is_a? Hash
|
|
94
67
|
end
|
|
95
|
-
|
|
96
68
|
end
|
|
97
69
|
end
|
|
98
70
|
end
|
data/lib/gon/spec_helpers.rb
CHANGED
|
@@ -12,7 +12,7 @@ class Gon
|
|
|
12
12
|
if controller.is_a? ActionController::Base
|
|
13
13
|
controller.gon
|
|
14
14
|
Gon.send(:current_gon).env[Gon::EnvFinder::ENV_CONTROLLER_KEY] =
|
|
15
|
-
|
|
15
|
+
controller
|
|
16
16
|
end
|
|
17
17
|
super
|
|
18
18
|
end
|
|
@@ -27,6 +27,5 @@ class Gon
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
if ENV['RAILS_ENV'] == 'test' && defined?(ActionController::TestCase::Behavior)
|
|
30
|
-
ActionController::TestCase::Behavior.
|
|
30
|
+
ActionController::TestCase::Behavior.include Gon::SpecHelper::Rails
|
|
31
31
|
end
|
|
32
|
-
|
data/lib/gon/version.rb
CHANGED
data/lib/gon/watch.rb
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
class Gon
|
|
4
4
|
class Watch < Gon
|
|
5
5
|
class << self
|
|
6
|
-
|
|
7
|
-
JS_FUNCTION = File.read(File.expand_path('../../../js/watch.js', __FILE__))
|
|
6
|
+
JS_FUNCTION = File.read(File.expand_path('../../js/watch.js', __dir__))
|
|
8
7
|
|
|
9
8
|
def render
|
|
10
9
|
JS_FUNCTION + "window.gon.watchedVariables=#{Gon::JsonDumper.dump all_variables};"
|
|
@@ -52,9 +51,8 @@ class Gon
|
|
|
52
51
|
|
|
53
52
|
def return_variable(value)
|
|
54
53
|
controller = Gon::EnvFinder.controller_env
|
|
55
|
-
controller.render json: Gon::Escaper.escape_unicode(Gon::JsonDumper.dump
|
|
54
|
+
controller.render json: Gon::Escaper.escape_unicode(Gon::JsonDumper.dump(value))
|
|
56
55
|
end
|
|
57
|
-
|
|
58
56
|
end
|
|
59
57
|
end
|
|
60
58
|
end
|
data/lib/gon.rb
CHANGED
|
@@ -18,15 +18,12 @@ require 'gon/jbuilder/parser'
|
|
|
18
18
|
require 'gon/json_dumper'
|
|
19
19
|
|
|
20
20
|
# NOTE : ActionDispatch::Request#uuid appears only in Rails 3.2.1
|
|
21
|
-
unless ActionDispatch::Request.
|
|
22
|
-
require 'gon/compatibility/old_rails'
|
|
23
|
-
end
|
|
21
|
+
require 'gon/compatibility/old_rails' unless ActionDispatch::Request.public_method_defined?(:uuid)
|
|
24
22
|
|
|
25
23
|
require 'gon/spec_helpers'
|
|
26
24
|
|
|
27
25
|
class Gon
|
|
28
26
|
class << self
|
|
29
|
-
|
|
30
27
|
def global
|
|
31
28
|
Gon::Global
|
|
32
29
|
end
|
|
@@ -35,11 +32,9 @@ class Gon
|
|
|
35
32
|
Gon::Watch
|
|
36
33
|
end
|
|
37
34
|
|
|
38
|
-
def method_missing(method, *args
|
|
35
|
+
def method_missing(method, *args)
|
|
39
36
|
if method.to_s =~ /=$/
|
|
40
|
-
if public_method_name?(method)
|
|
41
|
-
raise "You can't use Gon public methods for storing data: #{method}"
|
|
42
|
-
end
|
|
37
|
+
raise "You can't use Gon public methods for storing data: #{method}" if public_method_name?(method)
|
|
43
38
|
if self == Gon && !current_gon
|
|
44
39
|
raise 'Assign request-specific gon variables only through `gon` helper, not through Gon constant'
|
|
45
40
|
end
|
|
@@ -60,9 +55,7 @@ class Gon
|
|
|
60
55
|
|
|
61
56
|
def merge_variable(name, value)
|
|
62
57
|
old_value = all_variables[name]
|
|
63
|
-
if value.is_a?(Hash) && old_value.is_a?(Hash)
|
|
64
|
-
value = old_value.deep_merge(value)
|
|
65
|
-
end
|
|
58
|
+
value = old_value.deep_merge(value) if value.is_a?(Hash) && old_value.is_a?(Hash)
|
|
66
59
|
set_variable(name, value)
|
|
67
60
|
end
|
|
68
61
|
|
|
@@ -129,6 +122,5 @@ class Gon
|
|
|
129
122
|
def ensure_template_handler_is_defined
|
|
130
123
|
load 'jbuilder.rb' unless defined?(JbuilderTemplate)
|
|
131
124
|
end
|
|
132
|
-
|
|
133
125
|
end
|
|
134
126
|
end
|
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:
|
|
4
|
+
version: 8.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- gazay
|
|
@@ -66,21 +66,21 @@ dependencies:
|
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
68
|
- !ruby/object:Gem::Dependency
|
|
69
|
-
name:
|
|
69
|
+
name: jbuilder
|
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
72
|
- - ">="
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '
|
|
74
|
+
version: '0'
|
|
75
75
|
type: :development
|
|
76
76
|
prerelease: false
|
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
|
79
79
|
- - ">="
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '
|
|
81
|
+
version: '0'
|
|
82
82
|
- !ruby/object:Gem::Dependency
|
|
83
|
-
name:
|
|
83
|
+
name: pry
|
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
|
86
86
|
- - ">="
|
|
@@ -94,7 +94,7 @@ dependencies:
|
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '0'
|
|
96
96
|
- !ruby/object:Gem::Dependency
|
|
97
|
-
name:
|
|
97
|
+
name: pry-byebug
|
|
98
98
|
requirement: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
|
100
100
|
- - ">="
|
|
@@ -108,7 +108,7 @@ dependencies:
|
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
109
|
version: '0'
|
|
110
110
|
- !ruby/object:Gem::Dependency
|
|
111
|
-
name:
|
|
111
|
+
name: railties
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements:
|
|
114
114
|
- - ">="
|
|
@@ -122,7 +122,7 @@ dependencies:
|
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: '0'
|
|
124
124
|
- !ruby/object:Gem::Dependency
|
|
125
|
-
name:
|
|
125
|
+
name: rake
|
|
126
126
|
requirement: !ruby/object:Gem::Requirement
|
|
127
127
|
requirements:
|
|
128
128
|
- - ">="
|
|
@@ -136,19 +136,19 @@ dependencies:
|
|
|
136
136
|
- !ruby/object:Gem::Version
|
|
137
137
|
version: '0'
|
|
138
138
|
- !ruby/object:Gem::Dependency
|
|
139
|
-
name:
|
|
139
|
+
name: rspec
|
|
140
140
|
requirement: !ruby/object:Gem::Requirement
|
|
141
141
|
requirements:
|
|
142
142
|
- - ">="
|
|
143
143
|
- !ruby/object:Gem::Version
|
|
144
|
-
version: '0'
|
|
144
|
+
version: '3.0'
|
|
145
145
|
type: :development
|
|
146
146
|
prerelease: false
|
|
147
147
|
version_requirements: !ruby/object:Gem::Requirement
|
|
148
148
|
requirements:
|
|
149
149
|
- - ">="
|
|
150
150
|
- !ruby/object:Gem::Version
|
|
151
|
-
version: '0'
|
|
151
|
+
version: '3.0'
|
|
152
152
|
description: If you need to send some data to your js files and you don't want to
|
|
153
153
|
do this with long way trough views and parsing - use this force!
|
|
154
154
|
email:
|
|
@@ -181,7 +181,8 @@ files:
|
|
|
181
181
|
homepage: https://github.com/gazay/gon
|
|
182
182
|
licenses:
|
|
183
183
|
- MIT
|
|
184
|
-
metadata:
|
|
184
|
+
metadata:
|
|
185
|
+
rubygems_mfa_required: 'true'
|
|
185
186
|
rdoc_options: []
|
|
186
187
|
require_paths:
|
|
187
188
|
- lib
|
|
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
196
197
|
- !ruby/object:Gem::Version
|
|
197
198
|
version: '0'
|
|
198
199
|
requirements: []
|
|
199
|
-
rubygems_version: 4.0.
|
|
200
|
+
rubygems_version: 4.0.16
|
|
200
201
|
specification_version: 4
|
|
201
202
|
summary: Get your Rails variables in your JS
|
|
202
203
|
test_files: []
|