Class: Unmagic::Color::Console::Help

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/color/console/help.rb

Overview

Renders the help text for the console.

Examples:

puts Unmagic::Color::Console::Help.new.render

Instance Method Summary collapse

Instance Method Details

#renderString

Render the help text with syntax highlighting.

Returns:

  • (String)

    The formatted help text



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/unmagic/color/console/help.rb', line 16

def render
  link = highlighter.link("https://github.com/unmagic/unmagic-color")

  code = highlighter.highlight(<<~RUBY)
    # Parse colors
    parse("#ff5733")
    rgb(255, 87, 51)
    hsl(9, 100, 60)
    oklch(0.65, 0.22, 30)
    parse("rebeccapurple")

    # Manipulate colors
    color = parse("#ff5733")
    color.lighten(0.1)
    color.darken(0.1)
    color.saturate(0.1)
    color.desaturate(0.1)
    color.rotate(30)

    # Convert between formats
    color.to_rgb
    color.to_hsl
    color.to_oklch
    color.to_hex
    color.to_css_oklch

    # Create gradients
    gradient(:linear, ["#FF0000", "#0000FF"]).rasterize(width: 10).pixels[0].map(&:to_hex)

    # Helpers
    rgb(255, 87, 51)
    hsl(9, 100, 60)
    oklch(0.65, 0.22, 30)
    parse("#ff5733")
    gradient(:linear, ["#FF0000", "#0000FF"])
    percentage(50)
  RUBY

  "#{link}\n\n#{code}"
end

#to_sString

Returns The rendered help text.

Returns:

  • (String)

    The rendered help text



58
59
60
# File 'lib/unmagic/color/console/help.rb', line 58

def to_s
  render
end