bin/demo in output_mode-1.6.0 vs bin/demo in output_mode-1.7.0
- old
+ new
@@ -27,65 +27,54 @@
require "bundler/setup"
require "output_mode"
require 'erb'
-module DemoIndex
- extend OutputMode::TLDR::Index
-
- register_callable(header: 'Integer', row_color: [:yellow, :bold]) { |i| i }
- register_callable(header: 'Standard', header_color: [:strikethrough] ) { 'always visible' }
- register_callable(header: 'Verbose', verbose: true) { 'verbose visible' }
- register_callable(header: 'Simplified', verbose: false) { 'simplified visible' }
- register_callable(header: 'Interactive', interactive: true) { 'interactive visible' }
- register_callable(header: 'Non Interactive', interactive: false) { 'non-interactive visible' }
- register_callable(header: 'Yes/True') { true }
- register_callable(header: 'No/False', row_color: [:clear]) { false }
- register_callable(header: 'Missing') { nil }
- register_callable(header: 'Inline') do |interactive:, verbose:|
- if interactive && verbose
- 'interactive-verbose'
- elsif interactive
- 'interactive-simplified'
- elsif verbose
- 'non-interactive-verbose'
+class DemoIndex < OutputMode::Formatters::Index
+ constructor do
+ register(header: 'Integer', row_color: [:yellow, :bold]) { |i| i }
+ register(header: 'Standard', header_color: [:strikethrough] ) { 'always visible' }
+ if verbose?
+ register(header: 'Verbose') { 'verbose visible' }
else
- 'non-interactive-simplified'
+ register(header: 'Simplified') { 'simplified visible' }
end
+ if interactive?
+ register(header: 'Interactive') { 'interactive visible' }
+ else
+ register(header: 'Non Interactive') { 'non-interactive visible' }
+ end
+ register(header: 'Yes/True') { true }
+ register(header: 'No/False', row_color: [:clear]) { false }
+ register(header: 'Missing') { nil }
end
end
-module DemoShow
- extend OutputMode::TLDR::Show
-
- register_callable(header: 'Integer') { |i| i }
- register_callable(header: 'Standard') { 'always visible' }
- register_callable(header: 'Verbose', verbose: true) { 'verbose visible' }
- register_callable(header: 'Simplified', verbose: false) { 'simplified visible' }
- register_callable(header: 'Interactive', interactive: true) { 'interactive visible' }
- register_callable(header: 'Non Interactive', interactive: false) { 'non-interactive visible' }
- register_callable(header: 'Yes/True', section: :boolean) { true }
- register_callable(header: 'No/False', section: :boolean) { false }
- register_callable(header: 'Missing') { nil }
- register_callable(header: 'Tab') { "tab1\ttab2" }
- register_callable(header: 'New line') { "line1\nline2" }
+class DemoShow < OutputMode::Formatters::Show
+ constructor do
+ register(header: 'Integer') { |i| i }
+ register(header: 'Standard') { 'always visible' }
+ if verbose?
+ register(header: 'Verbose') { 'verbose visible' }
+ else
+ register(header: 'Simplified') { 'simplified visible' }
+ end
+ if interactive?
+ register(header: 'Interactive') { 'interactive visible' }
+ else
+ register(header: 'Non Interactive') { 'non-interactive visible' }
+ end
+ register(header: 'Yes/True', section: :boolean) { true }
+ register(header: 'No/False', section: :boolean) { false }
+ register(header: 'Missing') { nil }
+ register(header: 'Tab') { "tab1\ttab2" }
+ register(header: 'New line') { "line1\nline2" }
+ end
end
data = [1, 2, 3]
-other_template = ERB.new(<<~TEMPLATE, nil, '-')
-# Non boolean values
-<% each(:other) do |value, field:, padding:, **_| -%>
-<%= padding -%><%= pastel.blue.bold field -%><%= pastel.bold ':' -%> <%= pastel.green value %>
-<% end -%>
-
-# Boolean Values
-<% each(:boolean) do |value, field:, padding:, **_| -%>
-<%= padding -%><%= pastel.blue.bold field -%><%= pastel.bold ':' -%> <%= pastel.green value %>
-<% end -%>
-TEMPLATE
-
puts <<~EOF
#==============================================================================
#==============================================================================
# INDEX OUTPUTS
#==============================================================================
@@ -93,38 +82,38 @@
#==============================================================================
# Default Demo Index
# Simplified in interactive shells, verbose in non-interactive
#==============================================================================
-#{DemoIndex.build_output.render(*data)}
+#{DemoIndex.render(*data)}
#==============================================================================
# Demo Verbose Index
#==============================================================================
-#{DemoIndex.build_output(verbose: true).render(*data)}
+#{DemoIndex.render(*data, verbose: true)}
#==============================================================================
# Demo "Simplified" Index
#==============================================================================
-#{DemoIndex.build_output(verbose: false).render(*data)}
+#{DemoIndex.render(*data, verbose: false)}
#==============================================================================
# Force Interactive
# Always print as if the shell is interactive
#==============================================================================
-#{DemoIndex.build_output(interactive: true).render(*data)}
+#{DemoIndex.render(*data, interactive: true)}
#==============================================================================
# Force Non-Interactive
# Always print as if the shell is non-interactive
#==============================================================================
-#{DemoIndex.build_output(interactive: false).render(*data)}
+#{DemoIndex.render(*data, interactive: false)}
#==============================================================================
# Demo ASCII Index
#==============================================================================
-#{DemoIndex.build_output(ascii: true).render(*data)}
+#{DemoIndex.render(*data, ascii: true)}
#==============================================================================
#==============================================================================
# SHOW OUTPUTS
#==============================================================================
@@ -132,41 +121,34 @@
#==============================================================================
# Default Settings
# Simplified in interactive shells, verbose in non-interactive
#==============================================================================
-#{DemoShow.build_output.render(*data)}
+#{DemoShow.render(data.first)}
#==============================================================================
# Demo Verbose Show
#==============================================================================
-#{DemoShow.build_output(verbose: true).render(*data)}
+#{DemoShow.render(data.first, verbose: true)}
#==============================================================================
# Demo "Simplified" Show
#==============================================================================
-#{DemoShow.build_output(verbose: false).render(*data)}
+#{DemoShow.render(data.first, verbose: false)}
#==============================================================================
# Force Interactive
# Always print as if the shell is interactive
#==============================================================================
-#{DemoShow.build_output(interactive: true).render(*data)}
+#{DemoShow.render(data.first, interactive: true)}
#==============================================================================
# Force Non-Interactive
# Always print as if the shell is non-interactive
#==============================================================================
-#{DemoShow.build_output(interactive: false).render(*data)}
+#{DemoShow.render(data.first, interactive: false)}
#==============================================================================
# Demo ASCII Index
#==============================================================================
-#{DemoShow.build_output(ascii: true).render(*data)}
-
-#==============================================================================
-# Group the boolean value separately
-# NOTE: This only occurs in interactive mode
-# Non-Interactive sessions have a fix order
-#==============================================================================
-#{DemoShow.build_output(template: other_template).render(*data)}
+#{DemoShow.render(data.first, ascii: true)}
EOF