Module: FlashUnified::ViewHelper
- Defined in:
- app/helpers/flash_unified/view_helper.rb
Instance Method Summary collapse
-
#flash_container ⇒ Object
flash message display container.
-
#flash_general_error_messages ⇒ Object
General error messages.
-
#flash_global_storage ⇒ Object
General flash-storage using by Turbo Stream.
-
#flash_storage ⇒ Object
flash message storage.
-
#flash_templates ⇒ Object
Render templates partial (the <template> tags consumed by client-side JS).
-
#flash_turbo_stream ⇒ Object
Turbo Stream helper that appends flash storage to the global storage element.
-
#flash_unified_sources(options = {}) ⇒ Object
Wrapper helper that renders the common flash-unified pieces in a single call.
Instance Method Details
#flash_container ⇒ Object
flash message display container
22 23 24 |
# File 'app/helpers/flash_unified/view_helper.rb', line 22 def flash_container render partial: "flash_unified/container" end |
#flash_general_error_messages ⇒ Object
General error messages
27 28 29 |
# File 'app/helpers/flash_unified/view_helper.rb', line 27 def render partial: "flash_unified/general_error_messages" end |
#flash_global_storage ⇒ Object
General flash-storage using by Turbo Stream
4 5 6 |
# File 'app/helpers/flash_unified/view_helper.rb', line 4 def flash_global_storage render partial: "flash_unified/global_storage" end |
#flash_storage ⇒ Object
flash message storage
9 10 11 |
# File 'app/helpers/flash_unified/view_helper.rb', line 9 def flash_storage render partial: "flash_unified/storage" end |
#flash_templates ⇒ Object
Render templates partial (the <template> tags consumed by client-side JS). The generator copies ‘_templates.html.erb` by default; if it’s not available, fall back to an inline set of templates so the helper always returns usable markup.
17 18 19 |
# File 'app/helpers/flash_unified/view_helper.rb', line 17 def flash_templates render partial: "flash_unified/templates" end |
#flash_turbo_stream ⇒ Object
Turbo Stream helper that appends flash storage to the global storage element. This is a convenience helper for the common pattern of appending flash messages via Turbo Stream to the global flash-storage container.
Usage in views:
<%= flash_turbo_stream %>
Usage in controllers:
render turbo_stream: helpers.flash_turbo_stream
40 41 42 |
# File 'app/helpers/flash_unified/view_helper.rb', line 40 def flash_turbo_stream turbo_stream.append("flash-storage", partial: "flash_unified/storage") end |
#flash_unified_sources(options = {}) ⇒ Object
Wrapper helper that renders the common flash-unified pieces in a single call. This is a non-destructive convenience helper which calls the existing partial-rendering helpers in a sensible default order. Pass a hash to disable parts, e.g. ‘flash_unified_sources(container: false)`.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/flash_unified/view_helper.rb', line 48 def flash_unified_sources( = {}) opts = { global_storage: true, templates: true, general_errors: true, storage: true, container: false }.merge(.transform_keys(&:to_sym)) parts = [] parts << flash_global_storage if opts[:global_storage] parts << flash_templates if opts[:templates] parts << if opts[:general_errors] parts << flash_storage if opts[:storage] parts << flash_container if opts[:container] safe_join(parts, "\n") end |