Class: KnifeCookbookDoc::CookbookDoc

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/cookbook_doc.rb

Instance Method Summary collapse

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/knife/cookbook_doc.rb', line 39

def run
  unless (cookbook_dir = name_args.first)
    ui.fatal 'Please provide cookbook directory as an argument'
    exit(1)
  end

  cookbook_dir = File.realpath(cookbook_dir)

  model = ReadmeModel.new(cookbook_dir, config[:constraints])

  template = File.read(config[:template_file])
  eruby = Erubis::Eruby.new(template)
  result = eruby.result(model.get_binding)

  File.open("#{cookbook_dir}/#{config[:output_file]}", 'wb') do |f|
    result.each_line do |line|
      f.write line.gsub(/[ \t\r\n]*$/,'')
      f.write "\n"
    end
  end
end