Class: Eskimo::ASCII::Highlight

Inherits:
Component show all
Defined in:
lib/eskimo/ascii/components/highlight.rb

Overview

Highlight a substring with ASCII arrows.

Highlight.new(pattern: /lol/) do
  "- include: lol://file.yml"
end
# => "- include: lol://file.yml"
#                ^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern:, style: [:red, :bold, :underline], &children) ⇒ Highlight

Returns a new instance of Highlight.



15
16
17
18
19
20
21
# File 'lib/eskimo/ascii/components/highlight.rb', line 15

def initialize(pattern:, style: [:red, :bold, :underline], &children)
  @pastel = Pastel.new
  @pattern = pattern
  @style = style

  super(&children)
end

Instance Attribute Details

#pastelObject (readonly)

Returns the value of attribute pastel.



13
14
15
# File 'lib/eskimo/ascii/components/highlight.rb', line 13

def pastel
  @pastel
end

#patternObject (readonly)

Returns the value of attribute pattern.



13
14
15
# File 'lib/eskimo/ascii/components/highlight.rb', line 13

def pattern
  @pattern
end

#styleObject (readonly)

Returns the value of attribute style.



13
14
15
# File 'lib/eskimo/ascii/components/highlight.rb', line 13

def style
  @style
end

Instance Method Details

#renderObject



23
24
25
26
27
# File 'lib/eskimo/ascii/components/highlight.rb', line 23

def render(**)
  super.sub(pattern) do |substring|
    pastel.decorate(substring, *style)
  end
end