class Qddrud::Readme
Evaluates an opscode chef cookbook's metadata and github history to generate a README.md file. The README.rb is placed in the root level of the cookbook. This forces cookbook developers to properly use metadata to document their cookbooks efficiently. Additionally, it provides proper attribution for all committers in the project with links back to the contributors github profile. It is written to take advantage of cookbooks that properly utilize both Rake tasks and metadata.
Attributes
Hash map of all site cookbooks including metadata
Path to the site-cookbooks
Public Class Methods
Initialize a new instance of Drud::Readme
Attributes¶ ↑
-
:path
- The local path of the site cookbooks
Examples¶ ↑
This can be placed in a convenient location, such as a Rake task inside the cookbook. When the render method is called, it will overwrite the cookbooks README.md
readme = Drud::Readme.new(File.dirname(__FILE__)) readme.render
# File lib/qddrud/readme.rb, line 52 def initialize(path) @path = File.expand_path(path) @cookbooks = load_cookbooks end
Public Instance Methods
Renders the README.md file and saves it in the cookbooks path.
# File lib/qddrud/readme.rb, line 58 def render markdown = ReadmeTemplate.new( metadata: @metadata, tasks: @tasks, credit: @credit ) template_path = File.join( File.dirname(File.expand_path(__FILE__)), '../../templates/readme.md.erb' ) readme = markdown.render(File.read(template_path)) File.open("#{@cookbook}/README.md", 'w') { |file| file.write(readme) } end
Private Instance Methods
Generates a hash of all site cookbook metadata by cookbook folder name
# File lib/qddrud/readme.rb, line 72 def load_cookbooks # :doc: _cookbooks = Hash.new Dir.glob(File.join(@path, '*/*.rb')).each do |cb_metadata| cb_path = File.dirname(cb_metadata) cb_name = File.basename(cb_path) _cookbooks[cb_name] = [ 'path' => cb_path, 'metadata' => load_metadata(cb_metadata) ] end _cookbooks end
Reads the cookbooks metadata and instantiates an instance of Chef::Cookbook::Metadata
# File lib/qddrud/readme.rb, line 89 def load_metadata(cb_metadata) # :doc: metadata = Chef::Cookbook::Metadata.new metadata.from_file(cb_metadata) metadata end