Class: Eskimo::Components::Highlight

Inherits:
Eskimo::Component show all
Defined in:
lib/eskimo/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



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

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



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

def pastel
  @pastel
end

#patternObject (readonly)

Returns the value of attribute pattern



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

def pattern
  @pattern
end

#styleObject (readonly)

Returns the value of attribute style



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

def style
  @style
end

Instance Method Details

#renderObject



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

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