Class: Documentation::Body::ExamplePreviewComponent

Inherits:
ViewComponent::Base
  • Object
show all
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

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

#callObject



13
# File 'app/components/documentation/body/example_preview_component.rb', line 13

def call; end

#code_previewObject



19
20
21
22
23
# File 'app/components/documentation/body/example_preview_component.rb', line 19

def code_preview
   :pre, class: CSS_CLASSES_DEFAULT.join(" ") do
     :code, h(@source)
  end
end

#html_previewObject



15
16
17
# File 'app/components/documentation/body/example_preview_component.rb', line 15

def html_preview
  raw view_context.render(inline: @source)
end