Changeset 570

Show
Ignore:
Timestamp:
03/01/07 21:30:15 (2 years ago)
Author:
sandal
Message:

Now, more confusing access rights in plugins

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/ruport/format/csv.rb

    r562 r570  
    44  # See also:  Renderer::Table 
    55  class CSV < Plugin 
     6 
     7    opt_reader :show_table_headers, :format_options 
     8 
    69    # Generates table header by turning column_names into a CSV row. 
    710    # Uses the row renderer to generate the actual formatted output 
     
    1013    # or the Data::Table has no column names. 
    1114    def build_table_header 
    12       unless data.column_names.empty? || !options.show_table_headers 
     15      unless data.column_names.empty? || !show_table_headers 
    1316        Ruport::Renderer::Row.render_csv data.column_names, :io => output, 
    14           :format_options => options.format_options  
     17          :format_options => format_options  
    1518      end 
    1619    end 
     
    1922    def build_table_body 
    2023      render_data_by_row { |r|  
    21         r.options.format_options = options.format_options 
     24        r.options.format_options = format_options 
    2225      } 
    2326    end 
     
    2629    def build_row 
    2730      require "fastercsv" 
    28       FCSV(output,options.format_options || {}) { |csv|  
     31      FCSV(output,format_options || {}) { |csv|  
    2932        csv << data 
    3033      } 
  • trunk/lib/ruport/format/html.rb

    r559 r570  
    44  # See also Renderer::Table 
    55  class HTML < Plugin 
     6 
     7    opt_reader :show_table_headers, :class_str 
    68     
    79    # Generates table headers based on the column names of your Data::Table.   
     
    1113    def build_table_header 
    1214      output << "\t<table>\n" 
    13       unless data.column_names.empty? || !options.show_table_headers 
     15      unless data.column_names.empty? || !show_table_headers 
    1416        output << "\t\t<tr>\n\t\t\t<th>" +  
    1517          data.column_names.join("</th>\n\t\t\t<th>") +  
     
    3032 
    3133        rend.options.class_str = classstr 
    32         #Ruport::Renderer::Row.render_html(  
    33        #  :class_str => classstr, :io => output) { |rend| rend.data = row  } 
    3434      end 
    3535    end 
     
    4343    def build_row 
    4444      output << 
    45         "\t\t<tr#{options.class_str}>\n\t\t\t<td#{options.class_str}>" + 
    46         data.to_a.join("</td>\n\t\t\t<td#{options.class_str}>") + 
     45        "\t\t<tr#{class_str}>\n\t\t\t<td#{class_str}>" + 
     46        data.to_a.join("</td>\n\t\t\t<td#{class_str}>") + 
    4747        "</td>\n\t\t</tr>\n" 
    4848    end 
  • trunk/lib/ruport/format/plugin.rb

    r559 r570  
    2020    end 
    2121 
     22    module OptionAccessors 
     23 
     24 
     25      module ClassMethods 
     26        def opt_reader(*opts) 
     27          require "forwardable" 
     28          extend Forwardable 
     29          opts.each { |o| def_delegator :@options, o } 
     30        end 
     31      end 
     32 
     33      def self.included(base) 
     34        base.extend(ClassMethods) 
     35      end 
     36    end 
     37 
    2238    class Plugin 
     39 
    2340      include RenderingTools 
     41      include OptionAccessors 
    2442 
    2543      attr_accessor :options 
  • trunk/lib/ruport/format/text.rb

    r559 r570  
    22  module Format 
    33    class Text < Plugin 
     4 
     5      opt_reader :max_col_width, :alignment, :table_width, :show_table_headers 
    46       
    57      # Checks to ensure the table is not empty and then calls 
     
    1921 
    2022        c = data.column_names.enum_for(:each_with_index).map { |f,i| 
    21           f.to_s.center(options.max_col_width[i]) 
     23          f.to_s.center(max_col_width[i]) 
    2224        } 
    2325 
     
    2931      # 
    3032      def should_render_column_names 
    31         not data.column_names.empty? || !options.show_table_headers 
     33        not data.column_names.empty? || !show_table_headers 
    3234      end 
    3335 
     
    4345   
    4446 
    45         calculate_max_col_widths unless options.max_col_width 
     47        calculate_max_col_widths unless max_col_width 
    4648 
    4749        render_data_by_row do |rend| 
    4850          rend.options do |o| 
    49             o.max_col_width = options.max_col_width 
    50             o.alignment     = options.alignment 
    51             o.table_width   = options.table_width 
     51            o.max_col_width = max_col_width 
     52            o.alignment     = alignment 
     53            o.table_width   = table_width 
    5254          end 
    5355        end 
     
    5860      def build_row 
    5961 
    60         max_col_widths_for_row(data) unless options.max_col_width 
     62        max_col_widths_for_row(data) unless max_col_width 
    6163 
    6264        data.enum_for(:each_with_index).inject(line=[]) { |s,e| 
    6365          field,index = e 
    64           if options.alignment.eql? :center 
    65             line << field.to_s.center(options.max_col_width[index]) 
     66          if alignment.eql? :center 
     67            line << field.to_s.center(max_col_width[index]) 
    6668          else 
    6769            align = field.is_a?(Numeric) ? :rjust : :ljust 
    68             line << field.to_s.send(align, options.max_col_width[index]) 
     70            line << field.to_s.send(align, max_col_width[index]) 
    6971          end 
    7072        } 
     
    7779      #   "+------------------+" 
    7880      def hr 
    79         len = options.max_col_width.inject(data[0].to_a.length * 3) {|s,e|s+e}+1 
     81        len = max_col_width.inject(data[0].to_a.length * 3) {|s,e|s+e}+1 
    8082        "+" + "-"*(len-2) + "+\n" 
    8183      end 
     
    8688      def width 
    8789        require "ruport/system_extensions" 
    88         options.table_width || SystemExtensions.terminal_width 
     90        table_width || SystemExtensions.terminal_width 
    8991      end 
    9092 
     
    103105 
    104106        # allow override 
    105         return if options.max_col_width 
     107        return if max_col_width 
    106108 
    107109        options.max_col_width = [] 
     
    109111        unless data.column_names.empty? 
    110112          data.column_names.each_index do |i|  
    111             options.max_col_width[i] = data.column_names[i].to_s.length 
     113            max_col_width[i] = data.column_names[i].to_s.length 
    112114          end 
    113115        end 
     
    120122        options.max_col_width ||= [] 
    121123        row.each_with_index do |f,i| 
    122           if !options.max_col_width[i] || f.to_s.length > options.max_col_width[i] 
    123             options.max_col_width[i] = f.to_s.length 
     124          if !max_col_width[i] || f.to_s.length > max_col_width[i] 
     125            max_col_width[i] = f.to_s.length 
    124126          end 
    125127        end