Module: Inq::Frontmatter

Extended by:
Okay::WarningHelpers
Defined in:
lib/inq/frontmatter.rb

Overview

Module for generating YAML frontmatter, as used by Jekyll and other blog engines.

Class Method Summary collapse

Class Method Details

.generate(frontmatter, report_data) ⇒ String

Generates YAML frontmatter, as is used in Jekyll and other blog engines.

E.g.,

generate_frontmatter({'foo' => "bar %{baz}"}, {'baz' => "asdf"})

> “—nfoo: bar asdfn”

Parameters:

  • frontmatter (Hash)

    Frontmatter for the report.

  • report_data (Hash)

    The report data itself.

Returns:

  • (String)

    A YAML dump of the generated frontmatter.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/inq/frontmatter.rb', line 22

def self.generate(frontmatter, report_data)
  return "" if frontmatter.nil?

  frontmatter = convert_keys(frontmatter, :to_s)
  report_data = convert_keys(report_data, :to_sym)

  frontmatter = frontmatter.map { |k, v|
    # Sometimes report_data has unused keys, which generates a warning, but
    # we're okay with it.
    v = silence_warnings { v % report_data }

    [k, v]
  }.to_h

  YAML.dump(frontmatter) + "---\n\n"
end