class DocTemplate::Tags::TablePreserveAlignmentTag

Constants

STYLE_RE
TAG_NAME

Public Instance Methods

parse(node, _options = {}) click to toggle source
# File lib/doc_template/tags/table_preserve_alignment_tag.rb, line 9
def parse(node, _options = {})
  if (table = find_table node)
    # inside cells for each `p` with `text-align` css param we add specific class
    table.xpath('.//p').each do |el|
      if (m = STYLE_RE.match el['style'])
        el['style'] = el['style'].sub STYLE_RE, ''
        el['class'] = "text-#{m[1]}"
      end
    end

    @content = table.to_s
    replace_tag table
  end

  node.remove

  self
end

Private Instance Methods

find_table(node) click to toggle source
# File lib/doc_template/tags/table_preserve_alignment_tag.rb, line 30
def find_table(node)
  while (node = node.next_sibling)
    return node if node.name.casecmp('table').zero?
  end
end