Class: Sitepress::Parsers::Frontmatter::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/sitepress/parsers/frontmatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, data:) ⇒ Renderer

Returns a new instance of Renderer.



11
12
13
14
# File 'lib/sitepress/parsers/frontmatter.rb', line 11

def initialize(body:, data:)
  @body = body
  @data = data
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/sitepress/parsers/frontmatter.rb', line 9

def body
  @body
end

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/sitepress/parsers/frontmatter.rb', line 9

def data
  @data
end

Instance Method Details

#dump_yaml(data) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/sitepress/parsers/frontmatter.rb', line 16

def dump_yaml(data)
  if YAML.respond_to? :safe_dump
    YAML.safe_dump data, permitted_classes: Frontmatter.permitted_classes
  else
    # Live dangerously, lol
    YAML.dump data
  end
end

#renderObject



25
26
27
28
29
30
31
32
33
# File 'lib/sitepress/parsers/frontmatter.rb', line 25

def render
  [
    dump_yaml(Data.unmanage(data)),
    Frontmatter::DELIMITER,
    $/,
    $/,
    body
  ].join
end