Module: GuidesStyle18F::FrontMatter

Defined in:
lib/guides_style_18f/navigation.rb

Constant Summary collapse

EXTNAMES =
%w(.md .html)

Class Method Summary collapse

Class Method Details

.load(basedir) ⇒ Object



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

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



33
34
35
36
37
38
39
# File 'lib/guides_style_18f/navigation.rb', line 33

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



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

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