reportbuilder 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,12 @@
1
- === 1.1.0 / 2009-03-23
1
+ === 1.1.1 / 2010-03-24
2
+ * Test suite replaces Test::Unit for Test::MiniUnit and Hpricot for Nokogiri
3
+ * Bug fix: rtf generator doesn't accept a ReportBuilder::Image object
4
+ * Improved output for rtf on tables and headers of sections
5
+ * More documentation
6
+
7
+ === 1.1.0 / 2010-03-23
2
8
  * Added rtf support
3
- === 1.0.0 / 2009-03-22
9
+ === 1.0.0 / 2010-03-22
4
10
  Change of API:
5
11
  * Deleted "add_" before methods
6
12
  * Massive use of block after functions, to allow easy creation of reports
data/Manifest.txt CHANGED
@@ -6,9 +6,9 @@ bin/reportbuilder
6
6
  data/reportbuilder.css
7
7
  data/reportbuilder.js
8
8
  data/sheep.jpg
9
+ examples/create_rtf.rb
9
10
  examples/generic_interface.rb
10
11
  examples/images.rb
11
- examples/rtf.rb
12
12
  examples/test.rtf
13
13
  examples/using_a_block.rb
14
14
  lib/reportbuilder.rb
data/README.txt CHANGED
@@ -16,7 +16,10 @@ Report Abstract Interface. Creates text, html and rtf output, based on a common
16
16
  == SYNOPSIS:
17
17
 
18
18
  * Using generic ReportBuilder#add, every object will be parsed
19
- using #report_building_FORMAT, #report_building or #to_s
19
+ using methods
20
+ * report_building_FORMAT
21
+ * report_building or
22
+ * to_s
20
23
 
21
24
  require "reportbuilder"
22
25
  rb=ReportBuilder.new
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
  # -*- ruby -*-
3
3
  $:.unshift(File.dirname(__FILE__)+"/lib")
4
+
4
5
  require 'rubygems'
5
6
  require 'hoe'
6
7
  require 'reportbuilder'
@@ -10,8 +11,8 @@ Hoe.spec 'reportbuilder' do
10
11
  self.version=ReportBuilder::VERSION
11
12
  self.rubyforge_name = 'ruby-statsample'
12
13
  self.developer('Claudio Bustos', 'clbustos_at_gmail.com')
13
- self.url = "http://rubyforge.org/projects/ruby-statsample/"
14
- self.extra_deps << ["rtf","~>0.1"]
14
+ self.url = "http://ruby-statsample.rubyforge.org/reportbuilder/"
15
+ self.extra_deps << ["clbustos-rtf","~>0.2.1"]
15
16
  self.extra_dev_deps << ["hpricot", "~>0.8"]
16
17
  end
17
18
 
@@ -1,5 +1,7 @@
1
1
  $:.unshift(File.dirname(__FILE__)+"/../lib")
2
2
  require "reportbuilder"
3
+
4
+
3
5
  rb=ReportBuilder.new do
4
6
  text("First Paragraph")
5
7
  section(:name=>"Section 1") do
@@ -1,5 +1,5 @@
1
1
  $:.unshift(File.dirname(__FILE__)+"/../lib")
2
- require "reportbuilder"
2
+ require "reportbuilder"
3
3
  rb=ReportBuilder.new
4
4
  rb.add(2) # Int#to_s used
5
5
  section=ReportBuilder::Section.new(:name=>"Section 1")
@@ -11,6 +11,7 @@ table.row([2,"Peter"])
11
11
  section.add(table) # Section is a container for other methods
12
12
  rb.add(section) # table have a #report_building method
13
13
  rb.add("Another text") # used directly
14
+
14
15
  rb.name="Text output"
15
16
  puts rb.to_text
16
17
  rb.name="Html output"
data/examples/images.rb CHANGED
@@ -5,4 +5,4 @@ rb=ReportBuilder.new do
5
5
  end
6
6
  rb.name="Text output"
7
7
  puts rb.to_text
