File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed
Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,17 @@ If you need to send some data to your js files and you don't want to do this wit
1414 ...
1515```
1616
17+ For camelize your variables in js you can use:
18+
19+ ``` erb
20+ <head>
21+ <title>some title</title>
22+ <%= include_gon(:camel_case => true) %>
23+ <!-- or just include_gon(true) -->
24+ <!-- include your action js code with camelized variables -->
25+ ...
26+ ```
27+
1728In action of your controller you put something like this:
1829
1930``` ruby
@@ -41,18 +52,27 @@ alert(gon.your_array)
4152alert (gon .your_hash )
4253```
4354
55+ With camelize:
56+
57+ ``` js
58+ alert (gon .yourInt )
59+ alert (gon .yourOtherInt )
60+ alert (gon .yourArray )
61+ alert (gon .yourHash )
62+ ```
63+
4464## Installation
4565
4666Puts this line into ` Gemfile ` then run ` $ bundle ` :
4767
4868``` ruby
49- gem ' gon' , ' 1.1.0 '
69+ gem ' gon' , ' 1.1.1 '
5070```
5171
5272Or if you are old-school Rails 2 developer put this into ` config/environment.rb ` and run ` $ rake gems:install ` :
5373
5474``` ruby
55- config.gem ' gon' , :version => ' 1.1.0 '
75+ config.gem ' gon' , :version => ' 1.1.1 '
5676```
5777
5878Or manually install gon gem: ` $ gem install gon `
Original file line number Diff line number Diff line change @@ -5,13 +5,19 @@ def self.included base
55 end
66
77 module InstanceMethods
8- def include_gon
8+ def include_gon ( camel_case = false )
99 if Gon . request_env
1010 data = Gon . all_variables
1111
1212 script = "<script>window.gon = {};"
13- data . each do |key , val |
14- script += "gon." + key . to_s + '=' + val . to_json + ";"
13+ unless camel_case
14+ data . each do |key , val |
15+ script += "gon." + key . to_s + '=' + val . to_json + ";"
16+ end
17+ else
18+ data . each do |key , val |
19+ script += "gon." + key . to_s . camelize ( :lower ) + '=' + val . to_json + ";"
20+ end
1521 end
1622 script += "</script>"
1723 script . html_safe
Original file line number Diff line number Diff line change 11module Gon
2- VERSION = '1.1.0 '
2+ VERSION = '1.1.1 '
33end
You can’t perform that action at this time.
0 commit comments