module Stack module Parsable attr_accessor :raw attr_accessor :data attr_accessor :inline_data def parse!(raw_doc = self.raw, defaults = { }) self.data, self.raw = extract_yaml(raw_doc, nil, defaults) puts self.data end def payload self.data.deep_symbolize.merge(:inline_data => inline_data) end def extract_yaml(raw, replace = nil, defaults = { }) self.inline_data = [ ] data_table = defaults out = raw.dup i = -1 puts "out -> #{out}" while out =~ /^(---\s*\n.*?\n?)(---.*?\n)/m yaml = $1.dup out = out.gsub(/#{Regexp.escape(yaml)}#{Regexp.escape($2)}/m,((i>-1) ? "{{ document.inline_data[#{i}] | render_table }}" : "")) puts "out2 -> #{out}" d = YAML.load(yaml) if d.is_a?(Hash) self.inline_data << d if i > -1 data_table = data_table.deep_merge(d) end d = nil; i += 1; end data_table = data_table.deep_symbolize return data_table, out end end end