Skip to content

Commit 83b22e3

Browse files
committed
Js generation
1 parent 12895af commit 83b22e3

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ If you need to send some data to your js files and you don't want to do this wit
99
``` erb
1010
<head>
1111
<title>some title</title>
12-
<%= gon_variables %>
13-
<%= javascript_include_tag 'http://code.jquery.com/jquery-1.6.min.js' %> <!-- include jquery -->
14-
<%= include_gon_js %> <!-- http://gaziev.com/files/gon.js -->
12+
<%= include_gon %>
13+
<!-- include your action js code -->
1514
...
1615
```
1716

lib/gon/helpers.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ def self.included base
55
end
66

77
module InstanceMethods
8-
def include_gon_js
9-
javascript_include_tag 'http://gaziev.com/files/gon.js'
10-
end
11-
12-
def gon_variables
8+
def include_gon
139
data = Rails.cache.read('gon_variables') || {}
1410

15-
'<gon style="display:none">' + data.to_s.gsub('=>', ' : ') +
16-
'</gon>'
11+
script = "<script>function Gon(){"
12+
data.each do |key, val|
13+
script += "this." + key.to_s + "'" + val.to_s + "';"
14+
end
15+
script += "}; var Gon = new Gon()</script>"
16+
script.html_safe
1717
end
1818
end
1919

lib/gon/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Gon
2-
VERSION = '0.1.1'
2+
VERSION = '0.2.0'
33
end

0 commit comments

Comments
 (0)