Module: Clack::Box

Defined in:
lib/clack/box.rb

Overview

Renders a box with optional title around content Supports alignment, padding, and rounded/square corners

Class Method Summary collapse

Class Method Details

.render(message = "", title: "", content_align: :left, title_align: :left, width: :auto, title_padding: 1, content_padding: 2, rounded: true, format_border: nil, output: $stdout) ⇒ Object

Parameters:

  • message (String) (defaults to: "")

    Content to display in the box

  • title (String) (defaults to: "")

    Optional title for the box

  • content_align (:left, :center, :right) (defaults to: :left)

    Content alignment

  • title_align (:left, :center, :right) (defaults to: :left)

    Title alignment

  • width (Integer, :auto) (defaults to: :auto)

    Box width (auto fits to content)

  • title_padding (Integer) (defaults to: 1)

    Padding around title

  • content_padding (Integer) (defaults to: 2)

    Padding around content

  • rounded (Boolean) (defaults to: true)

    Use rounded corners (default: true)

  • format_border (Proc) (defaults to: nil)

    Optional proc to format border characters

  • output (IO) (defaults to: $stdout)

    Output stream



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/clack/box.rb', line 18

def render(
  message = "",
  title: "",
  content_align: :left,
  title_align: :left,
  width: :auto,
  title_padding: 1,
  content_padding: 2,
  rounded: true,
  format_border: nil,
  output: $stdout
)
  ctx = build_context(message, title, title_padding, content_padding, width, rounded, format_border)
  output.puts build_top_border(ctx[:display_title], ctx[:inner_width], title_padding, title_align, ctx[:symbols], ctx[:h_symbol])
  render_content_lines(output, ctx, content_align, content_padding)
  output.puts "#{ctx[:symbols][2]}#{ctx[:h_symbol] * ctx[:inner_width]}#{ctx[:symbols][3]}"
end