Class: TurboBoost::Elements::TagBuilders::BaseTagBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_boost/elements/tag_builders/base_tag_builder.rb

Direct Known Subclasses

ToggleTagsBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context) ⇒ BaseTagBuilder

Returns a new instance of BaseTagBuilder.



6
7
8
9
# File 'lib/turbo_boost/elements/tag_builders/base_tag_builder.rb', line 6

def initialize(view_context)
  @view_context = view_context
  @controller_pack = view_context.turbo_boost # TurboBoost::Commands::ControllerPack
end

Instance Attribute Details

#controller_packObject (readonly)

Returns the value of attribute controller_pack.



4
5
6
# File 'lib/turbo_boost/elements/tag_builders/base_tag_builder.rb', line 4

def controller_pack
  @controller_pack
end

Instance Method Details

#render_tag(name, loading: :eager, **kwargs, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/turbo_boost/elements/tag_builders/base_tag_builder.rb', line 11

def render_tag(name, loading: :eager, **kwargs, &block)
  options = kwargs.select { |_, value| value.present? }
  options.transform_keys! { |key| key.to_s.dasherize }

  loading = :eager unless loading == :lazy
  if loading == :eager
    view_context.tag.public_send(name.to_sym, **options, &block)
  else
    view_context.tag.public_send(name.to_sym, **options) {}
  end
end

#view_stackObject



23
24
25
26
27
28
29
# File 'lib/turbo_boost/elements/tag_builders/base_tag_builder.rb', line 23

def view_stack
  prefix = "app/views/"
  locations = caller_locations.select { |location| location.path.include?(prefix) }
  locations.each_with_object(Set.new) do |location, memo|
    memo << location.path[(location.path.index(prefix) + prefix.length)..]
  end
end