Class: Bs5::ExampleComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bs5::ExampleComponent
- Includes:
- ComponentsHelper
- Defined in:
- app/components/bs5/example_component.rb
Constant Summary
Constants included from ComponentsHelper
Instance Attribute Summary collapse
-
#snippet ⇒ Object
readonly
Returns the value of attribute snippet.
Instance Method Summary collapse
- #highlight ⇒ Object
-
#initialize(snippet:) ⇒ ExampleComponent
constructor
A new instance of ExampleComponent.
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
#snippet ⇒ Object (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
#highlight ⇒ Object
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 |