| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Ruport-util
Revision: 41
Author: sandal
Date: 02 Feb 2008 14:46:08
Changes:Fix for #5, thanks Brian
Files:| ... | ...@@ -1,10 +1,11 @@ | |
| 1 | require "rubygems" | |
| 1 | 2 | require "ruport" |
| 2 | 3 | require "ruport/util" |
| 3 | 4 | |
| 4 | 5 | class SampleReport < Ruport::Report |
| 5 | 6 | include Invoice |
| 6 | 7 | |
| 7 | def generate | |
| 8 | def renderable_data(format) | |
| 8 | 9 | render_invoice do |i| |
| 9 | 10 | i.data = Table("Item Number","Description","Price") { |t| |
| 10 | 11 | t << %w[101 Erlang\ The\ Movie $1000.00] |
| ... | ...@@ -25,4 +26,4 @@ | |
| 25 | 26 | end |
| 26 | 27 | |
| 27 | 28 | a = SampleReport.new |
| 28 | File.open("invoice.pdf","wb") { |f| f << a.generate } | |
| 29 | a.save_as("invoice.pdf") |
| ... | ...@@ -66,13 +66,24 @@ | |
| 66 | 66 | # # explicitly use a file, even if it doesn't end in .sql |
| 67 | 67 | # Ruport::Query.new(:file => "foo") |
| 68 | 68 | # |
| 69 | # # query with parameter substitution | |
| 70 | # Ruport::Query.new("select * from fo where bar=?", :params => [1234]) | |
| 71 | # Ruport::Query.new(:file => "foo", :params => [1234]) | |
| 72 | # | |
| 73 | # # query with parameter substitution (ActiveRecord style) | |
| 74 | # Ruport::Query.new(["select * from fo where bar=?", 1234]) | |
| 75 | # | |
| 69 | 76 | def initialize(sql, options={}) |
| 70 | 77 | if sql.kind_of?(Hash) |
| 71 | 78 | options = { :source => :default }.merge(sql) |
| 72 | 79 | sql = options[:file] || options[:string] |
| 73 | 80 | else |
| 81 | if sql.kind_of?(Array) | |
| 82 | options[:params] = sql[1..-1] | |
| 83 | sql = sql.first | |
| 84 | end | |
| 74 | 85 | options = { :source => :default, :string => sql }.merge(options) |
| 75 | options[:file] = sql if sql =~ /.sql$/ | |
| 86 | options[:file] = sql if sql =~ /\.sql$/ | |
| 76 | 87 | end |
| 77 | 88 | origin = options[:file] ? :file : :string |
| 78 | 89 |
| ... | ...@@ -29,6 +29,7 @@ | |
| 29 | 29 | :plain => Ruport::Query.new(@sql[0]), |
| 30 | 30 | :sourced => Ruport::Query.new(@sql[0], :source => :alternative), |
| 31 | 31 | :paramed => Ruport::Query.new(@sql[0], :params => [ 42 ]), |
| 32 | :paramed_ar => Ruport::Query.new([@sql[0], 69, 777]), | |
| 32 | 33 | :raw => Ruport::Query.new(@sql[0], :row_type => :raw), |
| 33 | 34 | :resultless => Ruport::Query.new(@sql[1]), |
| 34 | 35 | :multi => Ruport::Query.new(@sql[2]), |
| ... | ...@@ -52,13 +53,20 @@ | |
| 52 | 53 | query.execute.should == nil |
| 53 | 54 | end |
| 54 | 55 | |
| 55 | it "should allow excute to accept parameters" do | |
| 56 | it "should allow execute to accept parameters" do | |
| 56 | 57 | query = @query[:paramed] |
| 57 | 58 | setup_mock_dbi(1, :params => [ 42 ]) |
| 58 | 59 | |
| 59 | 60 | query.execute.should == nil |
| 60 | 61 | end |
| 61 | 62 | |
| 63 | it "should allow execute to accept parameters (ActiveRecord style)" do | |
| 64 | query = @query[:paramed_ar] | |
| 65 | setup_mock_dbi(1, :params => [ 69, 777 ]) | |
| 66 | ||
| 67 | query.execute.should == nil | |
| 68 | end | |
| 69 | ||
| 62 | 70 | it "should return nil for empty results" do |
| 63 | 71 | query = @query[:resultless] |
| 64 | 72 | setup_mock_dbi(1, :resultless => true, :sql => @sql[1]) |
| ... | ...@@ -22,7 +22,7 @@ | |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | def build_customer_header |
| 25 | move_cursor -5 | |
| 25 | move_cursor(-5) | |
| 26 | 26 | rounded_text_box(options.customer_info) { |o| |
| 27 | 27 | o.radius = 3 |
| 28 | 28 | o.width = options.header_width || 200 |
| ... | ...@@ -99,7 +99,7 @@ | |
| 99 | 99 | |
| 100 | 100 | horizontal_line left_boundary + 20, right_boundary - 25 |
| 101 | 101 | |
| 102 | move_cursor -10 | |
| 102 | move_cursor(-10) | |
| 103 | 103 | |
| 104 | 104 | add_text(options.comments,:justification => :center, |
| 105 | 105 | :left => 0, :right => 0 ) |