rgviz-rails 0.51 → 0.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rgviz_rails/view_helper.rb +22 -37
  2. metadata +3 -3
@@ -1,35 +1,12 @@
1
1
  module Rgviz
2
2
  module ViewHelper
3
3
  def rgviz(options = {})
4
- def opts_to_json(opts, special_keys)
5
- @s = '{'
6
- i = 0
7
- opts.each do |key, value|
8
- key = key.to_s.gsub('"', '\"')
9
-
10
- @s << ',' if i > 0
11
- @s << "\"#{key}\":"
12
- if value.kind_of? Array
13
- @s << '['
14
- value.each_with_index do |val, i|
15
- @s << ',' if i > 0
16
- if val.kind_of? String
17
- val = val.gsub('"', '\"')
18
- @s << "\"#{val}\""
19
- else
20
- @s << val.to_s
21
- end
22
- end
23
- @s << ']'
24
- elsif special_keys.include?(key) || !value.kind_of?(String)
25
- @s << value.to_s
26
- else
27
- value = value.gsub('"', '\"')
28
- @s << "\"#{value}\""
29
- end
30
- i += 1
4
+ def get_package(name)
5
+ down = name.downcase
6
+ case down
7
+ when 'gauge', 'geochart', 'table', 'treemap' then down
8
+ else 'corechart'
31
9
  end
32
- @s << '}'
33
10
  end
34
11
 
35
12
  options = options.with_indifferent_access
@@ -66,29 +43,37 @@ module Rgviz
66
43
 
67
44
  visitor = MagicNamesVisitor.new(html_prefix, js_prefix, param_prefix)
68
45
 
69
- special_keys = []
70
-
71
46
  opts.each do |key, value|
72
47
  next unless value.kind_of?(String)
73
48
 
74
49
  source = visitor.get_source(value, false)
75
50
  next unless source[:source]
76
51
 
77
- special_keys << key
78
-
79
52
  case source[:source]
80
53
  when :html
81
- opts[key] = "rgviz_get_value('#{source[:id]}')"
54
+ s = "rgviz_get_value('#{source[:id]}')"
55
+ def s.encode_json(options = {})
56
+ self
57
+ end
58
+ opts[key] = s
82
59
  uses_rgviz_get_value = true
83
60
  when :js
84
- opts[key] = "#{source[:id]}()"
61
+ s = "#{source[:id]}()"
62
+ def s.encode_json(options = {})
63
+ self
64
+ end
65
+ opts[key] = s
85
66
  when :param
86
- opts[key] = "param_#{source[:id]}"
67
+ s = "param_#{source[:id]}"
68
+ def s.encode_json(options = {})
69
+ self
70
+ end
71
+ opts[key] = s
87
72
  params << source[:id].to_i unless params.include?(source[:id])
88
73
  end
89
74
  end
90
75
 
91
- opts = opts_to_json(opts, special_keys)
76
+ opts = opts.to_json
92
77
 
93
78
  raise "Must specify an :id" unless id
94
79
  raise "Must specify a :kind" unless kind
@@ -161,7 +146,7 @@ module Rgviz
161
146
  end
162
147
 
163
148
  # Load visualizations and the package, if not already loaded
164
- pack = kind.downcase
149
+ pack = get_package kind
165
150
  @packages ||= []
166
151
  unless @packages.include?(pack)
167
152
  out << "google.load(\"visualization\", \"1\", {'packages':['#{pack}']});\n"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.51'
4
+ version: '0.52'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgviz
16
- requirement: &70132136604300 !ruby/object:Gem::Requirement
16
+ requirement: &70279841786980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70132136604300
24
+ version_requirements: *70279841786980
25
25
  description:
26
26
  email: aborenszweig@manas.com.ar
27
27
  executables: []