gon 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gon might be problematic. Click here for more details.
- data/README.md +21 -3
- data/lib/gon/helpers.rb +6 -6
- data/lib/gon/version.rb +1 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -20,11 +20,20 @@ For camelize your variables in js you can use:
|
|
20
20
|
<head>
|
21
21
|
<title>some title</title>
|
22
22
|
<%= include_gon(:camel_case => true) %>
|
23
|
-
<!-- or just include_gon(true) -->
|
24
23
|
<!-- include your action js code with camelized variables -->
|
25
24
|
...
|
26
25
|
```
|
27
26
|
|
27
|
+
For different namespace of your variables in js you can use:
|
28
|
+
|
29
|
+
``` erb
|
30
|
+
<head>
|
31
|
+
<title>some title</title>
|
32
|
+
<%= include_gon(:namespace => 'serverExports') %>
|
33
|
+
<!-- include your action js code with 'serverExports' namespace -->
|
34
|
+
...
|
35
|
+
```
|
36
|
+
|
28
37
|
In action of your controller you put something like this:
|
29
38
|
|
30
39
|
``` ruby
|
@@ -61,18 +70,27 @@ alert(gon.yourArray)
|
|
61
70
|
alert(gon.yourHash)
|
62
71
|
```
|
63
72
|
|
73
|
+
With custom namespace and camelize:
|
74
|
+
|
75
|
+
``` js
|
76
|
+
alert(customNamespace.yourInt)
|
77
|
+
alert(customNamespace.yourOtherInt)
|
78
|
+
alert(customNamespace.yourArray)
|
79
|
+
alert(customNamespace.yourHash)
|
80
|
+
```
|
81
|
+
|
64
82
|
## Installation
|
65
83
|
|
66
84
|
Puts this line into `Gemfile` then run `$ bundle`:
|
67
85
|
|
68
86
|
``` ruby
|
69
|
-
gem 'gon', '1.1.
|
87
|
+
gem 'gon', '1.1.2'
|
70
88
|
```
|
71
89
|
|
72
90
|
Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
|
73
91
|
|
74
92
|
``` ruby
|
75
|
-
config.gem 'gon', :version => '1.1.
|
93
|
+
config.gem 'gon', :version => '1.1.2'
|
76
94
|
```
|
77
95
|
|
78
96
|
Or manually install gon gem: `$ gem install gon`
|
data/lib/gon/helpers.rb
CHANGED
@@ -5,18 +5,18 @@ module Gon
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module InstanceMethods
|
8
|
-
def include_gon(
|
8
|
+
def include_gon(options = {})
|
9
9
|
if Gon.request_env
|
10
10
|
data = Gon.all_variables
|
11
|
-
|
12
|
-
script = "<script>window.
|
13
|
-
unless camel_case
|
11
|
+
namespace = options[:namespace] || 'gon'
|
12
|
+
script = "<script>window." + namespace + " = {};"
|
13
|
+
unless options[:camel_case]
|
14
14
|
data.each do |key, val|
|
15
|
-
script += "
|
15
|
+
script += namespace + "." + key.to_s + '=' + val.to_json + ";"
|
16
16
|
end
|
17
17
|
else
|
18
18
|
data.each do |key, val|
|
19
|
-
script += "
|
19
|
+
script += namespace + "." + key.to_s.camelize(:lower) + '=' + val.to_json + ";"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
script += "</script>"
|
data/lib/gon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153678100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153678100
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153677680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153677680
|
36
36
|
description: If you need to send some data to your js files and you don't want to
|
37
37
|
do this with long way trough views and parsing - use this force!
|
38
38
|
email:
|