Changeset 1275

Show
Ignore:
Timestamp:
02/10/08 09:16:40 (9 months ago)
Author:
brian
Message:

Make build_row() take an optional data argument, and use it directly for rendering table bodies

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ruport/branches/brian/exp-stage-data-2/lib/ruport/formatter.rb

    r1262 r1275  
    6767      # Iterates through <tt>data</tt> and passes 
    6868      # each row to render_row with the given options. 
     69      # This interface is is very inefficient, since new Renderer and 
     70      # Formatter objects are created for every row, and is deprecated. 
     71      # Iterate the rows directly within your Formatter instead. 
    6972      def render_data_by_row(options={},&block) 
    7073        data.each do |r| 
  • ruport/branches/brian/exp-stage-data-2/lib/ruport/formatter/csv.rb

    r1260 r1275  
    7979 
    8080    # Produces CSV output for a data row. 
    81     def build_row 
     81    def build_row(data = self.data) 
    8282      csv_writer << data 
    8383    end 
  • ruport/branches/brian/exp-stage-data-2/lib/ruport/formatter/html.rb

    r1226 r1275  
    5252    # Replaces nil and empty strings with "&nbsp;"  
    5353    def build_table_body 
    54       render_data_by_row do |rend| 
    55         r = rend.data 
    56         rend.data = r.map { |e| e.to_s.empty? ? "&nbsp;" : e } 
     54      data.each do |row| 
     55        build_row(row.map { |e| e.to_s.empty? ? "&nbsp;" : e }) 
    5756      end 
    5857    end 
     
    6463   
    6564    # Renders individual rows for the table. 
    66     def build_row 
     65    def build_row(data = self.data) 
    6766      output << 
    6867        "\t\t<tr>\n\t\t\t<td>" + 
  • ruport/branches/brian/exp-stage-data-2/lib/ruport/formatter/text.rb

    r1251 r1275  
    9595      calculate_max_col_widths unless options.max_col_width 
    9696 
    97       render_data_by_row do |rend| 
    98         rend.options do |o| 
    99           o.max_col_width = options.max_col_width 
    100           o.alignment     = options.alignment 
    101           o.table_width   = options.table_width    
    102           o.ignore_table_width = options.ignore_table_width 
    103         end 
    104       end 
     97      data.each { |row| build_row(row) } 
    10598 
    10699      output << fit_to_width(hr) 
     
    115108    # Uses fit_to_width to truncate the row if necessary. 
    116109    # 
    117     def build_row 
     110    def build_row(data = self.data) 
    118111      max_col_widths_for_row(data) unless options.max_col_width 
    119112