anychart_xml_builder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.version = "0.0.1"
7
+ gem.version = "0.0.2"
8
8
  gem.name = "anychart_xml_builder"
9
9
  gem.summary = %Q{AnyChart (http://anychart.com/home/) XML Builders}
10
10
  gem.description = %Q{This gem provides you the methods to easily generate the XML necessary for AnyChart}
@@ -13,6 +13,7 @@ begin
13
13
  gem.authors = ["jduarte"]
14
14
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
15
  gem.add_dependency "nokogiri", ">= 1.4.1"
16
+ # gem.add_dependency "activesupport", ">= 2.3.5"
16
17
 
17
18
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
19
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{anychart_xml_builder}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jduarte"]
12
- s.date = %q{2010-02-19}
12
+ s.date = %q{2010-02-22}
13
13
  s.description = %q{This gem provides you the methods to easily generate the XML necessary for AnyChart}
14
14
  s.email = %q{jose.fduarte@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -24,8 +24,10 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "anychart_xml_builder.gemspec",
27
+ "lib/anychart/view_helpers.rb",
27
28
  "lib/anychart_xml_builder.rb",
28
29
  "lib/column_bar.rb",
30
+ "lib/init.rb",
29
31
  "test/helper.rb",
30
32
  "test/test_anychart_xml_builder.rb",
31
33
  "test/xml/sample_71.rb"
@@ -0,0 +1,61 @@
1
+ module Anychart
2
+
3
+ module ViewHelpers
4
+
5
+ @@default_options = {
6
+ :anychart_swf_path => '/anychart_swfs/AnyChart.swf',
7
+ :anychart_swf_preloader => '/anychart_swfs/Preloader.swf',
8
+ :div_id => 'anychart'
9
+ }
10
+
11
+ def anychart(xml, options={})
12
+ opts = @@default_options.merge(options)
13
+ "<div id='#{opts[:div_id]}'>
14
+ <noscript>
15
+ <object id='chart'
16
+ name='chart'
17
+ classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
18
+ width='100%'
19
+ height='100%'
20
+ codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'>
21
+ <param name='movie' value='#{opts[:anychart_swf_preloader]}' />
22
+ <param name='bgcolor' value='#FFFFFF' />
23
+ <param name='allowScriptAccess' value='always' />
24
+ <param name='flashvars' value='swfFile=#{opts[:anychart_swf_path]}&XMLFile=#{xml}' />
25
+
26
+ <embed type='application/x-shockwave-flash'
27
+ pluginspage='http://www.adobe.com/go/getflashplayer'
28
+ src='#{opts[:anychart_swf_preloader]}'
29
+ width='100%'
30
+ height='100%'
31
+ id='chart'
32
+ name='chart'
33
+ bgColor='#FFFFFF'
34
+ allowScriptAccess='always'
35
+ flashvars='swfFile=#{opts[:anychart_swf_path]}&XMLFile=#{xml}' />
36
+ </object>
37
+ </noscript>
38
+ <script type='text/javascript'>
39
+ //<![CDATA[
40
+ document.write('<center>');
41
+ document.write('You need to have Adobe Flash Player 9 (or above) to view the chart.<br /><br />');
42
+ document.write('<a href=\'http://www.adobe.com/go/getflashplayer\'><img border=\'0\' src=\'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\' /></a><br />');
43
+ document.write('</center>');
44
+ //]]>
45
+ </script>
46
+
47
+ <script type='text/javascript' language='JavaScript'>
48
+ //<![CDATA[
49
+ var chartSample = new AnyChart('#{opts[:anychart_swf_path]}','#{opts[:anychart_swf_preloader]}');
50
+ chartSample.width = '100%';
51
+ chartSample.height = '100%';
52
+ chartSample.setXMLFile('#{xml}');
53
+ chartSample.write('#{opts[:div_id]}');
54
+ //init();
55
+ //]]>
56
+ </script>
57
+ </div>"
58
+ end
59
+ end
60
+
61
+ end
@@ -1,8 +1,33 @@
1
1
  require 'nokogiri'
2
2
  require 'column_bar'
3
+ require 'activesupport'
3
4
 
4
5
  module Anychart
6
+
7
+ class << self
8
+ def enable
9
+ enable_actionpack
10
+ end
11
+
12
+ # hooks Anychart::ViewHelpers into ActionView::Base
13
+ def enable_actionpack
14
+ def enable_actionpack
15
+ return if ActionView::Base.instance_methods.include_method? :anychart
16
+ require 'anychart/view_helpers'
17
+ ActionView::Base.send :include, ViewHelpers
18
+
19
+ if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
20
+ ActionController::Base.rescue_responses['Anychart::InvalidPage'] = :not_found
21
+ end
22
+ end
23
+ end
24
+ end
25
+
5
26
  module XML
6
27
 
7
28
  end
29
+ end
30
+
31
+ if defined? Rails
32
+ Anychart.enable_actionpack if defined? ActionController
8
33
  end
data/lib/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'anychart'
@@ -3,28 +3,29 @@ require 'xml/sample_71'
3
3
 
4
4
  class TestAnychartXmlBuilder < Test::Unit::TestCase
5
5
  should "create valid XML file like anychart/gallery/sample_71.xml" do
6
- assert_equal(Sample71.xml.gsub(/>[ \t\r\n]+</, '><'), Anychart::XML::ColumnBar.xml(:tooltip => "{%Name} - {%YValue}",
7
- :chart => {
8
- :title => "Multi-Series: with Simple Legend",
9
- :legend => "{%Icon} {%Name} ({%Value})",
10
- :axes => {
11
- :y => "{%Value}{numDecimals:0}"
12
- }
13
- },
14
- :data => {
15
- :series => [
16
- {:name => "Series 1",
17
- :points => [ {:name => "P1", :value => "12"},
18
- {:name => "P2", :value => "24"}
19
- ]
20
- },
21
- {:name => "Series 2",
22
- :points => [ {:name => "P1", :value => "23"},
23
- {:name => "P2", :value => "45"}
6
+ options = {:tooltip => "{%Name} - {%YValue}",
7
+ :chart => {
8
+ :title => "Multi-Series: with Simple Legend",
9
+ :legend => "{%Icon} {%Name} ({%Value})",
10
+ :axes => {
11
+ :y => "{%Value}{numDecimals:0}"
12
+ }
13
+ },
14
+ :data => {
15
+ :series => [
16
+ {:name => "Series 1",
17
+ :points => [ {:name => "P1", :value => "12"},
18
+ {:name => "P2", :value => "24"}
24
19
  ]
25
- }
26
- ]
27
- }
28
- ))
20
+ },
21
+ {:name => "Series 2",
22
+ :points => [ {:name => "P1", :value => "23"},
23
+ {:name => "P2", :value => "45"}
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ }
29
+ assert_equal(Sample71.xml.gsub(/>[ \t\r\n]+</, '><'), Anychart::XML::ColumnBar.xml(options))
29
30
  end
30
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anychart_xml_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jduarte
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-19 00:00:00 +00:00
12
+ date: 2010-02-22 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,8 +49,10 @@ files:
49
49
  - README.rdoc
50
50
  - Rakefile
51
51
  - anychart_xml_builder.gemspec
52
+ - lib/anychart/view_helpers.rb
52
53
  - lib/anychart_xml_builder.rb
53
54
  - lib/column_bar.rb
55
+ - lib/init.rb
54
56
  - test/helper.rb
55
57
  - test/test_anychart_xml_builder.rb
56
58
  - test/xml/sample_71.rb