Class: DocTemplate::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_template/document.rb

Constant Summary collapse

MAX_PARSE_ITERATIONS =
300
TAGS_WITHOUT_PARTS =

Contains the list of tags for which no parts should be created

[
  Tags::DefaultTag::TAG_NAME,
  Tags::GlsTag::TAG_NAME,
  Tags::MaterialsTag::TAG_NAME,
  '#'
].freeze
ELA_TG_TEMPLATE =
Lcms::Engine::Engine.root.join 'lib', 'doc_template', 'templates', 'ela-teacher-guidance.html.erb'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partsObject

Returns the value of attribute parts.



17
18
19
# File 'lib/doc_template/document.rb', line 17

def parts
  @parts
end

Class Method Details

.parse(nodes, opts = {}) ⇒ Object



19
20
21
# File 'lib/doc_template/document.rb', line 19

def self.parse(nodes, opts = {})
  new.parse(nodes, opts)
end

Instance Method Details

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/doc_template/document.rb', line 23

def parse(nodes, opts = {})
  @nodes = nodes
  @opts = opts
  @parts = @opts[:parts] || []

  # find all tags except ones which were marked as parsed first and nested levels
  xpath = [%(*[not(contains(@data-parsed, "true"))]/#{::DocTemplate::STARTTAG_XPATH}),
           %(*//*[not(contains(@data-parsed, "true"))]/#{::DocTemplate::STARTTAG_XPATH})]
  while (node = @nodes.at_xpath(*xpath))
    # identify the tag, take the siblings or enclosing and send it to the
    # relative tag class to render it
    next unless (tag_node = node.parent)

    handle_invalid_tag tag_node
    parse_node tag_node
  end

  add_custom_nodes unless @opts.key?(:level) || @opts.key?(:material)

  self
end

#renderObject



45
46
47
# File 'lib/doc_template/document.rb', line 45

def render
  @nodes.to_html
end