Class: JekyllSupport::YamlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/structure/yaml_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outline_options, content = '') ⇒ Object

Returns array of empty Sections.



11
12
13
14
15
16
17
18
# File 'lib/structure/yaml_parser.rb', line 11

def initialize(outline_options, content = '')
  @logger = outline_options.logger
  @sections = if content && !content.strip.empty?
                parse_sections outline_options, content
              else
                []
              end
end

Instance Attribute Details

#sectionsObject (readonly)

Returns the value of attribute sections.



8
9
10
# File 'lib/structure/yaml_parser.rb', line 8

def sections
  @sections
end

Instance Method Details

#parse_sections(outline_options, content) ⇒ Object

Returns Array of Sections that do not contain children.

Returns:

  • Array of Sections that do not contain children



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/structure/yaml_parser.rb', line 21

def parse_sections(outline_options, content)
  content = remove_leading_zeros remove_leading_spaces content
  yaml = YAML.safe_load content
  yaml.map { |entry| Section.new outline_options, entry }
rescue NoMethodError => e
  raise OutlineError, <<~END_MSG
    Invalid YAML within {% outline %} tag. The offending content was:

    <pre>#{content}</pre>
  END_MSG
rescue Psych::SyntaxError => e
  msg = <<~END_MSG
    Invalid YAML found within {% outline %} tag:<br>
    <pre>#{e.message}</pre>
  END_MSG
  @logger.error { e.message }
  raise OutlineError, msg
end