2015-08-22 15:25:16 -04:00
|
|
|
#!/usr/bin/env ruby
|
2017-01-18 13:31:19 -08:00
|
|
|
# frozen_string_literal: true
|
2015-08-22 15:25:16 -04:00
|
|
|
# Usage: script/generate-docs
|
|
|
|
# Reads in the fields, meta, and rules YAML files and produces markdown output
|
|
|
|
# suitable for documenting in the project's README
|
|
|
|
|
|
|
|
require 'yaml'
|
|
|
|
|
2016-02-08 15:37:19 -05:00
|
|
|
fields = YAML.load_file('_data/fields.yml')
|
|
|
|
meta = YAML.load_file('_data/meta.yml')
|
|
|
|
rules = YAML.load_file('_data/rules.yml')
|
2015-08-22 15:25:16 -04:00
|
|
|
|
|
|
|
puts "\n### Fields\n\n"
|
|
|
|
fields.each do |field|
|
2016-02-08 15:37:19 -05:00
|
|
|
puts "* `#{field['name']}` - #{field['description']}"
|
2015-08-22 15:25:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "\n### YAML front matter\n"
|
2016-02-08 15:37:19 -05:00
|
|
|
meta = meta.group_by { |m| m['required'] }
|
2015-08-22 15:25:16 -04:00
|
|
|
|
|
|
|
puts "\n#### Required fields\n\n"
|
2016-02-08 15:37:19 -05:00
|
|
|
meta[true].each do |field|
|
|
|
|
puts "* `#{field['name']}` - #{field['description']}"
|
2015-08-22 15:25:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "\n#### Optional fields\n\n"
|
2016-02-08 15:37:19 -05:00
|
|
|
meta[false].each do |field|
|
|
|
|
puts "* `#{field['name']}` - #{field['description']}"
|
2015-08-22 15:25:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "\n### Rules\n"
|
2016-02-08 15:37:19 -05:00
|
|
|
rules.each do |group, group_rules|
|
2015-08-22 15:25:16 -04:00
|
|
|
puts "\n#### #{group.capitalize}\n\n"
|
2016-02-08 15:37:19 -05:00
|
|
|
group_rules.each do |rule|
|
|
|
|
puts "* `#{rule['tag']}` - #{rule['description']}"
|
2015-08-22 15:25:16 -04:00
|
|
|
end
|
|
|
|
end
|