Class: Coupdoeil::Tag

Inherits:
Object
  • Object
show all
Defined in:
app/models/coupdoeil/tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(hovercard:, hovercard_options:, attributes:) ⇒ Tag

Returns a new instance of Tag.



5
6
7
8
9
10
11
# File 'app/models/coupdoeil/tag.rb', line 5

def initialize(hovercard:, hovercard_options:, attributes:)
  @hovercard_setup = hovercard
  @attributes = attributes
  hovercard_options = Hovercard::OptionsSet.new(hovercard_options)
  @hovercard_options_set = hovercard_setup.default_options.merge(hovercard_options)
  @hovercard_options_set.validate!
end

Instance Method Details

#render_in(view_context, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/coupdoeil/tag.rb', line 13

def render_in(view_context, &block)
  ActiveSupport::Notifications.instrument("render_tag.coupdoeil") do
    content = view_context.capture(&block) if block_given?
    view_context.("coup-doeil", **@attributes.merge(hovercard_attributes)) do
      if hovercard_options_set.preload?
        view_context.tag.template(view_context.render(hovercard_setup), class: "hovercard-content") + content
      else
        content
      end
    end
  end
end