Class: Impulse::BaseRenderer

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/impulse/base_renderer.rb

Constant Summary collapse

SELF_CLOSING_TAGS =
[:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag:, **system_args) ⇒ BaseRenderer

Returns a new instance of BaseRenderer.



5
6
7
8
9
10
# File 'app/components/impulse/base_renderer.rb', line 5

def initialize(tag:, **system_args)
  @tag = tag
  @system_args = system_args
  @system_args = @system_args.transform_keys { |key| key.to_s.dasherize }
  @system_args[:"data-impulse-view-component"] = ""
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
# File 'app/components/impulse/base_renderer.rb', line 12

def call
  if SELF_CLOSING_TAGS.include?(@tag)
    tag(@tag, **@system_args)
  else
    (@tag, content, **@system_args)
  end
end