8
-
8
+ puts rb.to_rtf
data/examples/test.rtf CHANGED
@@ -1,103 +1,86 @@
1
1
  {\rtf1\ansi\deff0\deflang2057\plain\fs24\fet1
2
2
  {\fonttbl
3
3
  {\f0\froman Times New Roman;}
4
- {\f1\fmodern Courier;}
5
4
  }
6
5
  {\info
7
- {\createim\yr2010\mo3\dy23\hr13\min11}
6
+ {\createim\yr2010\mo3\dy23\hr17\min51}
8
7
  }
9
8
  \paperw11907\paperh16840\margl1800\margr1800\margt1440\margb1440
10
- {\pard
11
- First Paragraph
12
- \par}
13
- {\pard\qc
14
- {\b\f0\fs34
15
- Section 1
9
+ {\*\shppict{\pict\picw128\pich112\bliptag2303101\jpegblip
10
+ ffd8ffe000104a46494600010102001200120000ffdb004300050304040403050404040505050607
11
+ 0c08070707070f0b0b090c110f1212110f111113161c1713141a1511111821181a1d1d1f1f1f1317
12
+ 2224221e241c1e1f1effdb0043010505050706070e08080e1e1411141e1e1e1e1e1e1e1e1e1e1e1e
13
+ 1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1effc0
14
+ 0011080070008003012200021101031101ffc4001c00000105010101000000000000000000000002
15
+ 03040506070801ffc4003b1000020103020403070204030900000000010203000411051206213151
16
+ 134161071422718191a108b1233242521572c11633627382a2d1e1f0ffc4001a0100020301010000
17
+ 00000000000000000003040001050206ffc400211100020201040301010000000000000000000102
18
+ 1103041221311341512291ffda000c03010002110311003f00f65d1506f758d3ace7305cdc849000
19
+ 4a852d8f9e0541838a34b91cabf8f08c6773a641f4f849aadc822c391ab48bca2a2da6a56177b45b
20
+ ddc4ecf9da9bb0c71ff09e7e552aace1a69d319bcbab7b3b769ee6558e3504927a9e59c01d49e5d0
21
+ 73ac06adabde6a1339791d216e421563b401d33dcfad4be33b8925d69e163f040a1507cc024fcf9f
22
+ e055250272b746ae97028c54df6c53b339cbb16380324e7901803ed49a28a18d85145150b27e9bab
23
+ 5f69e9e1db4a047bf79428082797d7cbbd6cf87f564d52d98edd93c7812ae3973e841ec707e5f93c
24
+ f6af3843528ac6ee64b860914a992e4742b923f19fae2bb849a7429a9c11941c92e4dcd15473f146
25
+ 971b854f1e618cee44c01e9f111441c51a5c8e55fc784633b9d320fa7c24d1b72fa67783255ed2f2
26
+ 8a66d2eed6ed37db4f1ca3009dad9233d323cbeb4f57409a6b866727d02c37ed31b291e6ac467d68
27
+ 8f43d357ac05bfcce6afe78848bd70c3a1a88e8c870c3eb5c6d430b3cdaeca6bcd02ca543e08303f
28
+ 910491f506a2a6b1abe8e5e0bc5f79054f84ce73cfbe7a91cfa1f4e95a1a8da85a457b6cd0ca3af3
29
+ 53e6a7bd538fc091cb7c64e51998a0bed68dc5d4b29925450173c81f41e43cfea6ab1d591ca3a956
30
+ 53820f506b67a0db1b5d3523618724b37cf3ff008c57cd4349b4bc6323a94908fe7538cfceb8d96a
31
+ c616a5464d3e8c5d1563368ba8a4bb041bc67932918348ff0009d47c5f0fdd5f39ebcb1f7e95c531
32
+ af243e9068ab16d175112ecf77cf3fe60c314e49a06a2ae15511c7f70718fcd4dacaf2c3e95556fa
33
+ 468b25dac73cadb20604f2ea79f4ab6b0d0ad22850dca09651cd8e4e3ed5637332da5a349b3f8680
34
+ 6428e83d2bb8c3db16c9a9bfcc0660d32c215c25ac67d5c6e3f9a71acacd976b5ac047fcb14ab5ba
35
+ b7ba19b79924f4079fda9ea22484dca57cb33dab6886222eb4edcac8776c04e411e6a6a4f0cebf34
36
+ b711d85f10c48db1ca4e0e7b367ae7a77cf7cd5bd46b9d1a1bb97c5f0da199482255ca907bfa9aad
37
+ b4ed04f2c651db93fa5dd040230464514d5e4deef6935c6ddde146cfb738ce067144134ad99ed4b5
38
+ fb4b7bf7b78e091d63255dc1c7c40f3001eddea35cf1242233eef0485fcb7e001f6359b766776776
39
+ 2ccc72493924f7a4d2ee6cd88e971a4ace81067c08f7733b467ed4ceaf7f6fa569379a9de315b6b3
40
+ 81e79881921114b37e01a9119cc6a479814d5cc56d770cf6570a92c724656589b9ee4604608ec798
41
+ fbd18cd6783b5ffd60fb48b8e247bcd1acf47b2d2964fe0d94b6e652c99e4247dc0938ebb76d7b1b
42
+ d8cf1d5b7b46f66da5717c36dee66ed184f016c88a54628e01f3195241ec4579df5efd16594fc48f
43
+ 3e8dc6cf65a34921616f35978b342b9fe40fbc06f4240f2ce6bd2dc11c19a270870159f05e911cab
44
+ a65adbb400bbe64937125dd88fea66662718193cb02ace15fb382f16feb238474ae26974dd1f86af
45
+ f59d3e094c6f7eb72b10930705a3420ee5ec495cd77ff67dc5da2f1d708d871470fced3585ea164d
46
+ ebb5d1812191c79302083e5cb912306bc25c59fa51f6ada77134d61a1e996dace986522defd2f228
47
+ 86ccf22eaec195b1d400467a135ecafd3d7b3d97d997b2ed3f85eeaee3bbbd577b8bb962cf866573
48
+ 92173cf68181938ce33819c54226ef93a15337cbbeca74ef1b0fc531677f15dea17b6b082459b247
49
+ 23f978854395fa2b21ff00abd2a4dc1c41213e4a7f6aa3b5d980ad3f0c6bae655b0bf669448d88e4
50
+ 6e6413e47b8f5f2f974cbd14ba6d335f2638e48d33aa8000c0000f4a2a3697742f34e82e72a4c880
51
+ b60100374239fae6a4d346134d3a614d5ec3ef16735beedbe2c6c9bb19c646334ed15089d3b3963a
52
+ b23b23a956538208c107b5269fbf956e2fae274042c92b3807a804934c5287a05d726eb4a944da6d
53
+ bc80e731807e6391aa6e2799b4de20d0b53524473dc9d3ae467915941284fa891140ff003b77a7f8
54
+ 46e77dac96cc7e28cee5f91ffdfef50bdabab0e00d52ea3ff7b64897b11ecf0baca3f294c45da323
55
+ 2c76cda3534525183a06539046452aac1857c665552cc40503249f215f6a8bda15cbd9f01ebf751b
56
+ 6d78b4db8643d9bc36c7e7150846f6645a7e10b7d4a407c5d4e596fd89ea44b233a7d90a8f901577
57
+ ac4be0e9770f9c7c040f99e5feb48d02d92cb42d3ece35da905ac7128ec15401fb557f17dc85822b
58
+ 5079b9dedf21d3f3fb5549d209863ba69199a28a297360e8fc3f6ed6ba35b42f9dc1371057041639
59
+ c63d338a9d51b4a667d2ed1dd8b334084927249da39d49a697479f9b6e4db0a28a2ace4e69aac22d
60
+ f52b9816331aa4ac154e792e7975f4c545ad3f1ec1124f6b3a2059240c1d87f5636e33f7acc52b25
61
+ 4e8ddc33df05224e9976d657893af303930ee3ceaf38ec25efb3ed796321966d2ee0291eb1362b35
62
+ 561a7dd936b3699382f6d748d111fdbb86323ef5d4255c02d4e1dead766bac94a594087aac6a3f14
63
+ f53375736f6b1892e654863ce37b9c28f99e83eb4f518cd0acf7b4a84dc7b3ee2080757d3a61ff00
64
+ 61ab2bad5ad20bf4d3d4bcf78c037810aee655fee6f251eac467ca9cd6238a6d26ee19d82452c2f1
65
+ b13e41811feb509563f3491dbc0d2c842c68326b0fa8dd3de5dc93bf2dc7e11d8790a99adeaaf7cf
66
+ e1c794814f207ab1ee6aae833959a5a7c3b15bec28a2b49c35a0dd1bbb6bfb811a5baff1154b659b
67
+ 902a463a0c9cf33e58c73c8e526c364c9182b66a74d8de1d3ada1906d748515867a100035228a29a
68
+ 309bb76145145428cf71cda9974e8ee5412607c1e63015b967ee17ef58baea73469342f0c83723a9
69
+ 5619c641e46b05af68b3e9b33322bcb6a79ac98fe5f46ec7f7fc507247d9a5a2ccab632a69703049
70
+ e373d1581fcd228a10f9d0884923c10ae8c3983cc106b3f2ddff00b32b729725e4d3cab496407365
71
+ 6039db8ef9ea83e63c8655c2b7f2484d94ad90ab98c9eb8ed5737bb8420adafbd1560de1e4039072
72
+ 08cf2c838ed4c276acc7c90709532b7846c2e6c348f13512a751ba76b9bc6073f1b73db9eca30a3d
73
+ 16a4f11305d1e7c9ea001f714ca0d4afee54dddbad8d94477786640f24cc3a6ec72551d700927974
74
+ 1906935cd4defa531af28118ed03fabd4d54dd209a7c6e7355e8aca28a2806a8b86379a648635dce
75
+ ec154671927a574eb6856deda281092b1a045cf5c018acef0968822116a7724f8846e850372008c6
76
+ 4e3ae41e9e5f3e9a6a3e38d2b664eb3329c9463e828a28a20985145150814514542183e26d266b2b
77
+ d9678a03ee8e772b28c84cf507039733cbd31eb54d5d51d55d191d432b0c329190476aa4bee18d3a
78
+ e1de488c96ecc0e0211b41e7cf07f60474f2a0cb1fc3470eb525533156f3496f3a4d136d743906b4
79
+ f6bc4368f18f1d5e27f300647d2a1eabc3375690096de4377cf0cab1e187a81939aa27564764752a
80
+ ca70411820f6ae2e50196b1e7568bbd635cf7889a0b456446e4ce79123b0aa2a5c31493482386379
81
+ 1cf4551927e956adc35ab88d18408c5b395122e57e7cf1cfd3353997274bc78555d14f52f49b1935
82
+ 1be4b58cedddcd9b190a0753ff00de78ab2b1e17d466908b9d96c83fa890c4f5e801fdc8eb5acd2b
83
+ 4db5d360315b29cb1cb3b1cb376cfcaae306fb059b55182a8bb64b45545088a155460003000afb45
84
+ 14c190145145421fffd9
85
+ }}
16
86
  }
17
- \par}
18
- {\pard\qc
19
- {\b\f0\fs32
20
- Section 1.1
21
- }
22
- \par}
23
- {\pard
24
- Paragraph inside section 1.1
25
- \par}
26
- \trowd\tgraph100
27
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx400
28
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx1400
29
- \pard\intbl
30
- id
31
- \cell
32
- \pard\intbl
33
- name
34
- \cell
35
- \row
36
- \trowd\tgraph100
37
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx400
38
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx1400
39
- \pard\intbl
40
- 1
41
- \cell
42
- \pard\intbl
43
- John
44
- \cell
45
- \row
46
- \trowd\tgraph100
47
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx400
48
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx1400
49
- \pard\intbl
50
- 2
51
- \cell
52
- \pard\intbl
53
- Peter
54
- \cell
55
- \row
56
- \trowd\tgraph100
57
- \clbrdrt\brdrw25\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx400
58
- \clbrdrt\brdrw25\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx1400
59
- \pard\intbl
60
- 3
61
- \cell
62
- \pard\intbl
63
- John
64
- \cell
65
- \row
66
- \trowd\tgraph100
67
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx400
68
- \clbrdrt\brdrw3\brdrs\clbrdrl\brdrw3\brdrs\clbrdrb\brdrw3\brdrs\clbrdrr\brdrw3\brdrs\cellx1400
69
- \pard\intbl
70
- 4
71
- \cell
72
- \pard\intbl
73
- Peter
74
- \cell
75
- \row
76
- {\pard\ql
77
- {\f1\fs20
78
- def test_generate
79
- {\line}
80
- html=ReportBuilder.generate(:format=>:html, :name=>@title, :directory=>@tmpdir) do
81
- {\line}
82
- text("hola")
83
- {\line}
84
- end
85
- {\line}
86
- doc=Hpricot(html)
87
- {\line}
88
- assert_equal(@title, doc.search("head/title").inner_html)
89
- {\line}
90
- assert_equal(@title, doc.search("body/h1").inner_html)
91
- {\line}
92
- assert_equal("hola", doc.search("body/p").inner_html)
93
- {\line}
94
-
95
- {\line}
96
- end
97
- {\line}
98
- }
99
- \par}
100
- {\pard
101
- Last paragraph
102
- \par}
103
- }
data/lib/reportbuilder.rb CHANGED
@@ -50,8 +50,7 @@ class ReportBuilder
50
50
  attr_accessor :name
