Class: Bootstrap5RailsExtensions::ModalHelper::ModalBuilder
- Inherits:
-
Object
- Object
- Bootstrap5RailsExtensions::ModalHelper::ModalBuilder
- Defined in:
- app/helpers/bootstrap5_rails_extensions/modal_helper.rb
Overview
モーダルの各セクションを構築する小さなDSL用ビルダー。
Instance Method Summary collapse
- #body(content = nil, full: false, &block) ⇒ Object
- #footer(content = nil, full: false, &block) ⇒ Object
- #header(content = nil, full: false, &block) ⇒ Object
-
#initialize(view_context, modal_id:, default_title:) ⇒ ModalBuilder
constructor
A new instance of ModalBuilder.
- #render_modal_content ⇒ Object
- #with_form(form_builder) ⇒ Object
Constructor Details
#initialize(view_context, modal_id:, default_title:) ⇒ ModalBuilder
Returns a new instance of ModalBuilder.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/bootstrap5_rails_extensions/modal_helper.rb', line 77 def initialize(view_context, modal_id:, default_title:) @view = view_context @modal_id = modal_id @default_title = default_title @header_html = nil @header_full = false @body_fragments = [] @body_full = nil = [] = nil @current_form_builder = nil end |
Instance Method Details
#body(content = nil, full: false, &block) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/helpers/bootstrap5_rails_extensions/modal_helper.rb', line 107 def body(content = nil, full: false, &block) html = extract_content(content, &block) if full raise ArgumentError, _("モーダル本文はfull: trueでは一度だけ設定できます") if @body_full || @body_fragments.any? @body_full = html else @body_fragments << html end self end |
#footer(content = nil, full: false, &block) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/helpers/bootstrap5_rails_extensions/modal_helper.rb', line 120 def (content = nil, full: false, &block) html = extract_content(content, &block) if full raise ArgumentError, _("モーダルフッターはfull: trueでは一度だけ設定できます") if || .any? = html else << html end self end |
#header(content = nil, full: false, &block) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/helpers/bootstrap5_rails_extensions/modal_helper.rb', line 98 def header(content = nil, full: false, &block) raise ArgumentError, _("モーダルヘッダーは一度だけ定義できます") if @header_html html = extract_content(content, &block) @header_full = full @header_html = html self end |
#render_modal_content ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/helpers/bootstrap5_rails_extensions/modal_helper.rb', line 133 def render_modal_content body_markup = build_body_markup header_markup = build_header_markup = @view.content_tag(:div, class: "modal-content") do @view.concat(header_markup) if header_markup @view.concat(body_markup) @view.concat() if end end |
#with_form(form_builder) ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/helpers/bootstrap5_rails_extensions/modal_helper.rb', line 90 def with_form(form_builder) previous = @current_form_builder @current_form_builder = form_builder yield(self) ensure @current_form_builder = previous end |