Class: Shimmer::RemoteNavigator
- Inherits:
-
Object
- Object
- Shimmer::RemoteNavigator
- Defined in:
- lib/shimmer/utils/remote_navigation.rb
Instance Method Summary collapse
- #append(id, with:, **locals) ⇒ Object
- #close_modal(id = nil) ⇒ Object
- #close_popover ⇒ Object
-
#initialize(controller) ⇒ RemoteNavigator
constructor
A new instance of RemoteNavigator.
- #insert_after(id, with:, **locals) ⇒ Object
- #insert_before(id, with:, **locals) ⇒ Object
- #navigate_to(path) ⇒ Object
- #open_modal(url, id: nil, size: nil, close: true) ⇒ Object
- #open_popover(url, selector:, placement: nil) ⇒ Object
- #prepend(id, with:, **locals) ⇒ Object
- #queued_updates ⇒ Object
- #remove(id) ⇒ Object
- #replace(id, with: id, **locals) ⇒ Object
- #run_javascript(script) ⇒ Object
- #update(id, with: id, **locals) ⇒ Object
- #updates? ⇒ Boolean
Constructor Details
#initialize(controller) ⇒ RemoteNavigator
Returns a new instance of RemoteNavigator.
68 69 70 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 68 def initialize(controller) @controller = controller end |
Instance Method Details
#append(id, with:, **locals) ⇒ Object
84 85 86 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 84 def append(id, with:, **locals) queued_updates.push turbo_stream.append(id, partial: with, locals: locals) end |
#close_modal(id = nil) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 116 def close_modal(id = nil) if id.present? run_javascript "ui.modal.close(#{{id: id}.to_json})" else run_javascript "ui.modal.close()" end end |
#close_popover ⇒ Object
128 129 130 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 128 def close_popover run_javascript "ui.popover.close()" end |
#insert_after(id, with:, **locals) ⇒ Object
108 109 110 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 108 def insert_after(id, with:, **locals) queued_updates.push turbo_stream.after(id, partial: with, locals: locals) end |
#insert_before(id, with:, **locals) ⇒ Object
104 105 106 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 104 def insert_before(id, with:, **locals) queued_updates.push turbo_stream.before(id, partial: with, locals: locals) end |
#navigate_to(path) ⇒ Object
132 133 134 135 136 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 132 def navigate_to(path) close_modal path = polymorphic_path(path) unless path.is_a?(String) run_javascript "Turbo.visit('#{path}')" end |
#open_modal(url, id: nil, size: nil, close: true) ⇒ Object
112 113 114 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 112 def open_modal(url, id: nil, size: nil, close: true) run_javascript "ui.modal.open(#{{url: url, id: id, size: size, close: close}.to_json})" end |
#open_popover(url, selector:, placement: nil) ⇒ Object
124 125 126 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 124 def open_popover(url, selector:, placement: nil) run_javascript "ui.popover.open(#{{url: url, selector: selector, placement: placement}.to_json})" end |
#prepend(id, with:, **locals) ⇒ Object
88 89 90 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 88 def prepend(id, with:, **locals) queued_updates.push turbo_stream.prepend(id, partial: with, locals: locals) end |
#queued_updates ⇒ Object
72 73 74 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 72 def queued_updates @queued_updates ||= [] end |
#remove(id) ⇒ Object
100 101 102 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 100 def remove(id) queued_updates.push turbo_stream.remove(id) end |
#replace(id, with: id, **locals) ⇒ Object
92 93 94 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 92 def replace(id, with: id, **locals) queued_updates.push turbo_stream.replace(id, partial: with, locals: locals) end |
#run_javascript(script) ⇒ Object
80 81 82 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 80 def run_javascript(script) queued_updates.push turbo_stream.append "shimmer", "<div class='hidden' data-controller='remote-navigation'>#{script}</div>" end |
#update(id, with: id, **locals) ⇒ Object
96 97 98 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 96 def update(id, with: id, **locals) queued_updates.push turbo_stream.update(id, partial: with, locals: locals) end |
#updates? ⇒ Boolean
76 77 78 |
# File 'lib/shimmer/utils/remote_navigation.rb', line 76 def updates? queued_updates.any? end |