51
51
  # Doesn't print a title if set to true
52
52
  attr_accessor :no_title
53
-
54
- VERSION = '1.1.0'
53
+ VERSION = '1.1.1'
55
54
  # Generates and optionally save the report on one function
56
55
  def self.generate(options=Hash.new, &block)
57
56
  options[:filename]||=nil
@@ -64,10 +63,10 @@ class ReportBuilder
64
63
  file=options.delete(:filename)
65
64
  format=options.delete(:format).to_s
66
65
  format[0]=format[0,1].upcase
67
-
68
-
69
66
  rb=ReportBuilder.new(options)
67
+
70
68
  rb.add(block)
69
+
71
70
  generator=Generator.const_get(format.to_sym).new(rb, options)
72
71
  generator.parse
73
72
  out=generator.out
@@ -103,7 +102,7 @@ class ReportBuilder
103
102
  end
104
103
  # Returns a RTF output
105
104
  def to_rtf()
106
- gen = Generator::Rtf.new(self,@options)
105
+ gen = Generator::Rtf.new(self, @options)
107
106
  gen.parse
108
107
  gen.out
109
108
  end
@@ -1,7 +1,8 @@
1
1
  class ReportBuilder
2
2
  # Abstract class for generators.
3
3
  # A generator is a class which control the output for a ReportBuilder object
