class Asciidoctor::Table::Cell

Public: Methods for managing the a cell in an AsciiDoc table.

Attributes

colspan[RW]

Public: An Integer of the number of columns this cell will span (default: nil)

inner_document[R]

Public: The internal Asciidoctor::Document for a cell that has the asciidoc style

rowspan[RW]

Public: An Integer of the number of rows this cell will span (default: nil)

style[RW]

Public: Get/Set the Symbol style for this cell (default: nil)

Public Class Methods

new(column, cell_text, attributes = {}) click to toggle source
Calls superclass method Asciidoctor::AbstractNode.new
# File lib/asciidoctor/table.rb, line 215
def initialize column, cell_text, attributes = {}, opts = {}
  super column, :cell
  if column
    cell_style = (in_header_row = column.table.header_row?) ? nil : column.attributes['style']
    # REVIEW feels hacky to inherit all attributes from column
    update_attributes column.attributes
  else
    in_header_row = cell_style = nil
  end
  if attributes
    @colspan = attributes.delete 'colspan'
    @rowspan = attributes.delete 'rowspan'
    # TODO eventually remove the style attribute from the attributes hash
    #cell_style = attributes.delete 'style' unless in_header_row || !(attributes.key? 'style')
    cell_style = attributes['style'] unless in_header_row || !(attributes.key? 'style')
    if opts[:strip_text]
      if cell_style == :literal || cell_style == :verse
        cell_text = cell_text.rstrip
        cell_text = cell_text.slice 1, cell_text.length - 1 while cell_text.start_with? LF
      else
        cell_text = cell_text.strip
      end
    end
    update_attributes attributes
  else
    @colspan = nil
    @rowspan = nil
  end
  # NOTE only true for non-header rows
  if cell_style == :asciidoc
    # FIXME hide doctitle from nested document; temporary workaround to fix
    # nested document seeing doctitle and assuming it has its own document title
    parent_doctitle = @document.attributes.delete('doctitle')
    # NOTE we need to process the first line of content as it may not have been processed
    # the included content cannot expect to match conditional terminators in the remaining
    # lines of table cell content, it must be self-contained logic
    # QUESTION should we reset cell_text to nil?
    # QUESTION is is faster to check for :: before splitting?
    inner_document_lines = cell_text.split LF, -1
    if (unprocessed_line1 = inner_document_lines[0]).include? '::'
      preprocessed_lines = (PreprocessorReader.new @document, [unprocessed_line1]).readlines
      unless unprocessed_line1 == preprocessed_lines[0] && preprocessed_lines.size < 2
        inner_document_lines.shift
        inner_document_lines.unshift(*preprocessed_lines) unless preprocessed_lines.empty?
      end
    end unless inner_document_lines.empty?
    @inner_document = Document.new(inner_document_lines, :header_footer => false, :parent => @document, :cursor => opts[:cursor])
    @document.attributes['doctitle'] = parent_doctitle unless parent_doctitle.nil?
  end
  @text = cell_text
  @style = cell_style
end

Public Instance Methods

content() click to toggle source

Public: Handles the body data (tbody, tfoot), applying styles and partitioning into paragraphs

This method should not be used for cells in the head row or that have the literal or verse style.

Returns the converted String for this Cell

# File lib/asciidoctor/table.rb, line 294
def content
  if @style == :asciidoc
    @inner_document.convert
  else
    text.split(BlankLineRx).map do |p|
      !@style || @style == :header ? p : Inline.new(parent, :quoted, p, :type => @style).convert
    end
  end
end
text() click to toggle source

Public: Get the String text of this cell with substitutions applied.

Used for cells in the head row as well as text-only (non-AsciiDoc) cells in the foot row and body.

This method shouldn't be used for cells that have the AsciiDoc style.

Returns the converted String text for this Cell

# File lib/asciidoctor/table.rb, line 276
def text
  apply_subs @text, (@style == :literal ? BASIC_SUBS : NORMAL_SUBS)
end
text=(val) click to toggle source

Public: Set the String text.

This method shouldn't be used for cells that have the AsciiDoc style.

Returns the new String text assigned to this Cell

# File lib/asciidoctor/table.rb, line 285
def text= val
  @text = val
end
to_s() click to toggle source
# File lib/asciidoctor/table.rb, line 304
def to_s
  "#{super.to_s} - [text: #@text, colspan: #{@colspan || 1}, rowspan: #{@rowspan || 1}, attributes: #@attributes]"
end