Module: GuidesStyle18F::FrontMatter
- Defined in:
- lib/guides_style_18f/navigation.rb
Class Method Summary collapse
- .load(basedir) ⇒ Object
- .validate(front_matter) ⇒ Object
- .validate_with_message_upon_error(front_matter) ⇒ Object
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.(front_matter) files_with_errors = validate front_matter return if files_with_errors.empty? = ['The following files have errors in their front matter:'] files_with_errors.each do |file, errors| << " #{file}:" .concat errors.map { |error| " #{error}" } end .join "\n" unless .size == 1 end |