4
- #
4
+ # Every object which have a #report_building() method could be
5
+ # parsed with #parse_element method.
5
6
  class Generator
6
7
  # Level of heading. See ReportBuilder::Section for using it.
7
8
  attr_reader :parse_level
@@ -51,7 +52,7 @@ class ReportBuilder
51
52
  def parse_element(element)
52
53
  method=("report_building_" + self.class::PREFIX).intern
53
54
  if element.is_a? Proc
54
- element.arity==0 ? instance_eval(&element) : element.call(self)
55
+ element.arity<1 ? instance_eval(&element) : element.call(self)
55
56
  elsif element.respond_to? method
56
57
  element.send(method, self)
57
58
  elsif element.respond_to? :report_building
@@ -1,10 +1,16 @@
1
+ gem 'clbustos-rtf'
1
2
  require 'rtf'
3
+
2
4
  class ReportBuilder
3
5
  class Generator
6
+ # Rtf Generator.
7
+ # Based on ruby-rtf (http://ruby-rtf.rubyforge.org/)
8
+ #
4
9
  class Rtf < Generator
5
10
  PREFIX="rtf"
11
+ # RTF::Document object.
12
+ # See http://ruby-rtf.rubyforge.org/ for documentation
6
13
  attr_accessor :rtf
7
- attr_reader :options
8
14
  include RTF
