Skip to content

Commit

Permalink
Js generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gazay committed May 9, 2011
1 parent 12895af commit 83b22e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -9,9 +9,8 @@ If you need to send some data to your js files and you don't want to do this wit
``` erb
<head>
<title>some title</title>
<%= gon_variables %>
<%= javascript_include_tag 'http://code.jquery.com/jquery-1.6.min.js' %> <!-- include jquery -->
<%= include_gon_js %> <!-- http://gaziev.com/files/gon.js -->
<%= include_gon %>
<!-- include your action js code -->
...
```

Expand Down
14 changes: 7 additions & 7 deletions lib/gon/helpers.rb
Expand Up @@ -5,15 +5,15 @@ def self.included base
end

module InstanceMethods
def include_gon_js
javascript_include_tag 'http://gaziev.com/files/gon.js'
end

def gon_variables
def include_gon
data = Rails.cache.read('gon_variables') || {}

'<gon style="display:none">' + data.to_s.gsub('=>', ' : ') +
'</gon>'
script = "<script>function Gon(){"
data.each do |key, val|
script += "this." + key.to_s + "'" + val.to_s + "';"
end
script += "}; var Gon = new Gon()</script>"
script.html_safe
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/gon/version.rb
@@ -1,3 +1,3 @@
module Gon
VERSION = '0.1.1'
VERSION = '0.2.0'
end

0 comments on commit 83b22e3

Please sign in to comment.