Module: Overlastic::OverlaysHelper

Defined in:
app/helpers/overlastic/overlays_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_overlay_nameObject



6
7
8
9
10
# File 'app/helpers/overlastic/overlays_helper.rb', line 6

def current_overlay_name
  return unless request.headers["Turbo-Frame"].to_s.starts_with?("overlay")

  request.headers["Turbo-Frame"].to_sym
end

#next_overlay_nameObject



12
13
14
15
16
# File 'app/helpers/overlastic/overlays_helper.rb', line 12

def next_overlay_name
  current_number = current_overlay_name.to_s.scan(/\d+/)&.first.to_i

  "overlay#{current_number + 1}".to_sym
end

#overlastic_tagObject



2
3
4
# File 'app/helpers/overlastic/overlays_helper.rb', line 2

def overlastic_tag
  turbo_frame_tag :overlay1, target: :_top
end

#render_overlay(locals = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/helpers/overlastic/overlays_helper.rb', line 18

def render_overlay(locals = {}, &block)
  string = capture(&block)
  type = request.headers["Overlay-Type"] || Overlastic.configuration.default_overlay
  args_header = request.headers["Overlay-Args"]
  overlay_args = JSON.parse(request.headers["Overlay-Args"]) if args_header.present?
  locals.merge! overlay_args.to_h.symbolize_keys

  render(Overlastic.configuration.public_send(:"#{type}_overlay_view_path"), locals) { string }
end