9
15
  def initialize(builder, options)
10
16
  super
@@ -26,8 +32,7 @@ class ReportBuilder
26
32
  ps=ParagraphStyle.new
27
33
  ps.justification = ParagraphStyle::CENTER_JUSTIFY
28
34
  h[k]={:cs=>cs, :ps=>ps}
29
- }
30
-
35
+ }
31
36
  end
32
37
  def default_options
33
38
 
@@ -48,7 +53,9 @@ class ReportBuilder
48
53
  def header(level,t)
49
54
  @rtf.paragraph(@header_styles[level][:ps]) do |n1|
50
55
  n1.apply(@header_styles[level][:cs]) do |n2|
56
+ n2.line_break
51
57
  n2 << t
58
+ n2.line_break
52
59
  end
53
60
  end
54
61
  end
@@ -63,6 +70,7 @@ class ReportBuilder
63
70
  end
64
71
 
65
72
  end
73
+
66
74
  def out
67
75
  @rtf.to_rtf
68
76
  end
@@ -70,6 +78,9 @@ class ReportBuilder
70
78
  File.open(filename,'wb') {|file| file.write(@rtf.to_rtf)
71
79
  }
72
80
  end
81
+ def html(t)
82
+ # Nothing
83
+ end
73
84
  end
74
85
  end
75
86
  end
@@ -71,7 +71,10 @@ class ReportBuilder::Image
71
71
  out+= border
72
72
  generator.preformatted(out)
73
73
  end
74
-
74
+ def report_building_rtf(generator)
75
+ raise "Not implemented on RTF::Document. Use gem install thecrisoshow-ruby-rtf for support" unless generator.rtf.respond_to? :image
76
+ generator.rtf.image(@filename)
77
+ end
75
78
  def report_building_html(generator)
76
79
  basedir=generator.directory+"/images"
77
80
  out=basedir+"/"+File.basename(@filename)
@@ -34,7 +34,7 @@ class ReportBuilder::Section
34
34
  def report_building_html(g)
35
35
  htag="h#{g.parse_level+1}"
36
36
  anchor=g.toc_entry(name)
37
- generator.html "<div class='section'><#{htag}>#{name}</#{htag}><a name='#{anchor}'></a>"
37
+ g.html "<div class='section'><#{htag}>#{name}</#{htag}><a name='#{anchor}'></a>"
38
38
  g.parse_cycle(self)
39
39
  g.html "</div>"
40
40
  end
@@ -5,6 +5,11 @@ class ReportBuilder
5
5
  def generate()
6
6
  @t=@element
7
7
  @rtf=@generator.rtf
8
+
9
+ # Title
10
+
11
+ @generator.header(6,@t.name)
12
+
8
13
  max_cols=@t.calculate_widths
9
14
  n_rows=@t.n_rows_no_hr+(@t.header.size>0 ? 1: 0)
10
15
  args=[n_rows, @t.n_columns]+max_cols.map{|m| m*@generator.options[:font_size]*10}
data/test/test_html.rb CHANGED
@@ -1,11 +1,12 @@
1
- require "test/unit"
1
+ require "minitest/unit"
2
2
  $:.unshift(File.dirname(__FILE__)+"/../lib")
