Module: GuidesStyle18F::FrontMatter

Defined in:
lib/guides_style_18f/navigation.rb

Class Method Summary collapse

Class Method Details

.load(basedir) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/guides_style_18f/navigation.rb', line 8

def self.load(basedir)
  # init_file_to_front_matter_map is initializing the map with a nil value
  # for every file that _should_ contain front matter as far as the
  # navigation menu is concerned. Any nil values that remain after merging
  # with the site_file_to_front_matter map will result in a validation
  # error.
  init_file_to_front_matter_map(basedir).merge(
    site_file_to_front_matter(init_site(basedir)))
end

.validate(front_matter) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/guides_style_18f/navigation.rb', line 29

def self.validate(front_matter)
  front_matter.map do |file, data|
    next [file, ['no front matter defined']] if data.nil?
    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



18
19
20
21
22
23
24
25
26
27
# File 'lib/guides_style_18f/navigation.rb', line 18

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