Class: Slamdown::Conversion::Tables::Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/slamdown/conversion/tables.rb

Overview

Carries interpreted groups and the canonical HTML fallback tree for one normalised table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, caption, head_rows, body_groups, foot_rows, html_required, captions_merged, dropped_spans) ⇒ Analysis

Returns a new instance of Analysis.



204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/slamdown/conversion/tables.rb', line 204

def initialize(table, caption, head_rows, body_groups, foot_rows, html_required, captions_merged, dropped_spans)
	@table = table
	@caption = caption
	@head_rows = head_rows.freeze
	@body_groups = body_groups.map(&:freeze).freeze
	@foot_rows = foot_rows.freeze
	@html_required = html_required
	@captions_merged = captions_merged
	@dropped_spans = dropped_spans
	@source_layout = Layout.new(head_rows, body_groups, foot_rows)
	freeze
end

Instance Attribute Details

#body_groupsObject (readonly)

Returns the value of attribute body_groups.



202
203
204
# File 'lib/slamdown/conversion/tables.rb', line 202

def body_groups
  @body_groups
end

#captionObject (readonly)

Returns the value of attribute caption.



202
203
204
# File 'lib/slamdown/conversion/tables.rb', line 202

def caption
  @caption
end

#foot_rowsObject (readonly)

Returns the value of attribute foot_rows.



202
203
204
# File 'lib/slamdown/conversion/tables.rb', line 202

def foot_rows
  @foot_rows
end

#head_rowsObject (readonly)

Returns the value of attribute head_rows.



202
203
204
# File 'lib/slamdown/conversion/tables.rb', line 202

def head_rows
  @head_rows
end

#html_requiredObject (readonly)

Returns the value of attribute html_required.



202
203
204
# File 'lib/slamdown/conversion/tables.rb', line 202

def html_required
  @html_required
end

#tableObject (readonly)

Returns the value of attribute table.



202
203
204
# File 'lib/slamdown/conversion/tables.rb', line 202

def table
  @table
end

Instance Method Details

#captions_merged?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/slamdown/conversion/tables.rb', line 221

def captions_merged?
	@captions_merged
end

#html_required?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/slamdown/conversion/tables.rb', line 217

def html_required?
	html_required
end

#layout(format) ⇒ Object

Header-cell inference differs only in how many leading all-header rows each output format can express.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/slamdown/conversion/tables.rb', line 226

def layout(format)
	heads, bodies, feet = corrected_groups
	if heads.empty? && !bodies.empty?
		first_group = bodies.first
		available = first_group.take_while(&:header?).length
		inferred = format == "markdown" ? [available, 1].min : available
		unless inferred.zero?
			heads = first_group.first(inferred)
			bodies = [first_group.drop(inferred)] + bodies.drop(1)
			bodies.reject!(&:empty?)
		end
	end
	bodies = [bodies.flatten] if format == "markdown" && bodies.length > 1
	Layout.new(heads, bodies, feet)
end

#table_for(format) ⇒ Object

Produces the corrected structural tree used whenever table syntax falls back to canonical HTML.



243
244
245
246
247
248
249
250
251
252
253
# File 'lib/slamdown/conversion/tables.rb', line 243

def table_for(format)
	children = @dropped_spans && !@source_layout.complexity_limited? ? materialise_dropped_spans(table.children) : table.children
	children = merge_sections(children, :table_head)
	children = merge_sections(children, :table_foot)
	children = merge_sections(children, :table_body) if format == "markdown"
	children = wrap_direct_rows(children)
	children = coerce_bodyless_sections(children)
	children = children.map { |child| canonicalise_fallback_node(child) }
	children = canonical_table_order(children)
	table.with(:children => children)
end