Class: Bs5::ExampleComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ComponentsHelper
Defined in:
app/components/bs5/example_component.rb

Constant Summary

Constants included from ComponentsHelper

ComponentsHelper::COMPONENTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentsHelper

#bs5_collapse, #bs5_popover, #bs5_tooltip

Constructor Details

#initialize(snippet:) ⇒ ExampleComponent

Returns a new instance of ExampleComponent.



11
12
13
14
15
# File 'app/components/bs5/example_component.rb', line 11

def initialize(snippet:)
  @snippet = snippet
  @path = snippet.split('/')
  @basename = @path.pop
end

Instance Attribute Details

#snippetObject (readonly)

Returns the value of attribute snippet.



9
10
11
# File 'app/components/bs5/example_component.rb', line 9

def snippet
  @snippet
end

Instance Method Details

#highlightObject



17
18
19
20
21
# File 'app/components/bs5/example_component.rb', line 17

def highlight
  formatter = Rouge::Formatters::HTML.new
  lexer = Rouge::Lexer.find(language)
  formatter.format(lexer.lex(file_content)).html_safe # rubocop:disable Rails/OutputSafety
end