diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-04-24 02:41:16 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-04-24 02:41:16 +0000 |
| commit | 9526e536fd66828b4f7f3e9fb59177d30e24e2b0 (patch) | |
| tree | 15be99b1aac6b23364f693ba9860e9c017a12986 /lib/puppet/util | |
| parent | 8d3673d5df4f09909f092c5cb42ef8870762db1a (diff) | |
Mostly done with the conversion to restructured text, but there are still some tweaks to perform on the typedocs output.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2408 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util')
| -rw-r--r-- | lib/puppet/util/docs.rb | 45 | ||||
| -rw-r--r-- | lib/puppet/util/provider_features.rb | 27 |
2 files changed, 57 insertions, 15 deletions
diff --git a/lib/puppet/util/docs.rb b/lib/puppet/util/docs.rb index ebbce7317..38a6eeb26 100644 --- a/lib/puppet/util/docs.rb +++ b/lib/puppet/util/docs.rb @@ -27,6 +27,51 @@ module Puppet::Util::Docs end end + # Build a table + def doctable(headers, data) + str = "\n\n" + + lengths = [] + # Figure out the longest field for all columns + data.each do |name, values| + [name, values].flatten.each_with_index do |value, i| + lengths[i] ||= 0 + lengths[i] = value.to_s.length if value.to_s.length > lengths[i] + end + end + + # The headers could also be longest + headers.each_with_index do |value, i| + lengths[i] = value.to_s.length if value.to_s.length > lengths[i] + end + + # Add the top header row + str += lengths.collect { |num| "=" * num }.join(" ") + "\n" + + # And the header names + str += headers.zip(lengths).collect { |value, num| pad(value, num) }.join(" ") + "\n" + + # And the second header row + str += lengths.collect { |num| "=" * num }.join(" ") + "\n" + + # Now each data row + data.sort { |a, b| a[0].to_s <=> b[0].to_s }.each do |name, rows| + str += [name, rows].flatten.zip(lengths).collect do |value, length| + pad(value, length) + end.join(" ") + "\n" + end + + # And the bottom line row + str += lengths.collect { |num| "=" * num }.join(" ") + "\n" + + str + "\n" + end + + # Pad a field with spaces + def pad(value, length) + value.to_s + (" " * (length - value.to_s.length)) + end + # Handle the inline indentation in the docs. def scrub(text) # Stupid markdown diff --git a/lib/puppet/util/provider_features.rb b/lib/puppet/util/provider_features.rb index 773f0ec98..b6e54b5bd 100644 --- a/lib/puppet/util/provider_features.rb +++ b/lib/puppet/util/provider_features.rb @@ -1,10 +1,10 @@ # Provides feature definitions. module Puppet::Util::ProviderFeatures - # The class that models the features and handles checking whether the features # are present. class ProviderFeature require 'puppet/util/methodhelper' + require 'puppet/util/docs' require 'puppet/util' include Puppet::Util include Puppet::Util::MethodHelper @@ -76,27 +76,24 @@ module Puppet::Util::ProviderFeatures names = @features.keys.sort { |a,b| a.to_s <=> b.to_s } names.each do |name| doc = @features[name].docs.gsub(/\n\s+/, " ") - str += " - **%s**: %s\n" % [name, doc] + str += "- **%s**: %s\n" % [name, doc] end + if providers.length > 0 - str += "<table><tr><th></th>\n" - names.each do |name| - str += "<th>%s</th>" % name - end - str += "</tr>\n" + headers = ["Provider", names].flatten + data = {} providers.each do |provname| + data[provname] = [] prov = provider(provname) - str += "<tr><td>%s</td>" % provname - names.each do |feature| - have = "" - if prov.feature?(feature) - have = "<strong>X</strong>" + names.each do |name| + if prov.feature?(name) + data[provname] << "**X**" + else + data[provname] << "" end - str += "<td>%s</td>" % have end - str += "</tr>\n" end - str += "</table>\n" + str += doctable(headers, data) end str end |
