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
- 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", drawer_position: false, footer_divider: nil, header: nil, header_divider: nil, overlay: nil, padding: nil, size: nil, content_div_data: nil, request: nil, title: nil) ⇒ Base
constructor
A new instance of Base.
- #title(&block) ⇒ 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", drawer_position: false, footer_divider: nil, header: nil, header_divider: nil, overlay: nil, padding: nil, size: nil, content_div_data: nil, request: nil, title: nil) ⇒ Base
Returns a new instance of Base.
25 26 27 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 |
# File 'lib/ultimate_turbo_modal/base.rb', line 25 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", drawer_position: false, footer_divider: nil, header: nil, header_divider: nil, overlay: nil, padding: nil, size: nil, content_div_data: nil, request: nil, title: nil ) @drawer = drawer_position if drawer? cfg = UltimateTurboModal.configuration.drawer_config @advance = false @advance_url = nil @close_button = .nil? ? cfg. : @drawer_size = self.class.validate_drawer_size!(size || cfg.size) else cfg = UltimateTurboModal.configuration.modal_config adv = advance.nil? ? cfg.advance : advance @advance = !!adv @advance_url = (adv.present? && adv.is_a?(String)) ? adv : nil @close_button = .nil? ? cfg. : @drawer_size = nil end @footer_divider = .nil? ? cfg. : @header = header.nil? ? cfg.header : header @header_divider = header_divider.nil? ? cfg.header_divider : header_divider @overlay = .nil? ? cfg. : @padding = padding.nil? ? cfg.padding : padding @allowed_click_outside_selector = allowed_click_outside_selector @close_button_data_action = @close_button_sr_label = @content_div_data = content_div_data @request = request @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)
170 171 172 173 174 175 176 177 |
# File 'lib/ultimate_turbo_modal/base.rb', line 170 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
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ultimate_turbo_modal/base.rb', line 73 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
112 113 114 115 116 117 |
# File 'lib/ultimate_turbo_modal/base.rb', line 112 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
104 105 106 107 108 109 110 |
# File 'lib/ultimate_turbo_modal/base.rb', line 104 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
99 100 101 |
# File 'lib/ultimate_turbo_modal/base.rb', line 99 def (&block) @footer = block end |
#title(&block) ⇒ Object
95 96 97 |
# File 'lib/ultimate_turbo_modal/base.rb', line 95 def title(&block) @title_block = block end |
#view_template(&block) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/ultimate_turbo_modal/base.rb', line 85 def view_template(&block) if turbo_frame? turbo_frame_tag("modal") do drawer? ? render_drawer(&block) : render_modal(&block) end else render block end end |