3
3
  require "reportbuilder"
4
4
  require 'fileutils'
5
5
  require 'tmpdir'
6
- require 'hpricot'
6
+ require 'nokogiri'
7
7
  require 'tempfile'
8
- class TestReportbuilderHtml < Test::Unit::TestCase
8
+ MiniTest::Unit.autorun
9
+ class TestReportbuilderHtml < MiniTest::Unit::TestCase
9
10
  def setup
10
11
  @tmpdir=Dir::mktmpdir
11
12
  @title="Test #{rand(100)}"
@@ -16,20 +17,20 @@ class TestReportbuilderHtml < Test::Unit::TestCase
16
17
  FileUtils.remove_entry_secure @tmpdir
17
18
  end
18
19
  def test_empty_document
19
- doc=Hpricot(@rp.to_html)
20
- assert_equal(@title, doc.search("head/title").inner_html)
21
- assert_equal(@title, doc.search("body/h1").inner_html)
22
- assert_match(/^\s+$/, doc.search("body").inner_html.gsub(/<h1>.+<\/h1>/,""))
20
+ doc=Nokogiri::HTML(@rp.to_html)
21
+ assert_equal(@title, doc.at_xpath("/html/head/title").content)
22
+ assert_equal(@title, doc.at_xpath("/html/body/h1").content)
23
+ assert_match("", doc.at_xpath("/html/body").to_s.gsub(/<h1>.+<\/h1>|<\/?body>/,""))
23
24
 
24
25
  end
25
26
  def test_generate
26
27
  html=ReportBuilder.generate(:format=>:html, :name=>@title, :directory=>@tmpdir) do
27
28
  text("hola")
28
29
  end
29
- doc=Hpricot(html)
30
- assert_equal(@title, doc.search("head/title").inner_html)
31
- assert_equal(@title, doc.search("body/h1").inner_html)
32
- assert_equal("hola", doc.search("body/p").inner_html)
30
+ doc=Nokogiri::HTML(html)
31
+ assert_equal(@title, doc.at_xpath("/html/head/title").inner_html)
32
+ assert_equal(@title, doc.at_xpath("/html/body/h1").inner_html)
33
+ assert_equal("hola", doc.at_xpath("/html/body/p").inner_html)
33
34
 
34
35
  end
35
36
  def test_include_js
data/test/test_image.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  $:.unshift(File.dirname(__FILE__)+"/../lib")
2
- require 'test/unit'
2
+ require 'minitest/unit'
3
3
  require 'tmpdir'
4
4
  require "reportbuilder"
5
- class TestReportbuilderImage < Test::Unit::TestCase
5
+ MiniTest::Unit.autorun
6
+ class TestReportbuilderImage < MiniTest::Unit::TestCase
6
7
  def setup
7
8
  @tmpdir=Dir::mktmpdir
8
9
  @rp=ReportBuilder.new(:no_name=>true, :directory=>@tmpdir)
@@ -39,5 +40,7 @@ Test
39
40
  def test_image_html
40
41
  assert_match(/img src='images\/sheep.jpg'/, @rp.to_html)
41
42
  end
42
-
43
+ def test_image_rtf
44
+ assert_match(/\\pict\\picw128\\pich112\\bliptag2403101\\jpegblip/, @rp.to_rtf)
45
+ end
43
46
  end
@@ -1,13 +1,24 @@
1
- require "test/unit"
1
+ require "minitest/unit"
2
2
  $:.unshift(File.dirname(__FILE__)+"/../lib")
3
3
  require "reportbuilder"
4
- require 'hpricot'
5
4
  require 'tempfile'
6
- class TestReportbuilder < Test::Unit::TestCase
5
+ MiniTest::Unit.autorun
6
+ class TestReportbuilder < MiniTest::Unit::TestCase
7
7
  def setup
8
8
  @datadir=File.dirname(__FILE__)+"/../data"
9
9
  @image=@datadir+"/sheep.jpg"
10
10
  end
11
+ def assert_nothing_raised(msg=nil)
12
+ msg||="Nothing should be raised, but raised %s"
13
+ begin
14
+ yield
15
+ not_raised=true
16
+ rescue Exception => e
17
+ not_raised=false
18
+ msg=sprintf(msg,e)
19
+ end
20
+ assert(not_raised,msg)
21
+ end
11
22
  # adding basic object
12
23
  def test_basic_generators
13
24
  # basic_classes = Array,String,Integer, Float,Time,Hash
@@ -63,7 +74,7 @@ class TestReportbuilder < Test::Unit::TestCase
63
74
  assert_equal("hola\n",rp.to_s)
