Class: Chef2Wiki
- Inherits:
-
Object
- Object
- Chef2Wiki
- Defined in:
- lib/chef2wiki/base.rb,
lib/chef2wiki/chef.rb,
lib/chef2wiki/cookbook.rb,
lib/chef2wiki/mediawiki.rb
Constant Summary collapse
- GEM_DATADIR =
Gem.datadir("chef2wiki") || "data"
- GEM_HOMEDIR =
File.join(ENV["HOME"], ".chef2wiki")
- DEFAULT_CONFIG_PATH =
File.join(GEM_HOMEDIR, "config.yml")
- DEFAULT_TEMPLATES_PATH =
File.join(GEM_HOMEDIR, "templates")
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#wiki ⇒ Object
readonly
Returns the value of attribute wiki.
Instance Method Summary collapse
-
#add_page(title, content, overwrite = true) ⇒ Object
Add page to MediaWiki.
-
#excluded_node_list ⇒ Object
Get excluded node list.
-
#generate_docs ⇒ Object
This requires markdown extension for mediawiki.
-
#initialize(options = {}) ⇒ Chef2Wiki
constructor
A new instance of Chef2Wiki.
-
#node_data(node_name) ⇒ Object
Get data for node.
-
#node_list ⇒ Object
Get node list.
-
#render_node(node) ⇒ Object
Render node.
Constructor Details
#initialize(options = {}) ⇒ Chef2Wiki
Returns a new instance of Chef2Wiki.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chef2wiki/base.rb', line 10 def initialize( = {}) [:config] ||= DEFAULT_CONFIG_PATH [:templates] ||= DEFAULT_TEMPLATES_PATH [:wiki] ||= :mediawiki @options = @config = read_config(File.([:config])) @templates = register_templates(File.([:templates])) @wiki = case [:wiki] when :mediawiki setup_media_wiki end Chef::Config.from_file(File.(config["chef"]["config"])) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/chef2wiki/base.rb', line 3 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/chef2wiki/base.rb', line 3 def @options end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
3 4 5 |
# File 'lib/chef2wiki/base.rb', line 3 def templates @templates end |
#wiki ⇒ Object (readonly)
Returns the value of attribute wiki.
3 4 5 |
# File 'lib/chef2wiki/base.rb', line 3 def wiki @wiki end |
Instance Method Details
#add_page(title, content, overwrite = true) ⇒ Object
Add page to MediaWiki
Attributes
-
title
- Title of the page (String) -
content
- Content of the page (String) -
overwrite
- Overwrite flag (Boolean)
9 10 11 12 13 14 15 16 17 |
# File 'lib/chef2wiki/mediawiki.rb', line 9 def add_page(title, content, overwrite = true) begin print "[MediaWiki]\tCreating page #{title}... " wiki.create(title, content, :overwrite => overwrite) puts "done." rescue Exception => ex puts "[MediaWiki]\tError adding page #{title}: " + ex..to_s end end |
#excluded_node_list ⇒ Object
Get excluded node list.
Returns
-
Node list (Array)
28 29 30 |
# File 'lib/chef2wiki/chef.rb', line 28 def excluded_node_list config["nodes"] ? config["nodes"]["exclude"] : [] end |
#generate_docs ⇒ Object
This requires markdown extension for mediawiki.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/chef2wiki/cookbook.rb', line 5 def generate_docs if config["cookbooks"]["repo_paths"].any? puts "[Chef2Wiki]\tCreating documentation..." @cookbooks = [] config["cookbooks"]["repo_paths"].each do |repo_path| doc_files = File.join(repo_path, "**", "README.md") Dir.glob(File.(doc_files)).sort.each do |file| cookbook = file.gsub("#{File.(repo_path)}/", "").gsub("/README.md", "") if cookbook != "README.md" @cookbooks += [cookbook] @content = File.read(file) add_page(cookbook, templates["documentation"].result(binding)) end end end add_page("Cookbooks_documentation", templates["documentation_list"].result(binding)) end end |
#node_data(node_name) ⇒ Object
Get data for node.
Attributes
-
node_name
- Name of the node from chef (String)
Returns
-
Node data (Hash)
9 10 11 12 13 14 |
# File 'lib/chef2wiki/chef.rb', line 9 def node_data(node_name) node = Chef::Node.load(node_name) data = node.to_hash data["run_list"] = node.run_list.run_list_items return data end |
#node_list ⇒ Object
Get node list.
Returns
-
Node list (Array)
20 21 22 |
# File 'lib/chef2wiki/chef.rb', line 20 def node_list Chef::Node.list.keys end |
#render_node(node) ⇒ Object
Render node.
Attributes
-
node
- Node name (String)
30 31 32 33 34 |
# File 'lib/chef2wiki/base.rb', line 30 def render_node(node) puts "[Chef2Wiki]\tWorking for node #{node}..." @data = node_data(node) templates["node"].result(binding) end |