lib/capitate/task_node.rb in capitate-0.2.11 vs lib/capitate/task_node.rb in capitate-0.2.13
- old
+ new
@@ -48,17 +48,15 @@
def add_task(task)
@tasks << task
end
# Get "child" nodes (sorted).
- #
def sorted_nodes
nodes.sort_by(&:name)
end
# Get tasks (sorted).
- #
def sorted_tasks
tasks.sort_by(&:fully_qualified_name) # { |t| t.name.to_s }
end
# Iterate over ALL "child" nodes, depth first.
@@ -105,10 +103,12 @@
def write_doc(dir, file_name = nil, title = nil, options = {}, &block)
file_name ||= full_name
title ||= full_name(":")
+
+
path = "#{dir}/#{file_name}.txt"
puts "%10s %-30s" % [ "create", path ]
File.open(path, "w") do |file|
file.puts "h1. #{title}\n\n"
@@ -157,19 +157,22 @@
# Task details
#
unless tasks.empty?
file.puts "\n\nh2. Task documentation\n\n"
sorted_tasks.each do |task|
+ file.puts %{<div class="recipe">\n\n}
file.puts "h3(##{task.fully_qualified_name}). #{task.fully_qualified_name}\n\n"
- file.puts "#{unindent(task.desc)}\n\n\n\n"
+ file.puts "#{unindent(task.desc)}\n\n"
+ file.puts "</div>\n\n\n"
end
end
#
# Write doc (recursively for "child" namespace)
+ #
sorted_nodes.each do |snode|
- snode.write_doc(dir)
+ snode.write_doc(dir, nil, nil, options)
end
# If block then let it do stuff with open file
if block_given?
file.puts "\n\n"
@@ -177,11 +180,10 @@
end
end
end
# Node to string.
- #
def to_s(level = 0)
spaces = " "
indent = (0...level).collect { spaces }.join("")
# Ignore top node (level = -1)
@@ -195,39 +197,35 @@
sorted_nodes.each do |node|
s += node.to_s(level + 1)
end
s
- end
+ end
- # Class methods
- class << self
+ # Create nodes and and task to node.
+ #
+ # If task is "mysql:centos:install", the nodes will look like:
+ #
+ # (top node) -> (mysql node) -> (centos node; w/ tasks: install)
+ #
+ # ==== Options
+ # +top_node+:: Node to start at
+ # +task+:: Task to add
+ #
+ def self.populate_with_task(top_node, task)
+ node_names = task.namespace.fully_qualified_name.split(":")
- # Create nodes and and task to node.
- #
- # If task is "mysql:centos:install", the nodes will look like:
- #
- # (top node) -> (mysql node) -> (centos node; w/ tasks: install)
- #
- # ==== Options
- # +top_node+:: Node to start at
- # +task+:: Task to add
- #
- def populate_with_task(top_node, task)
- node_names = task.namespace.fully_qualified_name.split(":")
-
- node = top_node
-
- node_names.each do |name|
- parent_node = node
- node = parent_node.find(name)
- if !node
- node = self.new(name, parent_node)
- parent_node.add_node(node)
- end
+ node = top_node
+
+ node_names.each do |name|
+ parent_node = node
+ node = parent_node.find(name)
+ if !node
+ node = self.new(name, parent_node)
+ parent_node.add_node(node)
end
- node.add_task(task)
end
-
+ node.add_task(task)
end
+
end
\ No newline at end of file