class DocTemplate::Tags::IndentTag

Constants

TAG_NAME
TEMPLATES

Attributes

node[R]
opts[R]

Public Instance Methods

parse(node, opts = {}) click to toggle source
# File lib/doc_template/tags/indent_tag.rb, line 12
def parse(node, opts = {})
  @node = node
  @opts = opts
  @content = parse_template({ content: parsed_content }, template_name(opts))
  replace_tag node
  self
end

Private Instance Methods

parsed_content() click to toggle source
# File lib/doc_template/tags/indent_tag.rb, line 24
def parsed_content
  # need to move br before content for proper indentation
  prepend_html = '<br>' if (br_nodes = node.css('br')).present?
  br_nodes.each(&:remove)
  content_without_tag = node.to_html.sub DocTemplate::FULL_TAG, ''
  html = parse_nested content_without_tag, opts

  if gdoc?(opts)
    nodes = Nokogiri::HTML.fragment html
    if (el = nodes.at_css('p'))
      el['class'] = 'u-ld-indented'
      html = nodes.to_s
    end
  end

  "#{prepend_html}#{html}"
end