Sha256: 331d58095c63dfb46e72f32b1a04eab143080d86c69e500099ad67225d6780ed
Contents?: true
Size: 1023 Bytes
Versions: 6
Compression:
Stored size: 1023 Bytes
Contents
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) end def payload self.data.deep_symbolize.merge(:data => inline_data) end def extract_yaml(raw, replace = nil, defaults = { }) self.inline_data = [ ] data_table = defaults out = raw.dup i = -1 while out =~ /^(---\s*\n.*?\n?)(---.*?\n)/m yaml = $1.dup out = out.gsub(/#{Regexp.escape(yaml)}#{Regexp.escape($2)}/m,((i>-1) ? "{{ document.data[#{i}] | render_table }}" : "")) 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
Version data entries
6 entries across 6 versions & 1 rubygems