Module: SnippetCli::VarSummaryRenderer
- Defined in:
- lib/snippet_cli/var_summary_renderer.rb
Overview
Pure display/formatting logic for the VarBuilder summary screen. Handles row computation, UI.note output, Gum.table rendering, and cursor erase lambda.
Class Method Summary collapse
-
.rows(vars) ⇒ Object
Returns display rows for the given vars array.
-
.show(vars) ⇒ Object
Renders the summary note + table.
Class Method Details
.rows(vars) ⇒ Object
Returns display rows for the given vars array. Form vars are expanded into dot-notation field rows; all others are [name, type].
14 15 16 17 18 19 20 21 22 |
# File 'lib/snippet_cli/var_summary_renderer.rb', line 14 def self.rows(vars) vars.flat_map do |var| if var[:type] == 'form' form_field_names(var[:params][:layout]).map { |field| ["#{var[:name]}.#{field}", 'form field'] } else [[var[:name], var[:type]]] end end end |
.show(vars) ⇒ Object
Renders the summary note + table. Returns a lambda that erases the output.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/snippet_cli/var_summary_renderer.rb', line 25 def self.show(vars) display_rows = rows(vars) names = display_rows.map { |name, _type| "{{#{name}}}" }.join(', ') text = "Reference your variables in the replacement using {{var}} syntax:\n#{names}" UI.note(text) puts Gum.table(display_rows, columns: %w[Name Type], print: true) puts build_erase(text, display_rows) end |