Class: UltimateTurboModal::Base
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- UltimateTurboModal::Base
- Includes:
- Phlex::DeferredRenderWithMainContent
- Defined in:
- lib/ultimate_turbo_modal/base.rb
Direct Known Subclasses
Constant Summary collapse
- CONFIRM_TEMPLATE_ID =
"utmr-confirm-template"- VALID_DRAWER_SIZES =
i[xs sm md lg xl 2xl full].freeze
- VALID_DRAWER_POSITIONS =
i[right left].freeze
Instance Attribute Summary collapse
-
#allowed_click_outside_selector ⇒ Object
Returns the value of attribute allowed_click_outside_selector.
-
#content_div_data ⇒ Object
Returns the value of attribute content_div_data.
-
#request ⇒ Object
Returns the value of attribute request.
Class Method Summary collapse
- .include_turbo_helpers ⇒ Object
- .validate_drawer_position!(value) ⇒ Object
- .validate_drawer_size!(value) ⇒ Object
Instance Method Summary collapse
- #footer(&block) ⇒ Object
-
#initialize(advance: nil, allowed_click_outside_selector: UltimateTurboModal.configuration.allowed_click_outside_selector, close_button: nil, close_button_data_action: "modal#hideModal", close_button_sr_label: "Close modal", close_on_submit: nil, confirm: false, drawer_position: false, footer_divider: nil, header: nil, header_divider: nil, overlay: nil, padding: nil, size: nil, content_div_data: nil, accept_label: nil, cancel_label: nil, request: nil, title: nil) ⇒ Base
constructor
A new instance of Base.
-
#title(&block) ⇒ Object
Both return nil so
<%= m.title do %>writes nothing to the ERB buffer. - #turbo_frame_name ⇒ Object
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(advance: nil, allowed_click_outside_selector: UltimateTurboModal.configuration.allowed_click_outside_selector, close_button: nil, close_button_data_action: "modal#hideModal", close_button_sr_label: "Close modal", close_on_submit: nil, confirm: false, drawer_position: false, footer_divider: nil, header: nil, header_divider: nil, overlay: nil, padding: nil, size: nil, content_div_data: nil, accept_label: nil, cancel_label: nil, request: nil, title: nil) ⇒ Base
Returns a new instance of Base.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ultimate_turbo_modal/base.rb', line 28 def initialize( advance: nil, allowed_click_outside_selector: UltimateTurboModal.configuration.allowed_click_outside_selector, close_button: nil, close_button_data_action: "modal#hideModal", close_button_sr_label: "Close modal", close_on_submit: nil, confirm: false, drawer_position: false, footer_divider: nil, header: nil, header_divider: nil, overlay: nil, padding: nil, size: nil, content_div_data: nil, accept_label: nil, cancel_label: nil, request: nil, title: nil ) @drawer = drawer_position @confirm = confirm @request = request raise ArgumentError, "Cannot render a drawer into the drawer-modal frame (drawers cannot be opened from inside another drawer or modal)" if drawer? && stacked? if confirm? cfg = UltimateTurboModal.configuration.confirm_config @drawer_size = nil @accept_label = accept_label || cfg.accept_label @cancel_label = cancel_label || cfg.cancel_label title ||= cfg.title elsif drawer? cfg = UltimateTurboModal.configuration.drawer_config @drawer_size = self.class.validate_drawer_size!(size || cfg.size) else cfg = UltimateTurboModal.configuration.modal_config @drawer_size = nil end adv = advance.nil? ? cfg.advance : advance @advance = !!adv @advance_url = (adv.present? && adv.is_a?(String)) ? adv : nil = .nil? ? cfg. : @close_on_submit = close_on_submit.nil? ? cfg.close_on_submit : close_on_submit = .nil? ? cfg. : @header = header.nil? ? cfg.header : header @header_divider = header_divider.nil? ? cfg.header_divider : header_divider = .nil? ? cfg. : @padding = padding.nil? ? cfg.padding : padding if stacked? @advance = false @advance_url = nil end @allowed_click_outside_selector = allowed_click_outside_selector = = @content_div_data = content_div_data @title = title self.class.include_turbo_helpers end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, &block) ⇒ Object (private)
233 234 235 236 237 238 239 240 |
# File 'lib/ultimate_turbo_modal/base.rb', line 233 def method_missing(method, *, &block) mod = self.class.included_modules.find { |m| m.method_defined?(method) } if mod mod.instance_method(method).bind_call(self, *, &block) else super end end |
Instance Attribute Details
#allowed_click_outside_selector ⇒ Object
Returns the value of attribute allowed_click_outside_selector.
6 7 8 |
# File 'lib/ultimate_turbo_modal/base.rb', line 6 def allowed_click_outside_selector @allowed_click_outside_selector end |
#content_div_data ⇒ Object
Returns the value of attribute content_div_data.
6 7 8 |
# File 'lib/ultimate_turbo_modal/base.rb', line 6 def content_div_data @content_div_data end |
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'lib/ultimate_turbo_modal/base.rb', line 6 def request @request end |
Class Method Details
.include_turbo_helpers ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ultimate_turbo_modal/base.rb', line 92 def self.include_turbo_helpers return if @turbo_helpers_included include Turbo::FramesHelper include Turbo::StreamsHelper include Phlex::Rails::Helpers::ContentTag include Phlex::Rails::Helpers::Routes include Phlex::Rails::Helpers::Tag @turbo_helpers_included = true end |
.validate_drawer_position!(value) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/ultimate_turbo_modal/base.rb', line 143 def validate_drawer_position!(value) return value if VALID_DRAWER_POSITIONS.include?(value.to_s.to_sym) raise ArgumentError, "Invalid drawer position: #{value.inspect}. Must be one of #{VALID_DRAWER_POSITIONS.map(&:inspect).join(", ")}" end |
.validate_drawer_size!(value) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/ultimate_turbo_modal/base.rb', line 135 def validate_drawer_size!(value) return value if VALID_DRAWER_SIZES.include?(value.to_s.to_sym) return value if value.is_a?(String) && value.match?(/\A\d+(\.\d+)?\s*(rem|em|px|%|vw|vh|dvw|dvh|svw|svh|lvw|lvh|ch|ex|cm|mm|in|pt|pc)\z/) raise ArgumentError, "Invalid drawer size: #{value.inspect}. Must be one of #{VALID_DRAWER_SIZES.map(&:inspect).join(", ")} or a CSS length string (e.g., \"30rem\", \"500px\", \"50vw\")" end |
Instance Method Details
#footer(&block) ⇒ Object
129 130 131 132 |
# File 'lib/ultimate_turbo_modal/base.rb', line 129 def (&block) = block nil end |
#title(&block) ⇒ Object
Both return nil so <%= m.title do %> writes nothing to the ERB buffer.
The assignment's own value is a Proc, and ERB would print it.
124 125 126 127 |
# File 'lib/ultimate_turbo_modal/base.rb', line 124 def title(&block) @title_block = block nil end |
#turbo_frame_name ⇒ Object
118 119 120 |
# File 'lib/ultimate_turbo_modal/base.rb', line 118 def turbo_frame_name stacked? ? "drawer-modal" : "modal" end |
#view_template(&block) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ultimate_turbo_modal/base.rb', line 104 def view_template(&block) if confirm? # Inert until the JS clones it, so it can live in the layout on every # page without a dialog (or its <style> tag) ever being active. template(id: CONFIRM_TEMPLATE_ID) { render_confirm } elsif turbo_frame? turbo_frame_tag(turbo_frame_name) do drawer? ? render_drawer(&block) : render_modal(&block) end else render block end end |