Module: AocCli::Helpers::ViewHelper

Included in:
ApplicationController, Components::DocsComponent, Components::PuzzleSyncComponent
Defined in:
lib/aoc_cli/helpers/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#heading(text) ⇒ Object



8
9
10
# File 'lib/aoc_cli/helpers/view_helper.rb', line 8

def heading(text)
  text.to_s.bold.cyan
end

#main_headerObject



4
5
6
# File 'lib/aoc_cli/helpers/view_helper.rb', line 4

def main_header
  heading("aoc-cli::<#{VERSION}>")
end

#success_tagObject



12
13
14
# File 'lib/aoc_cli/helpers/view_helper.rb', line 12

def success_tag
  "Success".green.bold
end

#table_for(*rows, gap: 2, indent: 0) ⇒ Object



16
17
18
19
20
# File 'lib/aoc_cli/helpers/view_helper.rb', line 16

def table_for(*rows, gap: 2, indent: 0)
  rows.map! { |row| row.map(&:to_s) }

  TableGenerator.new(rows:, gap:, indent:).generate!
end

#wrap_text(text, width: 80, indent: 0) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aoc_cli/helpers/view_helper.rb', line 22

def wrap_text(text, width: 80, indent: 0)
  raise "indent must be less than width" unless indent < width

  text.gsub(
    # Match the longest string (up to the indented width) thats followed
    # by a non-word char or any combination of newlines.
    /(.{1,#{width - indent}})(?:[^\S\n]+\n?|\n*\Z|\n)|\n/,
    # Surround string fragment with indent and newline.
    "#{' ' * indent}\\1\n"
  ).chomp
end