Module: Stack::Parsable
- Included in:
- Templates::Article, Templates::Layout, Templates::Page
- Defined in:
- lib/stack/parsable.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#inline_data ⇒ Object
Returns the value of attribute inline_data.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #extract_yaml(raw, replace = nil, defaults = { }) ⇒ Object
- #parse!(raw_doc = self.raw, defaults = { }) ⇒ Object
- #payload ⇒ Object
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/stack/parsable.rb', line 4 def data @data end |
#inline_data ⇒ Object
Returns the value of attribute inline_data.
5 6 7 |
# File 'lib/stack/parsable.rb', line 5 def inline_data @inline_data end |
#raw ⇒ Object
Returns the value of attribute raw.
3 4 5 |
# File 'lib/stack/parsable.rb', line 3 def raw @raw end |
Instance Method Details
#extract_yaml(raw, replace = nil, defaults = { }) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stack/parsable.rb', line 15 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 |
#parse!(raw_doc = self.raw, defaults = { }) ⇒ Object
7 8 9 |
# File 'lib/stack/parsable.rb', line 7 def parse!(raw_doc = self.raw, defaults = { }) self.data, self.raw = extract_yaml(raw_doc, nil, defaults) end |
#payload ⇒ Object
11 12 13 |
# File 'lib/stack/parsable.rb', line 11 def payload self.data.deep_symbolize.merge(:data => inline_data) end |