Permalink
Browse files

Now you can use camelized variables in your JS

  • Loading branch information...
1 parent f1293d1 commit dd4e7e38f11166bfc59af1b371271af0731175c8 @gazay committed Oct 26, 2011
Showing with 32 additions and 6 deletions.
  1. +22 −2 README.md
  2. +9 −3 lib/gon/helpers.rb
  3. +1 −1 lib/gon/version.rb
View
@@ -14,6 +14,17 @@ If you need to send some data to your js files and you don't want to do this wit
...
```
+For camelize your variables in js you can use:
+
+``` erb
+<head>
+ <title>some title</title>
+ <%= include_gon(:camel_case => true) %>
+ <!-- or just include_gon(true) -->
+ <!-- include your action js code with camelized variables -->
+ ...
+```
+
In action of your controller you put something like this:
``` ruby
@@ -41,18 +52,27 @@ alert(gon.your_array)
alert(gon.your_hash)
```
+With camelize:
+
+``` js
+alert(gon.yourInt)
+alert(gon.yourOtherInt)
+alert(gon.yourArray)
+alert(gon.yourHash)
+```
+
## Installation
Puts this line into `Gemfile` then run `$ bundle`:
``` ruby
-gem 'gon', '1.1.0'
+gem 'gon', '1.1.1'
```
Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
``` ruby
-config.gem 'gon', :version => '1.1.0'
+config.gem 'gon', :version => '1.1.1'
```
Or manually install gon gem: `$ gem install gon`
View
@@ -5,13 +5,19 @@ def self.included base
end
module InstanceMethods
- def include_gon
+ def include_gon(camel_case = false)
if Gon.request_env
data = Gon.all_variables
script = "<script>window.gon = {};"
- data.each do |key, val|
- script += "gon." + key.to_s + '=' + val.to_json + ";"
+ unless camel_case
+ data.each do |key, val|
+ script += "gon." + key.to_s + '=' + val.to_json + ";"
+ end
+ else
+ data.each do |key, val|
+ script += "gon." + key.to_s.camelize(:lower) + '=' + val.to_json + ";"
+ end
end
script += "</script>"
script.html_safe
View
@@ -1,3 +1,3 @@
module Gon
- VERSION = '1.1.0'
+ VERSION = '1.1.1'
end

0 comments on commit dd4e7e3

Please sign in to comment.