class AnsibleDocGenerator::DocGenerator

Attributes

lang[R]
md_output[RW]
playbook_path[R]

Public Class Methods

new(playbook_path, lang) click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 11
def initialize playbook_path, lang
  @playbook_path = playbook_path
  @lang = lang
  @md_output = []
end

Public Instance Methods

call() click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 17
def call
  parse_roles
  write_readme
end

Private Instance Methods

clean_md_output() click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 54
def clean_md_output
  md_output.reject{|line| line.strip == '' || line.nil? }.join("\n\n")
end
generate_doc_for_role(yml_path) click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 50
def generate_doc_for_role yml_path
  md_output << RoleDocExtractor.new(yml_path, lang).call
end
maybe_generate_doc_for_role(yml_path) click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 41
def maybe_generate_doc_for_role yml_path
  if File.exists?(yml_path)
    puts "+ Generating doc for: #{yml_path}"
    generate_doc_for_role yml_path
  else
    puts "- main.yml not found in path #{yml_path}"
  end
end
parse_roles() click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 24
def parse_roles
  paths.each do |path|
    yml_path = tasks_yml_path_for_role(path)
    maybe_generate_doc_for_role yml_path
  end
end
tasks_yml_path_for_role(path) click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 58
def tasks_yml_path_for_role path
  File.join(project_folder, path, 'tasks', 'main.yml')
end
write_readme() click to toggle source
# File lib/ansible_doc_generator/doc_generator.rb, line 31
def write_readme
  doc_path = File.join(project_folder, 'docs', "installation_#{lang}.md")

  delete_if_exists(doc_path)
  FileUtils.mkdir_p(File.dirname(doc_path))
  File.open(doc_path, 'w'){|file| file.write(clean_md_output) }

  puts "> Installation guide saved in #{doc_path}"
end