Class: DocTemplate::Tags::DefTag

Inherits:
BaseTag
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/doc_template/tags/def_tag.rb

Constant Summary collapse

STYLE_RE =
/<span (style=[^.>]*)>[^<]*$/i.freeze
TAG_NAME =
'def'
TAG_SEPARATOR =
'[separator]'
TEMPLATES =
{
  default: 'def.html.erb',
  gdoc: 'gdoc/def.html.erb'
}.freeze

Constants inherited from BaseTag

BaseTag::SOFT_RETURN_RE, BaseTag::UNICODE_SPACES_RE

Instance Attribute Summary

Attributes inherited from BaseTag

#anchor, #content

Instance Method Summary collapse

Methods inherited from BaseTag

#before_tag, #check_tag_soft_return, #content_until_break, #content_until_materials, #ela2?, #ela6?, #gdoc?, #include_break?, #include_break_for?, #materials, parse, #parse_nested, #parse_template, #placeholder, #placeholder_id, #render, #replace_tag, #tag_data, tag_with_html_regexp, #template_name, #template_path, template_path_for

Instance Method Details

#parse(node, opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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