64
75
  end
65
76
  def test_generate
66
- res=ReportBuilder.generate(:format=>:text,:name=>"Test") do
77
+ res=ReportBuilder.generate(:format=>:text,:name=>"Test") do
67
78
  text("hola")
68
79
  end
69
80
  assert_match(/^Test\nhola$/,res)
@@ -71,7 +82,7 @@ class TestReportbuilder < Test::Unit::TestCase
71
82
  html=ReportBuilder.generate(:name=>"Test", :format=>:html) do
72
83
  text("hola")
73
84
  end
74
- ReportBuilder.generate(:name=>"Test", :filename=>html_file,:format=>:html) do
85
+ ReportBuilder.generate(:name=>"Test", :filename=>html_file.path,:format=>:html) do
75
86
  text("hola")
76
87
  end
77
88
 
data/test/test_section.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "test/unit"
1
+ require "minitest/unit"
2
2
  $:.unshift(File.dirname(__FILE__)+"/../lib")
3
3
  require "reportbuilder"
4
- require 'hpricot'
5
-
6
- class TestReportbuilderSection < Test::Unit::TestCase
4
+ require 'nokogiri'
5
+ MiniTest::Unit.autorun
6
+ class TestReportbuilderSection < MiniTest::Unit::TestCase
7
7
  def setup
8
8
  @name="Test Section"
9
9
  @rp=ReportBuilder.new(:name=>"Test Section")
@@ -50,20 +50,21 @@ Test Section
50
50
  def test_section_html
51
51
  real=@rp.to_html
52
52
  #puts real
53
- doc = Hpricot(real)
53
+ base = Nokogiri::HTML(real)
54
54
  # Sanity
55
- assert_equal("Test Section", doc.search("head/title").inner_html)
55
+ doc=base.at_xpath("/html")
56
+ assert_equal("Test Section", doc.at_xpath("head/title").content)
56
57
  # Test toc
57
- base_ul=doc.search("/html/body/div[@id='toc']")
58
- assert(base_ul!="")
59
- #puts base_ul
58
+ base_ul=doc.at_xpath("/html/body/div[@id='toc']/ul")
59
+ assert(base_ul,"Toc have something")
60
60
  [
61
61
  ["li/a[@href='#toc_1']","Section 1"],
62
- ["li/a[@href='#toc_2']","Section 1.1"],
63
- ["li/a[@href='#toc_3']","Section 1.1.1"],
62
+ ["ul/li/a[@href='#toc_2']","Section 1.1"],
63
+ ["ul/ul/li/a[@href='#toc_3']","Section 1.1.1"],
64
64
  ["li/a[@href='#toc_4']","Section 2"]].each do |path, expected|
65
- inner=base_ul.search(path).inner_html
66
- assert_equal(expected, inner, "On #{path}")
65
+ assert(inner=base_ul.at_xpath(path),"#{path} should return something")
66
+ content=inner.content
67
+ assert_equal(expected, content, "On #{path}")
67
68
  end
68
69
 
69
70
  [
@@ -71,8 +72,8 @@ Test Section
71
72
  ["div[class='section']/h3",["Section 1.1"]],
72
73
  ["div[class='section']/h4",["Section 1.1.1"]]
73
74
  ].each do |path, expected|
74
- base_ul.search(path).each do |el|
75
- assert_equal(expected, el.inner_html, "On #{path} #{el}")
75
+ base_ul.xpath(path).each do |el|
76
+ assert_equal(expected, el.content, "On #{path} #{el}")
76
77
  end
77
78
  end
78
79
  end
data/test/test_table.rb CHANGED
@@ -1,11 +1,12 @@
1
- require "test/unit"
1
+ require "minitest/unit"
2
2
  $:.unshift(File.dirname(__FILE__)+"/../lib")
3
3
  require "reportbuilder"
4
4
  require 'reportbuilder/table/htmlgenerator'
5
5
  require 'reportbuilder/table/textgenerator'
6
- require 'hpricot'
6
+ require 'nokogiri'
7
7
 
8
- class TestReportbuilderTable < Test::Unit::TestCase
8
+ MiniTest::Unit.autorun
9
+ class TestReportbuilderTable < MiniTest::Unit::TestCase
9
10
  def setup
10
11
  super
11
12
  @name="Table Test"
@@ -98,11 +99,12 @@ HEREDOC
98
99
  </table>
99
100
  HEREDOC
100
101
 
101
- doc=Hpricot(@mock_generator)
102
+ doc=Nokogiri::HTML(@mock_generator).at_xpath("/html")
102
103
 
