grafico 0.2.3 → 0.2.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/grafico.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{grafico}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Rossmeissl"]
12
- s.date = %q{2010-04-29}
12
+ s.date = %q{2010-07-02}
13
13
  s.description = %q{Rails (2.x - 3.x) view helpers for graphs using Grafico, a javascript graphic library built on Raphael.}
14
14
  s.email = %q{andy@brighterplanet.com}
15
15
  s.extra_rdoc_files = [
@@ -1,18 +1,23 @@
1
1
  module Grafico
2
2
  module Helpers
3
+ GRAPH_TYPES = %w[LineGraph AreaGraph StackGraph StreamGraph BarGraph StackedBarGraph HorizontalBarGraph SparkLine SparkBar]
4
+
3
5
  def graph_tag(graph_type, element, data, options = {})
4
6
  args = []
5
7
  args << data.to_json
6
8
  args << options.to_json unless options.empty?
7
9
  javascript_tag "var #{options[:variable_name] || (element + graph_type)} = new Grafico.#{graph_type}($('#{element}'), #{args.join(',')});"
8
10
  end
9
-
10
- def line_graph_tag(element, data, options = {})
11
- graph_tag 'LineGraph', element, data, options
12
- end
13
11
 
14
- def sparkline_tag(element, data, options = {})
15
- graph_tag 'SparkLine', element, data, options
12
+ def self.included(receiver)
13
+ GRAPH_TYPES.each do |graph|
14
+ receiver.instance_eval do
15
+ define_method(:"#{graph.underscore}_tag") do |e, d, *opts|
16
+ opts = opts.first || Hash.new
17
+ graph_tag(graph, e, d, opts)
18
+ end
19
+ end
20
+ end
16
21
  end
17
22
  end
18
- end
23
+ end
data/test/test_grafico.rb CHANGED
@@ -1,23 +1,21 @@
1
- require 'helper'
2
-
3
- class TestGrafico < Test::Unit::TestCase
4
- def setup
5
- @helper = TestHelper.new
6
- end
7
-
8
- def test_setup
9
- assert_instance_of TestHelper, @helper
10
- end
11
-
12
- def test_graph_tag
13
- assert_equal @helper.graph_tag('FooGraph', 'my_element', [1, 2, 3]), wrap_as_javascript("var my_elementFooGraph = new Grafico.FooGraph($('my_element'), [1,2,3]);")
14
- end
15
-
16
- def test_line_graph_tag
17
- assert_equal @helper.line_graph_tag('my_element', [1, 2, 3]), wrap_as_javascript("var my_elementLineGraph = new Grafico.LineGraph($('my_element'), [1,2,3]);")
18
- end
19
-
20
- def test_sparkline_tag
21
- assert_equal @helper.line_graph_tag('my_element', [1, 2, 3]), wrap_as_javascript("var my_elementSparkLine = new Grafico.SparkLine($('my_element'), [1,2,3]);")
22
- end
23
- end
1
+ require 'helper'
2
+
3
+ class TestGrafico < Test::Unit::TestCase
4
+ def setup
5
+ @helper = TestHelper.new
6
+ end
7
+
8
+ def test_setup
9
+ assert_instance_of TestHelper, @helper
10
+ end
11
+
12
+ def test_graph_tag
13
+ assert_equal @helper.graph_tag('FooGraph', 'my_element', [1, 2, 3]), wrap_as_javascript("var my_elementFooGraph = new Grafico.FooGraph($('my_element'), [1,2,3]);")
14
+ end
15
+
16
+ def test_graph_types
17
+ Grafico::Helpers::GRAPH_TYPES.each do |type|
18
+ assert_equal @helper.send(:"#{type.underscore}_tag", 'my_element', [1, 2, 3]), wrap_as_javascript("var my_element#{type} = new Grafico.#{type}($('my_element'), [1,2,3]);")
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andy Rossmeissl
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-29 00:00:00 -04:00
17
+ date: 2010-07-02 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20