Sha256: cf6718bbb336ddeac14b3b56a67cb6970ae46b3031d3185dad89ac0b4d0fb2fb

Contents?: true

Size: 1016 Bytes

Versions: 37

Compression:

Stored size: 1016 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# Generates a markdown file containing fact documentation.
# usage: ruby generate.rb > facts.md

require 'yaml'
require 'erb'
require 'ostruct'

PATH_TO_SCHEMA = File.join(File.dirname(__FILE__), '../schema/facter.yaml')
PATH_TO_TEMPLATE = File.join(File.dirname(__FILE__), 'template.erb')

schema = YAML.load_file(PATH_TO_SCHEMA)

def format_facts(fact_hash)
  scope = OpenStruct.new({
                           facts: fact_hash
                         })

  erb = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
          ERB.new(File.read(PATH_TO_TEMPLATE), trim_mode: '-')
        else
          ERB.new(File.read(PATH_TO_TEMPLATE), nil, '-')
        end
  erb.result(scope.instance_eval { binding })
end

print "## Modern Facts\n\n"
print format_facts(schema.reject { |_name, info| info['hidden'] == true })
print "## Legacy Facts\n\n"
print format_facts(schema.reject { |_name, info| info['hidden'].nil? || info['hidden'] == false })

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
facter-4.10.0 lib/docs/generate.rb
facter-4.9.0 lib/docs/generate.rb
facter-4.8.0 lib/docs/generate.rb
facter-4.7.1 lib/docs/generate.rb
facter-4.7.0 lib/docs/generate.rb
facter-4.5.2 lib/docs/generate.rb
facter-4.5.1 lib/docs/generate.rb
facter-4.5.0 lib/docs/generate.rb
facter-4.4.3 lib/docs/generate.rb
facter-4.4.2 lib/docs/generate.rb
facter-4.4.1 lib/docs/generate.rb
facter-4.4.0 lib/docs/generate.rb
facter-4.3.1 lib/docs/generate.rb
facter-4.3.0 lib/docs/generate.rb
facter-4.2.14 lib/docs/generate.rb
facter-4.2.13 lib/docs/generate.rb
facter-4.2.12 lib/docs/generate.rb
facter-4.2.11 lib/docs/generate.rb
facter-4.2.10 lib/docs/generate.rb
facter-4.2.9 lib/docs/generate.rb