Class: SoupCMS::CLI::FrontMatterParser

Inherits:
Object
  • Object
show all
Defined in:
lib/soupcms/cli/front_matter_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(string) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/soupcms/cli/front_matter_parser.rb', line 8

def parse(string)
  return {}, string if string.lines[0] && string.lines[0].chomp.strip != '---'
  res = [{}, '']
  res[1] = string.lstrip.gsub(/---(.*)---/m) do |match|
    front_matter = $~.captures.first.strip
    res[0] = YAML.load(front_matter)
    ''
  end.strip
  return res[0], res[1]
end