Module: Railstart::UI

Defined in:
lib/railstart/ui.rb

Overview

Provides UI enhancement utilities for the Railstart CLI.

Handles ASCII art headers, styled boxes, and visual polish to create a Laravel-like installer experience.

Defined Under Namespace

Classes: NullPastel

Constant Summary collapse

LOGO =

ASCII art logo for Railstart

<<~LOGO
  ╔═╗┌─┐┬┬  ┌─┐┌┬┐┌─┐┬─┐┌┬┐
  ╠╦╝├─┤││  └─┐ │ ├─┤├┬┘ │
  ╩╚═┴ ┴┴┴─┘└─┘ ┴ ┴ ┴┴└─ ┴
LOGO

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error(message) ⇒ void

This method returns an undefined value.

Display an error message with icon.

Parameters:

  • message (String)

    the error message



104
105
106
# File 'lib/railstart/ui.rb', line 104

def error(message)
  puts pastel.red("#{message}")
end

.info(message) ⇒ void

This method returns an undefined value.

Display an info message with icon.

Parameters:

  • message (String)

    the info message



113
114
115
# File 'lib/railstart/ui.rb', line 113

def info(message)
  puts pastel.blue("#{message}")
end

.pastelPastel

Lazy-load Pastel for color formatting.

Returns:

  • (Pastel)

    pastel instance



121
122
123
124
125
126
127
128
129
130
# File 'lib/railstart/ui.rb', line 121

def pastel
  @pastel ||= begin
    require "pastel"
    Pastel.new
  rescue LoadError
    # Fallback to no-op if pastel is not available
    # (tty-prompt depends on pastel, so this should never happen)
    NullPastel.new
  end
end

.rails_versionString

Detect the installed Rails version.

Returns:

  • (String)

    Rails version or "Unknown" if not found



60
61
62
63
64
65
66
67
68
# File 'lib/railstart/ui.rb', line 60

def rails_version
  require "bundler"
  Bundler.with_unbundled_env do
    version_output = `rails --version 2>/dev/null`.strip
    version_output[/Rails (\d+\.\d+\.\d+)/, 1] || "Unknown"
  end
rescue StandardError
  "Unknown"
end

.section(title, separator: true) ⇒ void

This method returns an undefined value.

Display a section header with optional separator line.

Parameters:

  • title (String)

    section title

  • separator (Boolean) (defaults to: true)

    whether to show a line underneath



76
77
78
79
# File 'lib/railstart/ui.rb', line 76

def section(title, separator: true)
  puts pastel.cyan.bold(title.to_s)
  puts pastel.dim("" * 60) if separator
end

.show_logo(color: :cyan) ⇒ void

This method returns an undefined value.

Display the Railstart ASCII art logo with version and optional color.

Parameters:

  • color (Symbol) (defaults to: :cyan)

    color name (e.g., :cyan, :green, :magenta)



25
26
27
28
29
30
# File 'lib/railstart/ui.rb', line 25

def (color: :cyan)
  require_relative "version"
  puts pastel.send(color, LOGO)
  puts pastel.dim("      v#{Railstart::VERSION}")
  puts
end

.show_welcome(message = nil) ⇒ void

This method returns an undefined value.

Display a styled welcome message in a box.

Parameters:

  • message (String) (defaults to: nil)

    the welcome text to display (defaults to Rails version message)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/railstart/ui.rb', line 37

def show_welcome(message = nil)
  message ||= "Interactive Rails #{rails_version} Application Generator"

  box = TTY::Box.frame(
    width: 60,
    height: 3,
    align: :center,
    padding: [0, 1],
    border: :thick,
    style: {
      fg: :cyan,
      border: { fg: :cyan }
    }
  ) { message }

  puts box
  puts # blank line
end

.success(message) ⇒ void

This method returns an undefined value.

Display a success message with checkmark.

Parameters:

  • message (String)

    the success message



86
87
88
# File 'lib/railstart/ui.rb', line 86

