Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 77 lines (51 sloc) 2.497 kb
89df60b Alexey Gaziev Initial commit
authored
1 # Gon gem — get your Rails variables in your js
2
020007b Alexey Gaziev Added description and usage
authored
3 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!
89df60b Alexey Gaziev Initial commit
authored
4
5 ## Usage
6
020007b Alexey Gaziev Added description and usage
authored
7 `app/views/layouts/application.html.erb`
8
9 ``` erb
10 <head>
11 <title>some title</title>
83b22e3 Alexey Gaziev Js generation
authored
12 <%= include_gon %>
13 <!-- include your action js code -->
020007b Alexey Gaziev Added description and usage
authored
14 ...
15 ```
16
17 In action of your controller you put something like this:
18
19 ``` ruby
a4f0807 Alexey Gaziev Added types to description
authored
20 @your_int = 123
21 @your_array = [1,2]
22 @your_hash = {'a' => 1, 'b' => 2}
23 Gon.your_int = @your_int
7287e85 Alexey Gaziev Bump version to 1.0.0
authored
24 Gon.your_other_int = 345 + Gon.your_int
a4f0807 Alexey Gaziev Added types to description
authored
25 Gon.your_array = @your_array
7287e85 Alexey Gaziev Bump version to 1.0.0
authored
26 Gon.your_array << Gon.your_int
a4f0807 Alexey Gaziev Added types to description
authored
27 Gon.your_hash = @your_hash
7287e85 Alexey Gaziev Bump version to 1.0.0
authored
28
29 Gon.all_variables # > {:your_int => 123, :your_other_int => 468, :your_array => [1, 2, 123], :your_hash => {'a' => 1, 'b' => 2}}
30 Gon.your_array # > [1, 2, 123]
31
32 Gon.clear # Gon.all_variables now is {}
020007b Alexey Gaziev Added description and usage
authored
33 ```
34
35 In javascript file for view of this action write call to your variable:
36
37 ``` js
a4f0807 Alexey Gaziev Added types to description
authored
38 alert(Gon.your_int)
39 alert(Gon.your_other_int)
40 alert(Gon.your_array)
41 alert(Gon.your_hash)
020007b Alexey Gaziev Added description and usage
authored
42 ```
89df60b Alexey Gaziev Initial commit
authored
43
44 ## Installation
45
46 Puts this line into `Gemfile` then run `$ bundle`:
47
48 ``` ruby
7287e85 Alexey Gaziev Bump version to 1.0.0
authored
49 gem 'gon', '1.0.0'
89df60b Alexey Gaziev Initial commit
authored
50 ```
51
52 Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
53
54 ``` ruby
7287e85 Alexey Gaziev Bump version to 1.0.0
authored
55 config.gem 'gon', :version => '1.0.0'
89df60b Alexey Gaziev Initial commit
authored
56 ```
57
da310ad Alexey Gaziev Edited README.md via GitHub
authored
58 Or manually install gon gem: `$ gem install gon`
89df60b Alexey Gaziev Initial commit
authored
59
60 ## Contributors
61
62 * @gazay
63
2f1bc0e Alexey Gaziev Edited README.md via GitHub
authored
64 Special thanks to @brainopia, @kossnocorp and @ai.
89df60b Alexey Gaziev Initial commit
authored
65
66 ## License
67
68 The MIT License
69
70 Copyright (c) 2011 gazay
71
72 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
73
74 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
75
76 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.