google_visualr 2.1.6 → 2.1.7

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_visualr (2.1.6)
4
+ google_visualr (2.1.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -96,6 +96,9 @@ Please submit all feedback, bugs and feature-requests to {GitHub Issues Tracker}
96
96
 
97
97
  = Change Log
98
98
 
99
+ <em>Version 2.1.7</em>
100
+ * {Issue 56}[https://github.com/winston/google_visualr/issues/56] Typecast to proper JSON strings.
101
+
99
102
  <em>Version 2.1.6</em>
100
103
  * {Issue 54}[https://github.com/winston/google_visualr/issues/54] Allow apostrophes in labels.
101
104
  * {Pull Request 55}[https://github.com/winston/google_visualr/pull/55] Added support to accept BigDecimal as number.
@@ -273,7 +273,7 @@ module GoogleVisualr
273
273
 
274
274
  js = "{"
275
275
  js << "v: #{typecast(@v)}"
276
- js << ", f: '#{@f}'" unless @f.nil?
276
+ js << ", f: #{typecast(@f)}" unless @f.nil?
277
277
  js << ", p: #{typecast(@p)}" unless @p.nil?
278
278
  js << "}"
279
279
 
@@ -60,10 +60,10 @@ module GoogleVisualr
60
60
  def to_js
61
61
  super do |js|
62
62
  @ranges.each do |r|
63
- js << "\nformatter.addRange(#{typecast(r[:from])}, #{typecast(r[:to])}, '#{r[:color]}', '#{r[:bgcolor]}');"
63
+ js << "\nformatter.addRange(#{typecast(r[:from])}, #{typecast(r[:to])}, #{typecast(r[:color])}, #{typecast(r[:bgcolor])});"
64
64
  end
65
65
  @gradient_ranges.each do |r|
66
- js << "\nformatter.addGradientRange(#{typecast(r[:from])}, #{typecast(r[:to])}, '#{r[:color]}', '#{r[:fromBgColor]}', '#{r[:toBgColor]}');"
66
+ js << "\nformatter.addGradientRange(#{typecast(r[:from])}, #{typecast(r[:to])}, #{typecast(r[:color])}, #{typecast(r[:fromBgColor])}, #{typecast(r[:toBgColor])});"
67
67
  end
68
68
  end
69
69
  end
@@ -28,7 +28,7 @@ module GoogleVisualr
28
28
  def typecast(value)
29
29
  case
30
30
  when value.is_a?(String)
31
- return "'#{value.gsub(/[']/, '\\\\\'')}'"
31
+ return value.to_json
32
32
  when value.is_a?(Integer) || value.is_a?(Float)
33
33
  return value
34
34
  when value.is_a?(TrueClass) || value.is_a?(FalseClass)
@@ -1,3 +1,3 @@
1
1
  module GoogleVisualr
2
- VERSION = "2.1.6"
2
+ VERSION = "2.1.7"
3
3
  end
@@ -205,7 +205,7 @@ describe GoogleVisualr::DataTable do
205
205
  it "raises an exception if value is not date" do
206
206
  assert_raises_exception(4, 'ABCD')
207
207
  end
208
-
208
+
209
209
  it "accepts BigDecimal as number" do
210
210
  expect {
211
211
  dt.set_cell(0, 1, BigDecimal.new(42))
@@ -258,14 +258,14 @@ describe GoogleVisualr::DataTable do
258
258
  dt.new_column('string', nil, nil, 'interval', 'pattern')
259
259
  dt.add_row(['interval'])
260
260
 
261
- dt.to_js.should == "var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"role\":\"interval\",\"pattern\":\"pattern\"});data_table.addRow([{v: 'interval'}]);"
261
+ dt.to_js.should == "var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"role\":\"interval\",\"pattern\":\"pattern\"});data_table.addRow([{v: \"interval\"}]);"
262
262
  end
263
-
263
+
264
264
  it "escapes labels with apostrophes properly" do
265
265
  dt.new_column('number', 'Winston\'s')
266
266
  dt.add_row([1])
267
267
 
268
- dt.to_js.should == "var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"number\",\"label\":\"Winston's\"});data_table.addRow([{v: 1}]);"
268
+ dt.to_js.should == "var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"number\",\"label\":\"Winston's\"});data_table.addRow([{v: 1}]);"
269
269
  end
270
270
  end
271
271
 
@@ -288,10 +288,10 @@ describe GoogleVisualr::DataTable do
288
288
  end
289
289
 
290
290
  it "initializes with a hash" do
291
- cell = GoogleVisualr::DataTable::Cell.new( { :v => 1, :f => '1.0', :p => {:style => 'border: 1px solid green;'} } )
291
+ cell = GoogleVisualr::DataTable::Cell.new( { :v => 1, :f => "1.0", :p => {:style => "border: 1px solid green;"} } )
292
292
  cell.v.should == 1
293
- cell.f.should == '1.0'
294
- cell.p.should == {:style => 'border: 1px solid green;'}
293
+ cell.f.should == "1.0"
294
+ cell.p.should == {:style => "border: 1px solid green;"}
295
295
  end
296
296
  end
297
297
 
@@ -299,24 +299,29 @@ describe GoogleVisualr::DataTable do
299
299
  context "initialized with a value" do
300
300
  it "returns a json string" do
301
301
  cell = GoogleVisualr::DataTable::Cell.new(1)
302
- cell.to_js.should == '{v: 1}'
302
+ cell.to_js.should == "{v: 1}"
303
303
  end
304
304
 
305
305
  it "returns 'null' when v is nil" do
306
306
  cell = GoogleVisualr::DataTable::Cell.new(nil)
307
- cell.to_js.should == 'null'
307
+ cell.to_js.should == "null"
308
308
  end
309
309
  end
310
310
 
311
311
  context "initialized with a hash" do
312
312
  it "returns a json string when v is present" do
313
- cell = GoogleVisualr::DataTable::Cell.new( { :v => 1, :f => "1.0", :p => {:style => 'border: 1px solid green;'} } )
314
- cell.to_js.should == "{v: 1, f: '1.0', p: {style: 'border: 1px solid green;'}}"
313
+ cell = GoogleVisualr::DataTable::Cell.new( { :v => 1, :f => "1.0", :p => {:style => "border: 1px solid green;"} } )
314
+ cell.to_js.should == "{v: 1, f: \"1.0\", p: {style: \"border: 1px solid green;\"}}"
315
315
  end
316
316
 
317
317
  it "returns a json string when v is nil" do
318
- cell = GoogleVisualr::DataTable::Cell.new( { :v => nil, :f => "-", :p => {:style => 'border: 1px solid red;'} } )
319
- cell.to_js.should == "{v: null, f: '-', p: {style: 'border: 1px solid red;'}}"
318
+ cell = GoogleVisualr::DataTable::Cell.new( { :v => nil, :f => "-", :p => {:style => "border: 1px solid red;"} } )
319
+ cell.to_js.should == "{v: null, f: \"-\", p: {style: \"border: 1px solid red;\"}}"
320
+ end
321
+
322
+ it "returns a valid json string when there are apostrophes in v or f" do
323
+ cell = GoogleVisualr::DataTable::Cell.new( { :v => "I'm \"Winston\"", :f => "Winston<div style='color:red; font-style:italic'>Nice Guy</div>" } )
324
+ cell.to_js.should == "{v: \"I'm \\\"Winston\\\"\", f: \"Winston<div style='color:red; font-style:italic'>Nice Guy</div>\"}"
320
325
  end
321
326
  end
322
327
  end
@@ -50,7 +50,7 @@ describe GoogleVisualr::Formatter do
50
50
  it "works" do
51
51
  formatter = GoogleVisualr::BarFormat.new(:base => 100, :colorNegative => 'red', :colorPositive => 'green', :drawZeroLine => false, :max => 1000, :min => -1000, :showValue => false, :width => '150px')
52
52
  formatter.columns(1)
53
- formatter.to_js.should == "\nvar formatter = new google.visualization.BarFormat({base: 100, colorNegative: 'red', colorPositive: 'green', drawZeroLine: false, max: 1000, min: -1000, showValue: false, width: '150px'});\nformatter.format(data_table, 1);"
53
+ formatter.to_js.should == "\nvar formatter = new google.visualization.BarFormat({base: 100, colorNegative: \"red\", colorPositive: \"green\", drawZeroLine: false, max: 1000, min: -1000, showValue: false, width: \"150px\"});\nformatter.format(data_table, 1);"
54
54
  end
55
55
  end
56
56
  end
@@ -78,7 +78,7 @@ describe GoogleVisualr::Formatter do
78
78
  formatter.add_range(0, 1000, 'red', '#000000')
79
79
  formatter.add_gradient_range(2000, nil, 'blue', '#FFFFFF', '#333333')
80
80
  formatter.columns(1)
81
- formatter.to_js.should == "\nvar formatter = new google.visualization.ColorFormat();\nformatter.addRange(0, 1000, 'red', '#000000');\nformatter.addGradientRange(2000, null, 'blue', '#FFFFFF', '#333333');\nformatter.format(data_table, 1);"
81
+ formatter.to_js.should == "\nvar formatter = new google.visualization.ColorFormat();\nformatter.addRange(0, 1000, \"red\", \"#000000\");\nformatter.addGradientRange(2000, null, \"blue\", \"#FFFFFF\", \"#333333\");\nformatter.format(data_table, 1);"
82
82
  end
83
83
  end
84
84
  end
@@ -88,7 +88,7 @@ describe GoogleVisualr::Formatter do
88
88
  it "works" do
89
89
  formatter = GoogleVisualr::DateFormat.new(:formatType => 'long', :timeZone => 8)
90
90
  formatter.columns(1)
91
- formatter.to_js.should == "\nvar formatter = new google.visualization.DateFormat({formatType: 'long', timeZone: 8});\nformatter.format(data_table, 1);"
91
+ formatter.to_js.should == "\nvar formatter = new google.visualization.DateFormat({formatType: \"long\", timeZone: 8});\nformatter.format(data_table, 1);"
92
92
  end
93
93
  end
94
94
  end
@@ -98,7 +98,7 @@ describe GoogleVisualr::Formatter do
98
98
  it "works" do
99
99
  formatter = GoogleVisualr::NumberFormat.new(:decimalSymbol => '.', :fractionDigits => 4, :groupingSymbol => ',', :negativeColor => 'red', :negativeParens => false, :prefix => 'USD$', :suffix => '-')
100
100
  formatter.columns(1)
101
- formatter.to_js.should == "\nvar formatter = new google.visualization.NumberFormat({decimalSymbol: '.', fractionDigits: 4, groupingSymbol: ',', negativeColor: 'red', negativeParens: false, prefix: 'USD$', suffix: '-'});\nformatter.format(data_table, 1);"
101
+ formatter.to_js.should == "\nvar formatter = new google.visualization.NumberFormat({decimalSymbol: \".\", fractionDigits: 4, groupingSymbol: \",\", negativeColor: \"red\", negativeParens: false, prefix: \"USD$\", suffix: \"-\"});\nformatter.format(data_table, 1);"
102
102
  end
103
103
  end
104
104
  end
@@ -40,7 +40,7 @@ describe "GoogleVisualr::ParamsHelper" do
40
40
  end
41
41
 
42
42
  it "returns string" do
43
- assert_equal("a's", "'a\\'s'")
43
+ assert_equal("I'm \"AWESOME\"", "I'm \"AWESOME\"".to_json)
44
44
  end
45
45
 
46
46
  it "returns number" do
@@ -75,7 +75,7 @@ describe "GoogleVisualr::ParamsHelper" do
75
75
  end
76
76
 
77
77
  it "returns array of strings" do
78
- assert_equal({:colors => ['a', 'b']}, "{colors: ['a','b']}")
78
+ assert_equal({:colors => ['a', 'b']}, "{colors: [\"a\",\"b\"]}")
79
79
  end
80
80
 
81
81
  it "recursively calls js_parameters" do
@@ -20,8 +20,8 @@ end
20
20
  def base_chart_js(div_class="div_class")
21
21
  js = "\n<script type='text/javascript'>"
22
22
  js << "\n google.load('visualization','1', {packages: ['basechart'], callback: function() {"
23
- js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: '2004'}, {v: 1000}, {v: 400}]);data_table.addRow([{v: '2005'}, {v: 1200}, {v: 450}]);data_table.addRow([{v: '2006'}, {v: 1500}, {v: 600}]);data_table.addRow([{v: '2007'}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
24
- js << "\n chart.draw(data_table, {legend: 'Test Chart', width: 800, is3D: true});"
23
+ js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
24
+ js << "\n chart.draw(data_table, {legend: \"Test Chart\", width: 800, is3D: true});"
25
25
  js << "\n }});"
26
26
  js << "\n</script>"
27
27
  end
@@ -29,9 +29,9 @@ end
29
29
  def base_chart_with_listener_js(div_class="div_class")
30
30
  js = "\n<script type='text/javascript'>"
31
31
  js << "\n google.load('visualization','1', {packages: ['basechart'], callback: function() {"
32
- js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: '2004'}, {v: 1000}, {v: 400}]);data_table.addRow([{v: '2005'}, {v: 1200}, {v: 450}]);data_table.addRow([{v: '2006'}, {v: 1500}, {v: 600}]);data_table.addRow([{v: '2007'}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
32
+ js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
33
33
  js << "\n google.visualization.events.addListener(chart, 'select', function() {test_event(chart);});"
34
- js << "\n chart.draw(data_table, {legend: 'Test Chart', width: 800, is3D: true});"
34
+ js << "\n chart.draw(data_table, {legend: \"Test Chart\", width: 800, is3D: true});"
35
35
  js << "\n }});"
36
36
  js << "\n</script>"
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_visualr
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-19 00:00:00.000000000 Z
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70104206018240 !ruby/object:Gem::Requirement
16
+ requirement: &70327695181240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.5
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70104206018240
24
+ version_requirements: *70327695181240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70104206017740 !ruby/object:Gem::Requirement
27
+ requirement: &70327695180740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.11.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70104206017740
35
+ version_requirements: *70327695180740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70104206017280 !ruby/object:Gem::Requirement
38
+ requirement: &70327695179980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 3.2.8
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70104206017280
46
+ version_requirements: *70327695179980
47
47
  description: This Ruby gem, GoogleVisualr, is a wrapper around the Google Chart Tools
48
48
  that allows anyone to create the same beautiful charts with just Ruby; you don't
49
49
  have to write any JavaScript at all.