Module: ModalStack::Helpers::ModalStackAssetsHelper
- Defined in:
- lib/modal_stack/helpers/modal_stack_assets_helper.rb
Overview
Layout-level helpers for wiring modal_stack into the host app.
Instance Method Summary collapse
-
#build_dialog_data(provided, config) ⇒ Object
Merges caller-provided data attrs with the gem-managed ones (controller, max-depth value/strategy).
-
#modal_stack_dialog_tag(**html_options) ⇒ Object
Renders the singleton <dialog> root that the modal-stack Stimulus controller binds to.
-
#modal_stack_javascript_tag ⇒ Object
Emits a no-op SafeBuffer for now — kept as a stable hook for apps that prefer a single line in their layout.
-
#modal_stack_stylesheet_link_tag ⇒ Object
Renders a <link> for the configured CSS provider:.
Instance Method Details
#build_dialog_data(provided, config) ⇒ Object
Merges caller-provided data attrs with the gem-managed ones (controller, max-depth value/strategy). Caller data wins on key collision.
36 37 38 39 40 41 42 43 |
# File 'lib/modal_stack/helpers/modal_stack_assets_helper.rb', line 36 def build_dialog_data(provided, config) existing = provided || {} controllers = [existing[:controller], config.stack_root_data_attribute].compact.join(" ").strip data = existing.merge(controller: controllers) data[:modal_stack_max_depth_value] ||= config.max_depth if config.max_depth data[:modal_stack_max_depth_strategy_value] ||= config.max_depth_strategy.to_s data end |
#modal_stack_dialog_tag(**html_options) ⇒ Object
Renders the singleton <dialog> root that the modal-stack Stimulus controller binds to. Drop into your application layout:
<%= modal_stack_dialog_tag %>
25 26 27 28 29 30 31 32 |
# File 'lib/modal_stack/helpers/modal_stack_assets_helper.rb', line 25 def modal_stack_dialog_tag(**) config = ModalStack.configuration attrs = .dup attrs[:id] ||= config.dialog_id attrs[:data] = build_dialog_data(attrs[:data], config) content_tag(:dialog, "".html_safe, attrs) end |
#modal_stack_javascript_tag ⇒ Object
Emits a no-op SafeBuffer for now — kept as a stable hook for apps that prefer a single line in their layout. The actual JS loading is handled by the host app’s bundler / importmap.
48 49 50 |
# File 'lib/modal_stack/helpers/modal_stack_assets_helper.rb', line 48 def modal_stack_javascript_tag(**) ActiveSupport::SafeBuffer.new end |
#modal_stack_stylesheet_link_tag ⇒ Object
Renders a <link> for the configured CSS provider:
<%= modal_stack_stylesheet_link_tag %>
Returns an empty SafeBuffer when ‘config.css_provider = :none`, so apps can call this unconditionally.
13 14 15 16 17 18 |
# File 'lib/modal_stack/helpers/modal_stack_assets_helper.rb', line 13 def modal_stack_stylesheet_link_tag(**) provider = ModalStack.configuration.css_provider return ActiveSupport::SafeBuffer.new if provider == :none stylesheet_link_tag("modal_stack/#{provider}", **) end |