Options
Options can be set multiple ways. You can either pass them to the view helper, or set defaults directly in the class declaration.
Options are applied in the following order, from lowest to highest priority:
- Coupdoeil’s defaults
- class defaults
- action specific defaults
- helper
It is advised to define default options directly in classes and pass ad-hoc options to the helper mostly as a way to handle edge-cases. This facilitates uniform rendering of popovers across your application without having to ensure correct options are passed to helper everywhere a specific popover is used.
Options are passed as a hash with lower snake cased keys to either default_options
or default_options_for
methods.
Default options for the class
class ContactPopover < ApplicationPopover
default_options placement: :bottom
def tooltip
@contact = params[:contact]
end
end
Default options for one or many specific actions
class ContactPopover < ApplicationPopover
default_options_for :tooltip, placement: :bottom, loading: :preload
default_options_for :tooltip, :details, animation: false
def tooltip
@contact = params[:contact]
end
def details
# ...
end
end
Options passed to helper
<div>
<%= coupdoeil_hovervard_tag ContactPopover.with(contact:).tooltip, placement: :bottom do %>
...
<% end %>
</div>
Inheritance
Options defined on class can be inherited. This means that if you have a generic action present on many popover classes, you could define its options on ApplicationPopover
and it will be shared with all subclasses.
Also note that inherited options set in subclasses keep the untouched inherited values.
class ApplicationPopover < Coupdoeil::Popover
default_options_for :tooltip, animation: false, placement: :bottom
end
class ContactPopover < ApplicationPopover
default_options_for :tooltip, placement: :top
end
ApplicationPopover.default_options_for(:tooltip)
# => { placement: :bottom, animation: false }
ContactPopover.default_options_for(:tooltip)
# => { placement: :top, animation: false }
Inspecting options
You can inspect options to check either general default options for a class or a specific action.
ContactPopover.default_options
#=> { placement: :auto, ... }
ContactPopover.default_options_for(:tooltip)
#=> { animation: false, ... }