Sha256: 1fc0c3e7e89738f9ba4a6f0cea3bb961c2f03ad39dcccdef685f52982d604592

Contents?: true

Size: 2 KB

Versions: 4

Compression:

Stored size: 2 KB

Contents

module PdfTableHelper
  NORMAL_TH = {
    align: :center,
    valign: :center,
    size: 14,
    font_style: :bold,
    height: 30,
    background_color: 'eeeeee'
  }
  NORMAL_TD = {
    align: :left,
    valign: :center,
    size: 12,
    height: 30
  }
  LEFT_TD = {
    align: :left,
    valign: :center,
    size: 12
  }
  RIGHT_TD = {
    align: :right,
    valign: :center,
    size: 12
  }

  def left_header_table(data)
    options = {
      position: :center,
      width: bounds.width,
      cell_style: {
        border_lines: [:solid, :solid, :dashed, :solid]
      }
    }
    undash
    table(data, options) do
      columns(0).style NORMAL_TH
      columns(1..-1).style NORMAL_TD
    end
  end

  def top_header_table(data)
    options = {
      position: :center,
      width: bounds.width,
      cell_style: {
        border_lines: [:solid, :solid, :dashed, :solid]
      }
    }
    undash
    table(data, options) do
      row(0).style NORMAL_TH
      row(1..-1).style NORMAL_TD
    end
  end

  def grid_table(data, options = {})
    default_options = {
      position: :center,
      width: bounds.width,
      cell_style: {
        borders: []
      }
    }
    default_options.merge!(options)
    undash
    table(data, default_options) do
      columns(0).style LEFT_TD
      columns(-1).style RIGHT_TD
    end
  end

  def content_table(data, options = {}, &block)
    default_options = {
      position: :center,
      width: bounds.width,
      cell_style: {
        border_lines: [:solid, :solid, :solid, :solid],
        border_color: '999999'
      }
    }
    default_options.merge!(options)
    undash
    if block_given?
      table(data, default_options, &block)
    else
      table(data, default_options) do
        row(0..-1).style NORMAL_TD
      end
    end
  end

  def footer_table(data)
    options = {
      position: :center,
      width: bounds.width,
      cell_style: {
        borders: []
      }
    }
    undash
    table(data, options) do
      columns(0..-1).style NORMAL_TD
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_data-1.0.2 app/pdfs/concerns/pdf_table_helper.rb
rails_data-1.0.1 app/pdfs/concerns/pdf_table_helper.rb
rails_data-1.0.0 app/pdfs/concerns/pdf_table_helper.rb
rails_data-0.0.1 app/pdfs/concerns/pdf_table_helper.rb