def success(message)
  puts pastel.green("#{message}")
end

.warning(message) ⇒ void

This method returns an undefined value.

Display a warning message with icon.

Parameters:

  • message (String)

    the warning message



95
96
97
# File 'lib/railstart/ui.rb', line 95

def warning(message)
  puts pastel.yellow("#{message}")
end

Instance Method Details

#error(message) ⇒ void (private)

This method returns an undefined value.

Display an error message with icon.

Parameters:

  • message (String)

    the error message



104
105
106
# File 'lib/railstart/ui.rb', line 104

def error(message)
  puts pastel.red("#{message}")
end

#info(message) ⇒ void (private)

This method returns an undefined value.

Display an info message with icon.

Parameters:

  • message (String)

    the info message



113
114
115
# File 'lib/railstart/ui.rb', line 113

def info(message)
  puts pastel.blue("#{message}")
end

#pastelPastel (private)

Lazy-load Pastel for color formatting.

Returns:

  • (Pastel)

    pastel instance



121
122
123
124
125
126
127
128
129
130
# File 'lib/railstart/ui.rb', line 121

def pastel
  @pastel ||= begin
    require "pastel"
    Pastel.new
  rescue LoadError
    # Fallback to no-op if pastel is not available
    # (tty-prompt depends on pastel, so this should never happen)
    NullPastel.new
  end
end

#rails_versionString (private)

Detect the installed Rails version.

Returns:

  • (String)

    Rails version or "Unknown" if not found



60
61
62
63
64
65
66
67
68
# File 'lib/railstart/ui.rb', line 60

def rails_version
  require "bundler"
  Bundler.with_unbundled_env do
    version_output = `rails --version 2>/dev/null`.strip
    version_output[/Rails (\d+\.\d+\.\d+)/, 1] || "Unknown"
  end
rescue StandardError
  "Unknown"
end

#section(title, separator: true) ⇒ void (private)

This method returns an undefined value.

Display a section header with optional separator line.

Parameters:

  • title (String)

    section title

  • separator (Boolean) (defaults to: true)

    whether to show a line underneath



76
77
78
79
# File 'lib/railstart/ui.rb', line 76

def section(title, separator: true)
  puts pastel.cyan.bold(title.to_s)
  puts pastel.dim("" * 60) if separator
end

#show_logo(color: :cyan) ⇒ void (private)

This method returns an undefined value.

Display the Railstart ASCII art logo with version and optional color.

Parameters:

  • color (Symbol) (defaults to: :cyan)

    color name (e.g., :cyan, :green, :magenta)



25
26
27
28
29
30
# File 'lib/railstart/ui.rb', line 25

def (color: :cyan)
  require_relative "version"
  puts pastel.send(color, LOGO)
  puts pastel.dim("      v#{Railstart::VERSION}")
  puts
end

#show_welcome(message = nil) ⇒ void (private)

This method returns an undefined value.

Display a styled welcome message in a box.

Parameters:

  • message (String) (defaults to: nil)

    the welcome text to display (defaults to Rails version message)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/railstart/ui.rb', line 37

def show_welcome(message = nil)
  message ||= "Interactive Rails #{rails_version} Application Generator"

  box = TTY::Box.frame(
    width: 60,
    height: 3,
    align: :center,
    padding: [0, 1],
    border: :thick,
    style: {
      fg: :cyan,
      border: { fg: :cyan }
    }
  ) { message }

  puts box
  puts # blank line
end

#success(message) ⇒ void (private)

This method returns an undefined value.

Display a success message with checkmark.

Parameters:

  • message (String)

    the success message



86
87
88
# File 'lib/railstart/ui.rb', line 86

def success(message)
  puts pastel.green("#{message}")
end

#warning(message) ⇒ void (private)

This method returns an undefined value.

Display a warning message with icon.

Parameters:

  • message (String)

    the warning message



95
96
97
# File 'lib/railstart/ui.rb', line 95

def warning(message)
  puts pastel.yellow("#{message}")
end