Class: JekyllSupport::YamlParser
- Inherits:
-
Object
- Object
- JekyllSupport::YamlParser
- Defined in:
- lib/structure/yaml_parser.rb
Instance Attribute Summary collapse
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
-
#initialize(outline_options, content = '') ⇒ Object
constructor
Array of empty Sections.
-
#parse_sections(outline_options, content) ⇒ Object
Array of Sections that do not contain children.
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(, content = '') @logger = .logger @sections = if content && !content.strip.empty? parse_sections , content else [] end end |
Instance Attribute Details
#sections ⇒ Object (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.
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(, content) content = remove_leading_zeros remove_leading_spaces content yaml = YAML.safe_load content yaml.map { |entry| Section.new , 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.}</pre> END_MSG @logger.error { e. } raise OutlineError, msg end |