2015-08-22 21:25:16 +02:00
|
|
|
#!/usr/bin/env ruby
|
2017-01-18 22:31:19 +01:00
|
|
|
# frozen_string_literal: true
|
2015-08-22 21:25:16 +02: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 21:37:19 +01: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 21:25:16 +02:00
|
|
|
|
|
|
|
puts "\n### Fields\n\n"
|
|
|
|
fields.each do |field|
|
2016-02-08 21:37:19 +01:00
|
|
|
puts "* `#{field['name']}` - #{field['description']}"
|
2015-08-22 21:25:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "\n### YAML front matter\n"
|
2016-02-08 21:37:19 +01:00
|
|
|
meta = meta.group_by { |m| m['required'] }
|
2015-08-22 21:25:16 +02:00
|
|
|
|
|
|
|
puts "\n#### Required fields\n\n"
|
2016-02-08 21:37:19 +01:00
|
|
|
meta[true].each do |field|
|
|
|
|
puts "* `#{field['name']}` - #{field['description']}"
|
2015-08-22 21:25:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "\n#### Optional fields\n\n"
|
2016-02-08 21:37:19 +01:00
|
|
|
meta[false].each do |field|
|
|
|
|
puts "* `#{field['name']}` - #{field['description']}"
|
2015-08-22 21:25:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "\n### Rules\n"
|
2016-02-08 21:37:19 +01:00
|
|
|
rules.each do |group, group_rules|
|
2015-08-22 21:25:16 +02:00
|
|
|
puts "\n#### #{group.capitalize}\n\n"
|
2016-02-08 21:37:19 +01:00
|
|
|
group_rules.each do |rule|
|
|
|
|
puts "* `#{rule['tag']}` - #{rule['description']}"
|
2015-08-22 21:25:16 +02:00
|
|
|
end
|
|
|
|
end
|