Changeset 1224

Show
Ignore:
Timestamp:
12/09/07 20:32:17 (1 year ago)
Author:
mikem836
Message:

remove opt_reader - fix for #372

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ruport/trunk/examples/pdf_report_with_common_base.rb

    r1210 r1224  
    2323  def setup 
    2424    data.rename_columns { |c| c.to_s.titleize } 
    25     # this lets us omit the options prefix in the formatter 
    26     formatter.class.opt_reader(:example) 
    2725  end  
    2826end 
     
    5856  def build_client_header 
    5957   pad(10) do 
    60     add_text "Specific Report Header with example=#{example}", 
     58    add_text "Specific Report Header with example=#{options.example}", 
    6159             :justification => :center, :font_size => 12 
    6260   end 
  • ruport/trunk/examples/png_embed.rb

    r1210 r1224  
    1010 
    1111  renders :html, :for => RoadmapRenderer 
    12   opt_reader :image_file 
    1312 
    1413  def layout 
     
    1918 
    2019  def build_roadmap_image 
    21     output << "<img src='#{image_file}'/>" 
     20    output << "<img src='#{options.image_file}'/>" 
    2221  end 
    2322                                   
     
    3130 
    3231  renders :pdf, :for => RoadmapRenderer 
    33   opt_reader :image_file 
    3432 
    3533  def build_roadmap_image 
    36     center_image_in_box image_file, :x => 0, :y => 200,  
     34    center_image_in_box options.image_file, :x => 0, :y => 200,  
    3735                                   :width => 624, :height => 432 
    3836    move_cursor_to 80 
  • ruport/trunk/lib/ruport/formatter.rb

    r1223 r1224  
    181181    end 
    182182     
    183     # Allows the options specified to be accessed directly. 
    184     #  
    185     #   opt_reader :something 
    186     #   something == options.something #=> true 
    187     def self.opt_reader(*opts)  
    188       require "forwardable" 
    189       extend Forwardable 
    190       opts.each { |o| def_delegator :@options, o } 
    191     end 
    192      
    193183    # Gives a list of formats registered for this formatter. 
    194184    def self.formats 
  • ruport/trunk/lib/ruport/formatter/csv.rb

    r1188 r1224  
    3333                            Renderer::Group, Renderer::Grouping ] 
    3434 
    35     opt_reader :show_table_headers,  
    36                :format_options,  
    37                :show_group_headers, 
    38                :style 
    39  
    4035    # Hook for setting available options using a template. See the template  
    4136    # documentation for the available options and their format. 
     
    5348    # or the Data::Table has no column names. 
    5449    def build_table_header 
    55       unless data.column_names.empty? || !show_table_headers 
    56         render_row data.column_names, :format_options => format_options  
     50      unless data.column_names.empty? || !options.show_table_headers 
     51        render_row data.column_names, :format_options => options.format_options  
    5752      end 
    5853    end 
     
    6156    def build_table_body 
    6257      render_data_by_row { |r|  
    63         r.options.format_options = format_options 
     58        r.options.format_options = options.format_options 
    6459      } 
    6560    end 
     
    6863    def build_row 
    6964      require "fastercsv" 
    70       output << FCSV.generate_line(data,format_options || {}) 
     65      output << FCSV.generate_line(data,options.format_options || {}) 
    7166    end 
    7267     
     
    8782    # 
    8883    def build_grouping_header 
    89       unless style == :inline 
     84      unless options.style == :inline 
    9085        output << "#{data.grouped_by}," << grouping_columns 
    9186      end 
     
    9489    # Determines the proper style to use and renders the Grouping. 
    9590    def build_grouping_body 
    96       case style 
     91      case options.style 
    9792      when :inline 
    9893        render_inline_grouping(options) 
     
    113108    def render_justified_or_raw_grouping 
    114109      data.each do |_,group| 
    115         output << "#{group.name}" if style == :justified 
     110        output << "#{group.name}" if options.style == :justified 
    116111        group.each do |row| 
    117           output << "#{group.name if style == :raw}," << row.to_csv 
     112          output << "#{group.name if options.style == :raw}," << row.to_csv 
    118113        end 
    119114        output << "\n" 
  • ruport/trunk/lib/ruport/formatter/html.rb

    r1188 r1224  
    2929                             Renderer::Group, Renderer::Grouping ] 
    3030 
    31     opt_reader :show_table_headers, :show_group_headers, :style 
    32      
    3331    # Hook for setting available options using a template. See the template  
    3432    # documentation for the available options and their format. 
     
    4442    def build_table_header 
    4543      output << "\t<table>\n" 
    46       unless data.column_names.empty? || !show_table_headers 
     44      unless data.column_names.empty? || !options.show_table_headers 
    4745        output << "\t\t<tr>\n\t\t\t<th>" +  
    4846          data.column_names.join("</th>\n\t\t\t<th>") +  
     
    9088    # 
    9189    def build_grouping_body 
    92       case style 
     90      case options.style 
    9391      when :inline 
    9492        render_inline_grouping(options) 
  • ruport/trunk/lib/ruport/formatter/pdf.rb

    r1221 r1224  
    4747    attr_writer :pdf_writer 
    4848 
    49     opt_reader  :style, 
    50                 :table_format, 
    51                 :text_format, 
    52                 :paper_size, 
    53                 :paper_orientation 
    54      
    5549    save_as_binary_file 
    5650 
     
    7872    def pdf_writer 
    7973      @pdf_writer ||= options.formatter || 
    80         ::PDF::Writer.new( :paper => paper_size || "LETTER", 
    81               :orientation => paper_orientation || :portrait) 
     74        ::PDF::Writer.new( :paper => options.paper_size || "LETTER", 
     75              :orientation => options.paper_orientation || :portrait) 
    8276    end 
    8377 
     
    108102    # Renderer::Grouping. 
    109103    def build_grouping_body  
    110       case style 
     104      case options.style 
    111105      when :inline 
    112106        render_inline_grouping(options.to_hash.merge(:formatter => pdf_writer, 
     
    136130    #   add_text("Hello Mike",:font_size => 16) # renders at 16pt 
    137131    def add_text(text, format_opts={}) 
    138       format_opts = text_format.merge(format_opts) if text_format 
     132      format_opts = options.text_format.merge(format_opts) if options.text_format 
    139133      pdf_writer.text(text, format_opts) 
    140134    end 
     
    265259      table_data.rename_columns { |c| c.to_s }  
    266260             
    267       if table_format 
    268         format_opts = Marshal.load(Marshal.dump(table_format.merge(format_opts)))  
     261      if options.table_format 
     262        format_opts = 
     263          Marshal.load(Marshal.dump(options.table_format.merge(format_opts)))  
    269264      end   
    270265         
     
    430425          end 
    431426        end 
    432         table << [" "] if style == :separated 
     427        table << [" "] if options.style == :separated 
    433428      end 
    434429      render_table table, options.to_hash.merge(:formatter => pdf_writer) 
  • ruport/trunk/lib/ruport/formatter/text.rb

    r1188 r1224  
    4949                             Renderer::Group, Renderer::Grouping ] 
    5050 
    51     opt_reader :max_col_width, :alignment, :table_width,  
    52                :show_table_headers, :show_group_headers, 
    53                :ignore_table_width 
    54      
    5551    # Hook for setting available options using a template. See the template  
    5652    # documentation for the available options and their format. 
     
    7975 
    8076      c = data.column_names.enum_for(:each_with_index).map { |f,i| 
    81         f.to_s.center(max_col_width[i]) 
     77        f.to_s.center(options.max_col_width[i]) 
    8278      } 
    8379 
     
    9793      return if data.empty? 
    9894 
    99       calculate_max_col_widths unless max_col_width 
     95      calculate_max_col_widths unless options.max_col_width 
    10096 
    10197      render_data_by_row do |rend| 
    10298        rend.options do |o| 
    103           o.max_col_width = max_col_width 
    104           o.alignment     = alignment 
    105           o.table_width   = table_width    
    106           o.ignore_table_width = ignore_table_width 
     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 
    107103        end 
    108104      end 
     
    120116    # 
    121117    def build_row 
    122       max_col_widths_for_row(data) unless max_col_width 
     118      max_col_widths_for_row(data) unless options.max_col_width 
    123119 
    124120      data.enum_for(:each_with_index).inject(line=[]) { |s,e| 
    125121        field,index = e 
    126         if alignment.eql? :center 
    127           line << field.to_s.center(max_col_width[index]) 
     122        if options.alignment.eql? :center 
     123          line << field.to_s.center(options.max_col_width[index]) 
    128124        else 
    129125          align = field.is_a?(Numeric) ? :rjust : :ljust 
    130           line << field.to_s.send(align, max_col_width[index]) 
     126          line << field.to_s.send(align, options.max_col_width[index]) 
    131127        end 
    132128      } 
     
    158154    # 
    159155    def should_render_column_names? 
    160       not data.column_names.empty? || !show_table_headers 
     156      not data.column_names.empty? || !options.show_table_headers 
    161157    end 
    162158 
     
    167163    def hr 
    168164      ref = data.column_names.empty? ? data[0].to_a : data.column_names 
    169       len = max_col_width.inject(ref.length * 3) {|s,e|s+e} 
     165      len = options.max_col_width.inject(ref.length * 3) {|s,e|s+e} 
    170166      "+" + "-"*(len-1) + "+\n" 
    171167    end 
     
    175171    # Otherwise, uses SystemExtensions to determine terminal width. 
    176172    def width 
    177       table_width || SystemExtensions.terminal_width 
     173      options.table_width || SystemExtensions.terminal_width 
    178174    end 
    179175 
     
    192188    def calculate_max_col_widths 
    193189      # allow override 
    194       return if max_col_width 
     190      return if options.max_col_width 
    195191 
    196192      options.max_col_width = [] 
     
    198194      unless data.column_names.empty? 
    199195        data.column_names.each_index do |i|  
    200           max_col_width[i] = data.column_names[i].to_s.length 
     196          options.max_col_width[i] = data.column_names[i].to_s.length 
    201197        end 
    202198      end 
     
    210206      options.max_col_width ||= [] 
    211207      row.each_with_index do |f,i| 
    212         if !max_col_width[i] || f.to_s.length > max_col_width[i] 
    213           max_col_width[i] = f.to_s.length 
     208        if !options.max_col_width[i] || f.to_s.length > options.max_col_width[i] 
     209          options.max_col_width[i] = f.to_s.length 
    214210        end 
    215211      end