summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-05-04 12:29:03 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-05-04 12:29:03 -0700
commit4533aa16ec8c9ea4db2fc7de75b01ea056bcf624 (patch)
tree1f9a972820ee888e4668d36c981082a92b7754c2 /lib/puppet/network
parente5b62d7424da24799c4d16f0e104fac3008e2b89 (diff)
parentdda32647b4c11ecb352e469088f2438835ff99d7 (diff)
Merge branch 'bug/2.7.x/7353-unify-face-rendering-with-network-formathandler' into 2.7.x
Diffstat (limited to 'lib/puppet/network')
-rw-r--r--lib/puppet/network/formats.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index 4ca3240d4..082c83ee3 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -160,3 +160,39 @@ end
# This is really only ever going to be used for Catalogs.
Puppet::Network::FormatHandler.create_serialized_formats(:dot, :required_methods => [:render_method])
+
+
+Puppet::Network::FormatHandler.create(:console,
+ :mime => 'text/x-console-text',
+ :weight => 0) do
+ def json
+ @json ||= Puppet::Network::FormatHandler.format(:pson)
+ end
+
+ def render(datum)
+ # String to String
+ return datum if datum.is_a? String
+ return datum if datum.is_a? Numeric
+
+ # Simple hash to table
+ if datum.is_a? Hash and datum.keys.all? { |x| x.is_a? String or x.is_a? Numeric }
+ output = ''
+ column_a = datum.map do |k,v| k.to_s.length end.max + 2
+ column_b = 79 - column_a
+ datum.sort_by { |k,v| k.to_s } .each do |key, value|
+ output << key.to_s.ljust(column_a)
+ output << json.render(value).
+ chomp.gsub(/\n */) { |x| x + (' ' * column_a) }
+ output << "\n"
+ end
+ return output
+ end
+
+ # ...or pretty-print the inspect outcome.
+ return json.render(datum)
+ end
+
+ def render_multiple(data)
+ data.collect(&:render).join("\n")
+ end
+end