gon 4.0.0 → 4.0.1
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.
- data/.gitignore +1 -1
- data/CHANGELOG.md +6 -0
- data/lib/gon.rb +8 -11
- data/lib/gon/rabl.rb +7 -3
- data/lib/gon/version.rb +1 -1
- data/lib/gon/watch.rb +1 -1
- data/spec/gon/basic_spec.rb +20 -0
- data/spec/gon/rabl_spec.rb +19 -0
- data/spec/gon/watch_spec.rb +1 -1
- data/spec/test_data/sample.rabl +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 4.0.1
|
4
|
+
|
5
|
+
* Removed BlankSlate requirement *Peter Schröder*
|
6
|
+
* Gon#set_variable and Gon#get_variable moved to public scope
|
7
|
+
* Added option :locals to gon.rabl functionality
|
8
|
+
|
3
9
|
## 4.0.0
|
4
10
|
|
5
11
|
* Added gon.watch functionality (thanks to @brainopia and @kossnocorp)
|
data/lib/gon.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
if defined?(Jbuilder)
|
2
|
-
gem 'blankslate'
|
3
|
-
end
|
4
1
|
require 'action_view'
|
5
2
|
require 'action_controller'
|
6
3
|
require 'gon/base'
|
@@ -39,6 +36,14 @@ class Gon
|
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
39
|
+
def get_variable(name)
|
40
|
+
Request.gon[name]
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_variable(name, value)
|
44
|
+
Request.gon[name] = value
|
45
|
+
end
|
46
|
+
|
42
47
|
def all_variables
|
43
48
|
Request.gon
|
44
49
|
end
|
@@ -71,14 +76,6 @@ class Gon
|
|
71
76
|
|
72
77
|
private
|
73
78
|
|
74
|
-
def get_variable(name)
|
75
|
-
Request.gon[name]
|
76
|
-
end
|
77
|
-
|
78
|
-
def set_variable(name, value)
|
79
|
-
Request.gon[name] = value
|
80
|
-
end
|
81
|
-
|
82
79
|
def store_builder_data(builder, data, options)
|
83
80
|
if options[:as]
|
84
81
|
set_variable(options[:as].to_s, data)
|
data/lib/gon/rabl.rb
CHANGED
@@ -15,17 +15,21 @@ class Gon
|
|
15
15
|
|
16
16
|
data = parse_rabl \
|
17
17
|
Gon::Base.get_template_path(options, 'rabl'),
|
18
|
-
Gon::Base.get_controller(options)
|
18
|
+
Gon::Base.get_controller(options),
|
19
|
+
options[:locals]
|
19
20
|
|
20
21
|
[data, options]
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
def parse_rabl(rabl_path, controller)
|
26
|
+
def parse_rabl(rabl_path, controller, locals)
|
27
|
+
locals ||= {}
|
26
28
|
source = File.read(rabl_path)
|
27
29
|
rabl_engine = ::Rabl::Engine.new(source, :format => 'json')
|
28
|
-
|
30
|
+
|
31
|
+
output = rabl_engine.render(controller, locals)
|
32
|
+
|
29
33
|
JSON.parse(output)
|
30
34
|
end
|
31
35
|
|
data/lib/gon/version.rb
CHANGED
data/lib/gon/watch.rb
CHANGED
data/spec/gon/basic_spec.rb
CHANGED
@@ -27,6 +27,26 @@ describe Gon do
|
|
27
27
|
Gon.klass = Hash
|
28
28
|
end
|
29
29
|
|
30
|
+
it 'can be filled with dynamic named variables' do
|
31
|
+
Gon.clear
|
32
|
+
|
33
|
+
check = {}
|
34
|
+
3.times do |i|
|
35
|
+
Gon.set_variable("variable#{i}", i)
|
36
|
+
check["variable#{i}"] = i
|
37
|
+
end
|
38
|
+
|
39
|
+
Gon.all_variables.should == check
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can set and get variable with dynamic name' do
|
43
|
+
Gon.clear
|
44
|
+
var_name = "variable#{rand}"
|
45
|
+
|
46
|
+
Gon.set_variable var_name, 1
|
47
|
+
Gon.get_variable(var_name).should == 1
|
48
|
+
end
|
49
|
+
|
30
50
|
end
|
31
51
|
|
32
52
|
describe '#include_gon' do
|
data/spec/gon/rabl_spec.rb
CHANGED
@@ -27,6 +27,25 @@ describe Gon do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
context 'option locals' do
|
31
|
+
it 'works without locals object properly' do
|
32
|
+
Gon.rabl(
|
33
|
+
:template =>'spec/test_data/sample.rabl',
|
34
|
+
:controller => controller
|
35
|
+
)
|
36
|
+
Gon.objects.map { |it| it['object']['inspect'] }.should == ['1', '2']
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'works with different locals object' do
|
40
|
+
Gon.rabl(
|
41
|
+
:template =>'spec/test_data/sample.rabl',
|
42
|
+
:controller => controller,
|
43
|
+
:locals => { :objects => [3, 4] }
|
44
|
+
)
|
45
|
+
Gon.objects.map { |it| it['object']['inspect'] }.should == ['3', '4']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
30
49
|
it 'works if rabl is included' do
|
31
50
|
Gon.rabl :template =>'spec/test_data/sample.rabl', :controller => controller
|
32
51
|
Gon.objects.length.should == 2
|
data/spec/gon/watch_spec.rb
CHANGED
@@ -54,7 +54,7 @@ describe Gon::Watch do
|
|
54
54
|
controller.params = params
|
55
55
|
Gon::Request.env['action_controller.instance'] = controller
|
56
56
|
|
57
|
-
controller.should_receive('render').with(:
|
57
|
+
controller.should_receive('render').with(:json => 1)
|
58
58
|
|
59
59
|
Gon.watch.a = 1
|
60
60
|
end
|
data/spec/test_data/sample.rabl
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
collection @objects => 'objects'
|
2
|
-
attributes :
|
2
|
+
attributes :inspect
|
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.0.
|
4
|
+
version: 4.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|