Class: Documentation::Body::ExamplePreviewComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Documentation::Body::ExamplePreviewComponent
- Defined in:
- app/components/documentation/body/example_preview_component.rb
Constant Summary collapse
- CSS_CLASSES_DEFAULT =
%w[text-sm mb-2].freeze
- CSS_CLASSES =
CSS_CLASSES_DEFAULT
Instance Method Summary collapse
- #call ⇒ Object
- #code_preview ⇒ Object
- #html_preview ⇒ Object
-
#initialize(source:) ⇒ ExamplePreviewComponent
constructor
A new instance of ExamplePreviewComponent.
Constructor Details
#initialize(source:) ⇒ ExamplePreviewComponent
Returns a new instance of ExamplePreviewComponent.
7 8 9 10 11 |
# File 'app/components/documentation/body/example_preview_component.rb', line 7 def initialize( source: ) @source = source.gsub("<$", "<%").gsub("$>", "%>") end |
Instance Method Details
#call ⇒ Object
13 |
# File 'app/components/documentation/body/example_preview_component.rb', line 13 def call; end |
#code_preview ⇒ Object
19 20 21 22 23 |
# File 'app/components/documentation/body/example_preview_component.rb', line 19 def code_preview content_tag :pre, class: CSS_CLASSES_DEFAULT.join(" ") do content_tag :code, h(@source) end end |
#html_preview ⇒ Object
15 16 17 |
# File 'app/components/documentation/body/example_preview_component.rb', line 15 def html_preview raw view_context.render(inline: @source) end |