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 hovercards across your application without having to ensure correct options are passed to helper everywhere a specific hovercard is used.
Default options for the class
class ContactHovercard < ApplicationHovercard
default_options placement: :bottom
def tooltip
@contact = params[:contact]
end
end
Default options for one or many specific actions
class ContactHovercard < ApplicationHovercard
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 ContactHovercard.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 hovercard classes, you could define its options on ApplicationHovercard
and it will be shared with all subclasses.
Also note that inherited options set in subclasses keep the untouched inherited values.
class ApplicationHovercard < Coupdoeil::Hovercard
default_options_for :tooltip, animation: false, placement: :bottom
end
class ContactHovercard < ApplicationHovercard
default_options_for :tooltip, placement: :top
end
ApplicationHovercard.default_options_for(:tooltip)
# => { placement: :bottom, animation: false }
ContactHovercard.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.
ContactHovercard.default_options
#=> { placement: :auto, ... }
ContactHovercard.default_options_for(:tooltip)
#=> { animation: false, ... }