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

Instance Method Details

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
33
34
35
# File 'lib/modal_stack/helpers/modal_stack_assets_helper.rb', line 25

def modal_stack_dialog_tag(**html_options)
  config = ModalStack.configuration
  attrs = html_options.dup
  attrs[:id] ||= config.dialog_id

  existing_data = attrs[:data] || {}
  controllers = [existing_data[:controller], config.stack_root_data_attribute].compact.join(" ").strip
  attrs[:data] = existing_data.merge(controller: controllers)

  (:dialog, "".html_safe, attrs)
end

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.



40
41
42
# File 'lib/modal_stack/helpers/modal_stack_assets_helper.rb', line 40

def modal_stack_javascript_tag(**)
  ActiveSupport::SafeBuffer.new
end

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