Last active
October 9, 2016 03:00
-
-
Save trombik/b2df709657c08d845b1d3b3916e592d3 to your computer and use it in GitHub Desktop.
create a table for README.md from ansible var files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'psych' | |
require 'pathname' | |
def escape(string) | |
string.gsub(/_/, '\_') | |
end | |
def mdfy_default(file) | |
yaml = Psych.load_file(file) | |
puts '| Variable | Description | Default |' | |
puts '|----------|-------------|---------|' | |
yaml.each do |e| | |
k = e[0] | |
v = e[1].to_s.empty? ? '""' : e[1].to_s | |
puts "| %s | | %s |" % [ escape(k), escape(v) ] | |
end | |
end | |
def mdfy_var(file) | |
yaml = Psych.load_file(file) | |
puts "## #{ file.basename.to_s.split('.').first }" | |
puts '' | |
puts '| Variable | Default |' | |
puts '|----------|---------|' | |
yaml.each do |e| | |
k = e[0] | |
v = e[1].to_s.empty? ? '""' : e[1].to_s | |
puts "| %s | %s |" % [ escape(k), escape(v) ] | |
end | |
end | |
file = Pathname.new('.') + 'defaults' + 'main.yml' | |
mdfy_default(file) | |
puts '' | |
var_dir = Pathname.new('.') + 'vars' | |
var_files = var_dir.children.select { |c| c.file? } | |
var_files.sort.each do |f| | |
mdfy_var(f) | |
puts '' | |
puts 'Created by [yaml2readme.rb](https://gist.github.com/trombik/b2df709657c08d845b1d3b3916e592d3)' | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment