gon 2.0.0 → 2.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.

Files changed (5) hide show
  1. data/README.md +44 -23
  2. data/gon.gemspec +1 -1
  3. data/lib/gon.rb +5 -1
  4. data/lib/gon/version.rb +1 -1
  5. metadata +11 -11
data/README.md CHANGED
@@ -5,27 +5,39 @@ If you need to send some data to your js files and you don't want to do this wit
5
5
 
6
6
  Now with [Rabl](https://github.com/nesquena/rabl) support!
7
7
 
8
- ## A example of typical use
8
+ ## An example of typical use
9
9
 
10
10
  When you need to send some start data from your controller to your js
11
- you probably doing something like this:
11
+ you might be doing something like this:
12
12
 
13
- 1. Write this data in controller(presenter/model) in some variable
14
- 2. In view for this action you put this data in some objects by data
13
+ 1. Write this data in controller(presenter/model) to some variable
14
+ 2. In view for this action you put this variable to some objects by data
15
15
  attributes, or write js right in view
16
- 3. Then in js it depends - if you previously write data in data
16
+ 3. Then there can be two ways in js:
17
+ + if you previously wrote data in data
17
18
  attributes - you should parse this attributes and write data to some
18
- js variable. If you write js right in view (many frontenders shame you for
19
+ js variable.
20
+ + if you wrote js right in view (many frontenders would shame you for
19
21
  that) - you just use data from this js - OK.
20
22
  4. You can use your data in your js
21
23
 
22
- And everytime when you need some data from action to js you do this.
24
+ And everytime when you need to send some data from action to js you do this.
23
25
 
24
26
  With gon you configure it firstly - just put in layout one tag, and add
25
- gem line to your Gemfile and do two actions:
27
+ gem line to your Gemfile and do the following:
28
+
29
+ 1. Write variables by
30
+
31
+ ``` ruby
32
+ gon.variable_name = variable_value
33
+ ```
34
+
35
+ 2. In your js you get this by
36
+
37
+ ``` js
38
+ gon.variable_name
39
+ ```
26
40
 
27
- 1. Write variables by gon.variable_name = variable_value
28
- 2. In your js you get this by gon.variable_name
29
41
  3. profit?
30
42
 
31
43
  ## Usage
@@ -107,24 +119,24 @@ alert(customNamespace.yourHash)
107
119
 
108
120
  ## Usage with Rabl
109
121
 
110
- Now you can write your variables assign logic in templates with [Rabl](https://github.com/nesquena/rabl).
111
- How write templates very clearly described in their repo.
122
+ Now you can write your variables assign logic to templates with [Rabl](https://github.com/nesquena/rabl).
123
+ The way of writing Rabl templates is very clearly described in their repo.
112
124
 
113
125
  Profit of using Rabl with gon:
114
126
 
115
127
  1. You can clean your controllers now!
116
128
  2. Clear and easy work with database objects and collections
117
129
  3. All power of Rabl
118
- 4. You still can be lazy and don't use common way to transfer data in js
130
+ 4. You can still be lazy and don't use common way to transfer data in js
119
131
  5. And so on
120
132
 
121
133
  For using gon with Rabl you need to create new Rabl template and map gon
122
134
  to it.
123
135
  For example you have model Post with attributes :title and :body.
124
136
  You want to get all your posts in your js as an Array.
125
- Thats what you need to do:
137
+ That's what you need to do:
126
138
 
127
- 1. Create Rabl template. I preffer creating special directory for
139
+ 1. Create Rabl template. I prefer creating special directory for
128
140
  templates which are not view templates.
129
141
 
130
142
  `app/goners/posts/index.rabl`
@@ -134,7 +146,7 @@ Thats what you need to do:
134
146
  attributes :id, :title, :body
135
147
  ```
136
148
 
137
- 2. After that you need only map this template to gon.
149
+ 2. All you need to do after that is only to map this template to gon.
138
150
 
139
151
  `app/controllers/post_controller.rb#index`
140
152
 
@@ -144,14 +156,23 @@ Thats what you need to do:
144
156
  @posts = Post.all # Rabl works with instance variables of controller
145
157
 
146
158
  gon.rabl 'app/goners/posts/index.rabl'
159
+ # some controller logic
147
160
  end
148
161
  ```
149
162
 
150
- Thats it! In your js now you get gon.posts variable which is Array of
163
+ Thats it! Now you will get in your js gon.posts variable which is Array of
151
164
  post objects with attributes :id, :title and :body.
152
165
 
153
- P.s. If you didn't put include_gon tag in your html head area - it
154
- wouldn't work. You can read about this in common usage above.
166
+ In javascript file for view of this action write call to your variable:
167
+
168
+ ``` js
169
+ alert(gon.posts)
170
+ alert(gon.posts[0])
171
+ alert(gon.posts[0].post.body)
172
+ ```
173
+
174
+ P.s. If you didn't put include_gon tag in your html head area - it
175
+ wouldn't work. You can read about this in common usage above.
155
176
 
156
177
  ### Some tips of usage Rabl with gon:
157
178
 
@@ -169,10 +190,10 @@ collection @posts => 'alias'
169
190
  ....
170
191
  ```
171
192
 
172
- Rabl will return you array and gon by default put it to variable
193
+ Rabl will return you an array and gon by default will put it to variable
173
194
  gon.rabl
174
195
 
175
- Two way how you can change it - using aliases or you can add alias to
196
+ Two ways how you can change it - using aliases or you can add alias to
176
197
  gon mapping method:
177
198
 
178
199
  ``` ruby
@@ -186,13 +207,13 @@ gon.rabl 'path/to/rabl/file', :as => 'alias'
186
207
  Puts this line into `Gemfile` then run `$ bundle`:
187
208
 
188
209
  ``` ruby
189
- gem 'gon', '2.0.0'
210
+ gem 'gon', '2.0.1'
190
211
  ```
191
212
 
192
213
  Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
193
214
 
194
215
  ``` ruby
195
- config.gem 'gon', :version => '2.0.0'
216
+ config.gem 'gon', :version => '2.0.1'
196
217
  ```
197
218
 
198
219
  Or manually install gon gem: `$ gem install gon`
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ['gazay']
10
10
  s.email = ['alex.gaziev@gmail.com']
11
- s.homepage = ""
11
+ s.homepage = "https://github.com/gazay/gon"
12
12
  s.summary = %q{Get your Rails variables in your JS}
13
13
  s.description = %q{If you need to send some data to your js files and you don't want to do this with long way trough views and parsing - use this force!}
14
14
 
data/lib/gon.rb CHANGED
@@ -44,7 +44,11 @@ module Gon
44
44
  end
45
45
 
46
46
  def rabl(view_path, options = {})
47
- rabl_data = Gon::Rabl.parse_rabl(view_path, @request_env['action_controller.instance'])
47
+ rabl_data = Gon::Rabl.parse_rabl(view_path, options[:controller] ||
48
+ @request_env['action_controller.instance'] ||
49
+ @request_env['action_controller.rescue.response'].
50
+ instance_variable_get('@template').
51
+ instance_variable_get('@controller'))
48
52
  if options[:as]
49
53
  set_variable(options[:as].to_s, rabl_data)
50
54
  elsif rabl_data.is_a? Hash
@@ -1,3 +1,3 @@
1
1
  module Gon
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  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: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-07 00:00:00.000000000Z
12
+ date: 2011-11-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &2158488420 !ruby/object:Gem::Requirement
16
+ requirement: &2154717400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2158488420
24
+ version_requirements: *2154717400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rabl
27
- requirement: &2158488000 !ruby/object:Gem::Requirement
27
+ requirement: &2154716980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2158488000
35
+ version_requirements: *2154716980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &2158487540 !ruby/object:Gem::Requirement
38
+ requirement: &2154716520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2158487540
46
+ version_requirements: *2154716520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2158487120 !ruby/object:Gem::Requirement
49
+ requirement: &2154716100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2158487120
57
+ version_requirements: *2154716100
58
58
  description: If you need to send some data to your js files and you don't want to
59
59
  do this with long way trough views and parsing - use this force!
60
60
  email:
@@ -73,7 +73,7 @@ files:
73
73
  - lib/gon/rabl.rb
74
74
  - lib/gon/version.rb
75
75
  - spec/gon/gon_spec.rb
76
- homepage: ''
76
+ homepage: https://github.com/gazay/gon
77
77
  licenses: []
78
78
  post_install_message:
79
79
  rdoc_options: []