gon 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gon might be problematic. Click here for more details.
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/gon/base.rb +27 -13
- data/lib/gon/escaper.rb +1 -1
- data/lib/gon/jbuilder.rb +11 -7
- data/lib/gon/version.rb +1 -1
- data/spec/gon/basic_spec.rb +1 -1
- data/spec/gon/global_spec.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|

|
4
4
|
|
5
|
-
|
5
|
+
[](http://travis-ci.org/gazay/gon) [](https://codeclimate.com/github/gazay/gon)
|
6
6
|
|
7
7
|
If you need to send some data to your js files and you don't want to do this with long way through views and parsing - use this force!
|
8
8
|
|
data/lib/gon/base.rb
CHANGED
@@ -3,24 +3,13 @@ class Gon
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def render_data(options)
|
6
|
-
data = Gon.all_variables || {}
|
7
|
-
if Gon.global.all_variables.present?
|
8
|
-
data[:global] = Gon.global.all_variables
|
9
|
-
end
|
10
6
|
namespace, tag, cameled, watch = parse_options options
|
11
7
|
script = "window.#{namespace} = {};"
|
12
8
|
|
13
|
-
|
14
|
-
if cameled
|
15
|
-
script << "#{namespace}.#{key.to_s.camelize(:lower)}=#{val.to_json};"
|
16
|
-
else
|
17
|
-
script << "#{namespace}.#{key.to_s}=#{val.to_json};"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
script << Gon.watch.render if watch and Gon::Watch.all_variables.present?
|
9
|
+
script << formatted_data(namespace, cameled, watch)
|
22
10
|
script = Gon::Escaper.escape_unicode(script)
|
23
11
|
script = Gon::Escaper.javascript_tag(script) if tag
|
12
|
+
|
24
13
|
script.html_safe
|
25
14
|
end
|
26
15
|
|
@@ -58,6 +47,31 @@ class Gon
|
|
58
47
|
[namespace, tag, cameled, watch]
|
59
48
|
end
|
60
49
|
|
50
|
+
def formatted_data(namespace, keys_cameled, watch)
|
51
|
+
script = ''
|
52
|
+
|
53
|
+
gon_variables.each do |key, val|
|
54
|
+
js_key = keys_cameled ? key.to_s.camelize(:lower) : key.to_s
|
55
|
+
script << "#{namespace}.#{js_key}=#{val.to_json};"
|
56
|
+
end
|
57
|
+
|
58
|
+
if watch and Gon::Watch.all_variables.present?
|
59
|
+
script << Gon.watch.render
|
60
|
+
end
|
61
|
+
|
62
|
+
script
|
63
|
+
end
|
64
|
+
|
65
|
+
def gon_variables
|
66
|
+
data = Gon.all_variables || {}
|
67
|
+
|
68
|
+
if Gon.global.all_variables.present?
|
69
|
+
data[:global] = Gon.global.all_variables
|
70
|
+
end
|
71
|
+
|
72
|
+
data
|
73
|
+
end
|
74
|
+
|
61
75
|
def right_extension?(extension, template_path)
|
62
76
|
File.extname(template_path) == ".#{extension}"
|
63
77
|
end
|
data/lib/gon/escaper.rb
CHANGED
@@ -7,7 +7,7 @@ class Gon
|
|
7
7
|
|
8
8
|
def escape_unicode(javascript)
|
9
9
|
if javascript
|
10
|
-
result = javascript.gsub(/\342\200\250/u, '
')
|
10
|
+
result = javascript.gsub(/\342\200\250/u, '
').gsub(/(<\/)/u, '\u003C/')
|
11
11
|
javascript.html_safe? ? result.html_safe : result
|
12
12
|
else
|
13
13
|
''
|
data/lib/gon/jbuilder.rb
CHANGED
@@ -78,16 +78,20 @@ class Gon
|
|
78
78
|
path = partial_line.match(/['"]([^'"]*)['"]/)[1]
|
79
79
|
path = parse_path path
|
80
80
|
options_hash = partial_line.match(/,(.*)/)[1]
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
self.instance_variable_set('@' + name.to_s, val)
|
85
|
-
eval "def #{name}; self.instance_variable_get('@' + '#{name.to_s}'); end"
|
86
|
-
end
|
87
|
-
end
|
81
|
+
|
82
|
+
set_options_from_hash(options_hash) if options_hash.present?
|
83
|
+
|
88
84
|
find_partials File.readlines(path)
|
89
85
|
end
|
90
86
|
|
87
|
+
def set_options_from_hash(options_hash)
|
88
|
+
options = eval "{#{options_hash}}"
|
89
|
+
options.each do |name, val|
|
90
|
+
self.instance_variable_set("@#{name.to_s}", val)
|
91
|
+
eval "def #{name}; self.instance_variable_get('@' + '#{name.to_s}'); end"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
91
95
|
def parse_path(path)
|
92
96
|
return path if File.exists?(path)
|
93
97
|
|
data/lib/gon/version.rb
CHANGED
data/spec/gon/basic_spec.rb
CHANGED
@@ -102,7 +102,7 @@ describe Gon do
|
|
102
102
|
@base.include_gon.should == '<script type="text/javascript">' +
|
103
103
|
"\n//<![CDATA[\n" +
|
104
104
|
'window.gon = {};' +
|
105
|
-
%q(gon.str="
|
105
|
+
%q(gon.str="\u003C/script><script>alert('!')\u003C/script>";) +
|
106
106
|
"\n//]]>\n" +
|
107
107
|
'</script>'
|
108
108
|
end
|
data/spec/gon/global_spec.rb
CHANGED
@@ -83,7 +83,7 @@ describe Gon::Global do
|
|
83
83
|
@base.include_gon.should == "<script type=\"text/javascript\">" +
|
84
84
|
"\n//<![CDATA[\n" +
|
85
85
|
"window.gon = {};" +
|
86
|
-
"gon.global={\"str\":\"
|
86
|
+
"gon.global={\"str\":\"\\u003C/script><script>alert('!')\\u003C/script>\"};" +
|
87
87
|
"\n//]]>\n" +
|
88
88
|
"</script>"
|
89
89
|
end
|
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: 4.1.
|
4
|
+
version: 4.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04
|
12
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|