Class: Coupdoeil::Popover
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- Coupdoeil::Popover
show all
- Includes:
- AbstractController::Caching, AbstractController::Callbacks, AbstractController::Helpers, AbstractController::Logger, AbstractController::Rendering, AbstractController::Translation, ActionView::Layouts, ActionView::Rendering
- Defined in:
- app/models/coupdoeil/popover.rb,
app/models/coupdoeil/popover/setup.rb,
app/models/coupdoeil/popover/option.rb,
app/models/coupdoeil/popover/registry.rb,
app/models/coupdoeil/popover/options_set.rb,
app/models/coupdoeil/popover/option/cache.rb,
app/models/coupdoeil/popover/option/offset.rb,
app/models/coupdoeil/popover/option/loading.rb,
app/models/coupdoeil/popover/option/trigger.rb,
app/models/coupdoeil/popover/option/animation.rb,
app/models/coupdoeil/popover/option/placement.rb,
app/models/coupdoeil/popover/option/opening_delay.rb,
app/models/coupdoeil/popover/view_context_delegation.rb
Defined Under Namespace
Modules: ViewContextDelegation
Classes: Option, OptionsSet, Registry, Setup
Constant Summary
collapse
- DoubleRenderError =
Class.new(::AbstractController::DoubleRenderError)
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params, cp_view_context) ⇒ Popover
Returns a new instance of Popover.
96
97
98
99
100
|
# File 'app/models/coupdoeil/popover.rb', line 96
def initialize(params, cp_view_context)
super()
@params = params
@__cp_view_context = cp_view_context
end
|
Class Attribute Details
.registry ⇒ Object
Returns the value of attribute registry.
46
47
48
|
# File 'app/models/coupdoeil/popover.rb', line 46
def registry
@registry
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
94
95
96
|
# File 'app/models/coupdoeil/popover.rb', line 94
def params
@params
end
|
Class Method Details
.default_options ⇒ Object
57
|
# File 'app/models/coupdoeil/popover.rb', line 57
def default_options(...) = default_options_for(DEFAULT_OPTIONS_KEY, ...)
|
.default_options_for(*action_names, **option_values) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'app/models/coupdoeil/popover.rb', line 59
def default_options_for(*action_names, **option_values)
if option_values.blank?
@default_options_by_method[action_names.first] || default_options
else
action_names.each do |action_name|
options = @default_options_by_method[action_name] || default_options
@default_options_by_method[action_name] = options.merge(OptionsSet.new(option_values))
end
end
end
|
.inherited(subclass) ⇒ Object
51
52
53
54
55
|
# File 'app/models/coupdoeil/popover.rb', line 51
def inherited(subclass)
super
Coupdoeil::Popover.registry.register(subclass.popover_resource_name, subclass)
subclass.instance_variable_set(:@default_options_by_method, @default_options_by_method.dup)
end
|
.method_missing(method_name, *args) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'app/models/coupdoeil/popover.rb', line 70
def method_missing(method_name, *args, &)
return super unless action_methods.include?(method_name.name)
action_methods.each do |action_name|
define_singleton_method(action_name) { setup_class.new(self).with_type(action_name) }
end
public_send(method_name)
end
|
.popover_resource_name ⇒ Object
48
|
# File 'app/models/coupdoeil/popover.rb', line 48
def popover_resource_name = @popover_resource_name ||= name.delete_suffix("Popover").underscore
|
.respond_to_missing?(method, include_all = false) ⇒ Boolean
79
80
81
|
# File 'app/models/coupdoeil/popover.rb', line 79
def respond_to_missing?(method, include_all = false)
action_methods.include?(method.name) || super
end
|
.setup_class ⇒ Object
83
84
85
86
87
88
89
90
91
|
# File 'app/models/coupdoeil/popover.rb', line 83
def setup_class
@setup_class ||= begin
setup_klass = Class.new(Setup)
action_methods.each do |action_name|
setup_klass.define_method(action_name) { with_type(action_name) }
end
setup_klass
end
end
|
.with ⇒ Object
49
|
# File 'app/models/coupdoeil/popover.rb', line 49
def with(...) = setup_class.new(self).with_params(...)
|
Instance Method Details
#controller ⇒ Object
103
|
# File 'app/models/coupdoeil/popover.rb', line 103
def controller = @__cp_view_context.controller
|
#helpers ⇒ Object
102
|
# File 'app/models/coupdoeil/popover.rb', line 102
def helpers = @__cp_view_context
|
#process(method_name) ⇒ Object
120
121
122
123
124
125
126
127
|
# File 'app/models/coupdoeil/popover.rb', line 120
def process(method_name, *)
benchmark("processed popover #{self.class.popover_resource_name}/#{method_name}", silence: true) do
ActiveSupport::Notifications.instrument("render_popover.coupdoeil") do
super
response_body || render(action_name)
end
end
end
|
#render ⇒ Object
113
114
115
116
117
118
|
# File 'app/models/coupdoeil/popover.rb', line 113
def render(...)
return super unless response_body
raise DoubleRenderError, "Render was called multiple times in this action. \
Also note that render does not terminate execution of the action."
end
|
#view_context ⇒ Object
105
106
107
108
109
110
111
|
# File 'app/models/coupdoeil/popover.rb', line 105
def view_context
super.tap do |context|
context.extend ViewContextDelegation
context.popover = self
context.__cp_view_context = @__cp_view_context
end
end
|