Class: Eskimo::Components::Highlight
- Inherits:
-
Eskimo::Component
- Object
- Eskimo::Component
- Eskimo::Components::Highlight
- 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
-
#pastel ⇒ Object
readonly
Returns the value of attribute pastel.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
-
#initialize(pattern:, style: [:red, :bold, :underline], &children) ⇒ Highlight
constructor
A new instance of Highlight.
- #render ⇒ Object
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
#pastel ⇒ Object (readonly)
Returns the value of attribute pastel
14 15 16 |
# File 'lib/eskimo/components/highlight.rb', line 14 def pastel @pastel end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern
14 15 16 |
# File 'lib/eskimo/components/highlight.rb', line 14 def pattern @pattern end |
#style ⇒ Object (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
#render ⇒ Object
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 |