class DocTemplate::Tags::DefTag

Constants

STYLE_RE
TAG_NAME
TAG_SEPARATOR
TEMPLATES

Public Instance Methods

parse(node, opts = {}) click to toggle source
# File lib/doc_template/tags/def_tag.rb, line 16
def parse(node, opts = {})
  # Need to extract the Tag and preserves all the styling inside it
  node_html = node.inner_html
  start_pos = node_html.index '['
  end_pos = node_html.rindex ']'
  needle = node_html[start_pos..end_pos]

  preserved_style = STYLE_RE.match(needle).try(:[], 1)
  subject = (opts[:metadata].try(:[], 'subject').presence || 'ela').downcase
  definition, description = opts[:value].split(';').map(&:strip)

  data = node_html.sub(needle, TAG_SEPARATOR).split(TAG_SEPARATOR, 2).map(&:squish)

  params = {
    append: data[1],
    definition: definition,
    description: description,
    prepend: data[0],
    preserved_style: preserved_style,
    subject: subject
  }

  @content = "<p>#{parse_template(params, template_name(opts))}</p>"

  if node.name == 'li'
    @result = node.replace "<li class='#{node['class']}'>#{placeholder}</li>"
  else
    replace_tag node
  end
  self
end