Class: Coupdoeil::Tag
- Inherits:
-
Object
- Object
- Coupdoeil::Tag
- Defined in:
- app/models/coupdoeil/tag.rb
Instance Method Summary collapse
-
#initialize(popover:, popover_options:, attributes:) ⇒ Tag
constructor
A new instance of Tag.
- #popover_attributes(prefixed: false) ⇒ Object
- #render_in(view_context, &block) ⇒ Object
Constructor Details
#initialize(popover:, popover_options:, attributes:) ⇒ Tag
Returns a new instance of Tag.
7 8 9 10 11 12 |
# File 'app/models/coupdoeil/tag.rb', line 7 def initialize(popover:, popover_options:, attributes:) @popover_setup = popover @popover_setup.() if @attributes = attributes @popover_setup..validate! end |
Instance Method Details
#popover_attributes(prefixed: false) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/coupdoeil/tag.rb', line 27 def popover_attributes(prefixed: false) attributes = { popover_options: .to_base36 } unless .preload? params = Params.serialize(popover_setup.params).sole.presence&.to_json attributes.merge!(popover_type: popover_setup.identifier, popover_params: params) end if Coupdoeil.config. attributes.merge!(.to_h.transform_keys { "popover_#{_1}".to_sym }) end attributes.transform_keys! { "data-#{_1.name.tr("_", "-")}" } if prefixed attributes end |
#render_in(view_context, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/coupdoeil/tag.rb', line 14 def render_in(view_context, &block) ActiveSupport::Notifications.instrument("render_tag.coupdoeil") do content = view_context.capture(&block) if block_given? view_context.content_tag("coup-doeil", **tag_attributes) do if .preload? view_context.tag.template(view_context.render(popover_setup), class: "popover-content") + content else content end end end end |