Module: GuidesStyle18F::FrontMatter

Defined in:
lib/guides_style_18f/navigation.rb

Class Method Summary collapse

Class Method Details

.load(basedir) ⇒ Object



7
8
9
10
11
# File 'lib/guides_style_18f/navigation.rb', line 7

def self.load(basedir)
  Dir[File.join basedir, 'pages', '**', '*.md'].map do |f|
    [f[basedir.size + 1..-1], SafeYAML.load_file(f, safe: true)]
  end.to_h
end

.validate(front_matter) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/guides_style_18f/navigation.rb', line 24

def self.validate(front_matter)
  front_matter.map do |file, data|
    next [file, ['no front matter defined']] unless data.instance_of? Hash
    errors = missing_property_errors(data) + permalink_errors(data)
    [file, errors] unless errors.empty?
  end.compact.to_h
end

.validate_with_message_upon_error(front_matter) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/guides_style_18f/navigation.rb', line 13

def self.validate_with_message_upon_error(front_matter)
  files_with_errors = validate front_matter
  return if files_with_errors.empty?
  message = ['The following files have errors in their front matter:']
  files_with_errors.each do |file, errors|
    message << "  #{file}:"
    message.concat errors.map { |error| "    #{error}" }
  end
  message.join "\n" unless message.size == 1
end