103
- assert(doc.search("a[@name='MOCK']")!="")
104
- assert(doc.search("table"!=""))
105
- assert_equal(@header, doc.search("table/thead/th").map {|m| m.inner_html} )
104
+ assert(doc.at_xpath("a[@name='MOCK']")!="")
105
+ assert(doc.at_xpath("table")!="")
106
+
107
+ assert_equal(@header, doc.xpath("//table/thead/th").map {|m| m.content} )
106
108
  [[2,%w{a}],
107
109
  [3,%w{a f}],
108
110
  [4,%w{a}],
@@ -110,7 +112,7 @@ HEREDOC
110
112
  [6,%w{a}],
111
113
 
112
114
  ].each do |m,exp|
113
- real=doc.search("table/tbody/tr/td[@colspan='#{m}']").map {|x| x.inner_html}
115
+ real=doc.xpath("//table/tbody/tr/td[@colspan='#{m}']").map {|x| x.inner_html}
114
116
  assert_equal(exp, real, "On table/tbody/tr/td[@colspan='#{m}']"
115
117
  )
116
118
  end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportbuilder
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 0
9
- version: 1.1.0
4
+ version: 1.1.1
10
5
  platform: ruby
11
6
  authors:
12
7
  - Claudio Bustos
@@ -14,77 +9,59 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-03-23 00:00:00 -03:00
12
+ date: 2010-03-24 00:00:00 -03:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
- name: rtf
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ name: clbustos-rtf
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
24
20
  requirements:
25
21
  - - ~>
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 1
30
- version: "0.1"
31
- type: :runtime
32
- version_requirements: *id001
23
+ version: 0.2.1
24
+ version:
33
25
  - !ruby/object:Gem::Dependency
34
26
  name: rubyforge
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
37
30
  requirements:
38
31
  - - ">="
39
32
  - !ruby/object:Gem::Version
40
- segments:
41
- - 2
42
- - 0
43
- - 4
44
33
  version: 2.0.4
45
- type: :development
46
- version_requirements: *id002
34
+ version:
47
35
  - !ruby/object:Gem::Dependency
48
36
  name: gemcutter
49
- prerelease: false
50
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
51
40
  requirements:
52
41
  - - ">="
53
42
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- - 5
57
- - 0
58
43
  version: 0.5.0
59
- type: :development
60
- version_requirements: *id003
44
+ version:
61
45
  - !ruby/object:Gem::Dependency
62
46
  name: hpricot
63
- prerelease: false
64
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
65
50
  requirements:
66
51
  - - ~>
67
52
  - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
- - 8
71
53
  version: "0.8"
72
- type: :development
73
- version_requirements: *id004
54
+ version:
74
55
  - !ruby/object:Gem::Dependency
75
56
  name: hoe
76
- prerelease: false
77
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
78
60
  requirements:
79
61
  - - ">="
80
62
  - !ruby/object:Gem::Version
81
- segments:
82
- - 2
83
- - 5
84
- - 1
85
63
  version: 2.5.1
86
- type: :development
87
- version_requirements: *id005
64
+ version:
88
65
  description: Report Abstract Interface. Creates text, html and rtf output, based on a common framework.
89
66
  email:
90
67
  - clbustos_at_gmail.com
@@ -105,9 +82,9 @@ files:
105
82
  - data/reportbuilder.css
106
83
  - data/reportbuilder.js
107
84
  - data/sheep.jpg
85
+ - examples/create_rtf.rb
108
86
  - examples/generic_interface.rb
109
87
  - examples/images.rb
110
- - examples/rtf.rb
111
88
  - examples/test.rtf
112
89
  - examples/using_a_block.rb
113
90
  - lib/reportbuilder.rb
@@ -127,7 +104,7 @@ files:
127
104
  - test/test_section.rb
128
105
  - test/test_table.rb
129
106
  has_rdoc: true
130
- homepage: http://rubyforge.org/projects/ruby-statsample/
107
+ homepage: http://ruby-statsample.rubyforge.org/reportbuilder/
131
108
  licenses: []
132
109
 
133
110
  post_install_message:
@@ -140,20 +117,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
117
  requirements:
141
118
  - - ">="
142
119
  - !ruby/object:Gem::Version
143
- segments:
144
- - 0
145
120
  version: "0"
121
+ version:
146
122
  required_rubygems_version: !ruby/object:Gem::Requirement
147
123
  requirements:
148
124
  - - ">="
149
125
  - !ruby/object:Gem::Version
150
- segments:
151
- - 0
152
126
  version: "0"
127
+ version:
153
128
  requirements: []
154
129
 
155
130
  rubyforge_project: ruby-statsample
156
- rubygems_version: 1.3.6
131
+ rubygems_version: 1.3.5
157
132
  signing_key:
158
133
  specification_version: 3
159
134
  summary: Report Abstract Interface