Class: PDFGen::SmartTable

Inherits:
Table show all
Defined in:
lib/smart_table.rb

Defined Under Namespace

Classes: RowsContainer

Instance Attribute Summary collapse

Attributes inherited from Table

#repeat_footer_on_each_page, #repeat_header_on_each_page

Attributes inherited from BaseRegion

#parent

Attributes included from BaseAttributes

#background_color, #border_bottom, #border_color, #border_left, #border_right, #border_style, #border_top, #border_width, #height, #is_breakable, #pad_bottom, #pad_left, #pad_right, #pad_top, #page_pad_top, #width

Instance Method Summary collapse

Methods inherited from Table

#align_cell_in_row, #footer, #title, #width=

Methods inherited from BaseRegion

#check_fit_in_height, #document, #minimal_height, #set_properties, #value

Methods included from BaseAttributes

#av_width, #border=, #border_params, #breakable?, included, #paddings=, #var_init

Methods included from BaseAttributes::ClassMethods

#common_setter

Constructor Details

#initialize(parent) ⇒ SmartTable

Returns a new instance of SmartTable.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/smart_table.rb', line 58

def initialize(parent)
  super(parent)
  @title = RowsContainer.new(self)
  @header = RowsContainer.new(self)
  @body = RowsContainer.new(self)
  @footer = RowsContainer.new(self)

  self.width = parent.av_width
  
  @data_source = nil
  @header_data = nil
  @body_data = nil

  @is_header_rendered = false
  @is_body_rendered = false
  @columns = nil

  @body_regions = []
  
end

Instance Attribute Details

#body_regionsObject

Returns the value of attribute body_regions.



11
12
13
# File 'lib/smart_table.rb', line 11

def body_regions
  @body_regions
end

#data_sourceObject

Returns the value of attribute data_source.



89
90
91
# File 'lib/smart_table.rb', line 89

def data_source
  @data_source
end

#header_regionObject

Returns the value of attribute header_region.



11
12
13
# File 'lib/smart_table.rb', line 11

def header_region
  @header_region
end

Instance Method Details

#body(style = nil, &initialization_block) ⇒ Object



151
152
153
154
# File 'lib/smart_table.rb', line 151

def body(style = nil, &initialization_block)
  super
  @is_body_rendered = true
end

#build_bodyObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/smart_table.rb', line 128

def build_body()
  @body_data.each do |row|
    span = Span.new(self.document)
    span.width = self.width
    span.border = true
    row.each do |cap|
      caption = Caption.new(self.document)
      caption.text = cap
      caption.width = self.width / row.size
      caption.border_left = true
      yield(span, caption) if block_given?
      span.add_region(caption)
    end
    @body_regions << span
  end
  @is_body_rendered = true
end

#build_headerObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/smart_table.rb', line 112

def build_header()
  span = Span.new(self.document)
  span.width = self.width
  span.border = true
  @header_data.each do |cap|
    caption = Caption.new(self.document)
    caption.text = cap
    caption.width = self.width / @header_data.size
    caption.border_left = true
    yield(span, caption) if block_given?
    span.add_region(caption)
  end
  @is_header_rendered = true
  span
end

#calculate_minimal_heightObject



91
92
93
94
# File 'lib/smart_table.rb', line 91

def calculate_minimal_height
  regions_formation
  super
end

#header(style = nil, &initialization_block) ⇒ Object



146
147
148
149
# File 'lib/smart_table.rb', line 146

def header(style = nil, &initialization_block)
  super
  @is_header_rendered = true
end

#regions_formationObject



96
97
98
99
100
101
# File 'lib/smart_table.rb', line 96

def regions_formation
  @header.add_region(build_header) unless @is_header_rendered
  build_body unless @is_body_rendered

  @body_regions.each { |region| @body.add_region(region) }
end

#render(pos, av_height, test = false) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/smart_table.rb', line 103

def render(pos, av_height, test=false)
  @header_region = nil if @is_header_rendered
  @body_regions.clear if @is_body_rendered

  regions_formation
  
  super
end