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 CHANGED
@@ -2,4 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
-
5
+ .rvmrc
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
- output = rabl_engine.render(controller, {})
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
@@ -1,3 +1,3 @@
1
1
  class Gon
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
data/lib/gon/watch.rb CHANGED
@@ -109,7 +109,7 @@ class Gon
109
109
  def return_variable(value)
110
110
  controller = Gon::Base.get_controller
111
111
 
112
- controller.render :text => value.to_json
112
+ controller.render :json => value
113
113
  end
114
114
 
115
115
  end
@@ -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
@@ -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
@@ -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(:text => '1')
57
+ controller.should_receive('render').with(:json => 1)
58
58
 
59
59
  Gon.watch.a = 1
60
60
  end
@@ -1,2 +1,2 @@
1
1
  collection @objects => 'objects'
2
- attributes :id
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.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-07-24 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack