Module: TurboPower::StreamHelper
- Includes:
- AttributeTransformations
- Included in:
- RenderHelper
- Defined in:
- lib/turbo_power/stream_helper.rb
Instance Method Summary collapse
-
#add_css_class(targets = nil, classes = "", **attributes) ⇒ Object
Attribute Actions.
- #clear_local_storage(**attributes) ⇒ Object
- #clear_session_storage(**attributes) ⇒ Object
-
#clear_storage(type = nil, **attributes) ⇒ Object
Storage Actions.
-
#console_log(message = nil, level = :log, **attributes) ⇒ Object
Debug Actions.
- #console_table(data = [], columns = [], **attributes) ⇒ Object
-
#custom_action(name, target: nil, content: nil, attributes: {}) ⇒ Object
Also see: => github.com/hotwired/turbo-rails/pull/374.
- #custom_action_all(name, targets: nil, content: nil, attributes: {}) ⇒ Object
-
#dispatch_event(targets = nil, name = nil, detail: {}, **attributes) ⇒ Object
Event Actions.
-
#graft(targets = nil, parent = nil, **attributes) ⇒ Object
DOM Actions.
-
#history_back(**attributes) ⇒ Object
Browser History Actions.
- #history_forward(**attributes) ⇒ Object
- #history_go(delta = 0, **attributes) ⇒ Object
- #inner_html(targets = nil, html = nil, **attributes, &block) ⇒ Object
- #insert_adjacent_html(targets = nil, html = nil, position: "beforeend", **attributes, &block) ⇒ Object
- #insert_adjacent_text(targets = nil, text = nil, position: "beforebegin", **attributes) ⇒ Object
- #morph(targets = nil, html = nil, **attributes, &block) ⇒ Object
-
#notification(title = nil, **attributes) ⇒ Object
Notification Actions.
- #outer_html(targets = nil, html = nil, **attributes, &block) ⇒ Object
- #push_state(url = nil, title = "", state = {}, **attributes) ⇒ Object
-
#redirect_to(url = nil, turbo_action = "advance", turbo_frame = nil, **attributes) ⇒ Object
Turbo Actions.
-
#reload(**attributes) ⇒ Object
Browser Actions.
- #remove_attribute(targets = nil, attribute = nil, **attributes) ⇒ Object
- #remove_css_class(targets = nil, classes = "", **attributes) ⇒ Object
- #remove_local_storage_item(key = nil, **attributes) ⇒ Object
- #remove_session_storage_item(key = nil, **attributes) ⇒ Object
- #remove_storage_item(key = nil, type = nil, **attributes) ⇒ Object
- #replace_css_class(targets = nil, from = "", to = "", **attributes) ⇒ Object
- #replace_state(url = nil, title = "", state = {}, **attributes) ⇒ Object
-
#reset_form(targets = nil, **attributes) ⇒ Object
Form Actions.
- #scroll_into_view(targets = nil, align_to_top = nil, **attributes) ⇒ Object
- #set_attribute(targets = nil, attribute = nil, value = nil, **attributes) ⇒ Object
- #set_cookie(cookie = nil, **attributes) ⇒ Object
- #set_cookie_item(key = nil, value = nil, **attributes) ⇒ Object
- #set_dataset_attribute(targets = nil, attribute = nil, value = nil, **attributes) ⇒ Object
- #set_focus(targets = nil, **attributes) ⇒ Object
- #set_local_storage_item(key = nil, value = nil, **attributes) ⇒ Object
- #set_meta(name = nil, content = nil, **attributes) ⇒ Object
- #set_property(targets = nil, name = nil, value = nil, **attributes) ⇒ Object
- #set_session_storage_item(key = nil, value = nil, **attributes) ⇒ Object
- #set_storage_item(key = nil, value = nil, type = nil, **attributes) ⇒ Object
- #set_style(targets = nil, name = nil, value = nil, **attributes) ⇒ Object
- #set_styles(targets = nil, styles = nil, **attributes) ⇒ Object
- #set_title(title = nil, **attributes) ⇒ Object
- #set_value(targets = nil, value = nil, **attributes) ⇒ Object
- #text_content(targets = nil, text = nil, **attributes) ⇒ Object
- #toggle_attribute(targets = nil, attribute = "", force = "false", **attributes) ⇒ Object
- #toggle_css_class(targets = nil, classes = "", **attributes) ⇒ Object
- #turbo_clear_cache(**attributes) ⇒ Object
-
#turbo_frame_reload(target = nil, **attributes) ⇒ Object
Turbo Frame Actions.
- #turbo_frame_set_src(target = nil, src = nil, **attributes) ⇒ Object
- #turbo_progress_bar_hide(**attributes) ⇒ Object
- #turbo_progress_bar_set_value(value = nil, **attributes) ⇒ Object
-
#turbo_progress_bar_show(**attributes) ⇒ Object
Turbo Progress Bar Actions.
Instance Method Details
#add_css_class(targets = nil, classes = "", **attributes) ⇒ Object
Attribute Actions
64 65 66 67 68 69 |
# File 'lib/turbo_power/stream_helper.rb', line 64 def add_css_class(targets = nil, classes = "", **attributes) classes = attributes[:classes] || classes classes = classes.join(" ") if classes.is_a?(Array) custom_action_all :add_css_class, targets: targets, attributes: attributes.merge(classes: classes) end |
#clear_local_storage(**attributes) ⇒ Object
148 149 150 |
# File 'lib/turbo_power/stream_helper.rb', line 148 def clear_local_storage(**attributes) clear_storage("local", **attributes) end |
#clear_session_storage(**attributes) ⇒ Object
152 153 154 |
# File 'lib/turbo_power/stream_helper.rb', line 152 def clear_session_storage(**attributes) clear_storage("session", **attributes) end |
#clear_storage(type = nil, **attributes) ⇒ Object
Storage Actions
144 145 146 |
# File 'lib/turbo_power/stream_helper.rb', line 144 def clear_storage(type = nil, **attributes) custom_action :clear_storage, attributes: attributes.reverse_merge(type: type) end |
#console_log(message = nil, level = :log, **attributes) ⇒ Object
Debug Actions
230 231 232 |
# File 'lib/turbo_power/stream_helper.rb', line 230 def console_log( = nil, level = :log, **attributes) custom_action :console_log, attributes: attributes.reverse_merge(message: , level: level) end |
#console_table(data = [], columns = [], **attributes) ⇒ Object
234 235 236 |
# File 'lib/turbo_power/stream_helper.rb', line 234 def console_table(data = [], columns = [], **attributes) custom_action :console_table, attributes: attributes.reverse_merge(data: data, columns: columns) end |
#custom_action(name, target: nil, content: nil, attributes: {}) ⇒ Object
Also see:
> github.com/hotwired/turbo-rails/pull/374
12 13 14 |
# File 'lib/turbo_power/stream_helper.rb', line 12 def custom_action(name, target: nil, content: nil, attributes: {}) turbo_stream_action_tag name, target: target, template: content, **transform_attributes(attributes) end |
#custom_action_all(name, targets: nil, content: nil, attributes: {}) ⇒ Object
16 17 18 |
# File 'lib/turbo_power/stream_helper.rb', line 16 def custom_action_all(name, targets: nil, content: nil, attributes: {}) turbo_stream_action_tag name, targets: targets, template: content, **transform_attributes(attributes) end |
#dispatch_event(targets = nil, name = nil, detail: {}, **attributes) ⇒ Object
Event Actions
132 133 134 |
# File 'lib/turbo_power/stream_helper.rb', line 132 def dispatch_event(targets = nil, name = nil, detail: {}, **attributes) custom_action_all :dispatch_event, targets: targets, content: detail.to_json, attributes: attributes.reverse_merge(name: name) end |
#graft(targets = nil, parent = nil, **attributes) ⇒ Object
DOM Actions
22 23 24 |
# File 'lib/turbo_power/stream_helper.rb', line 22 def graft(targets = nil, parent = nil, **attributes) custom_action_all :graft, targets: targets, attributes: attributes.reverse_merge(parent: parent) end |
#history_back(**attributes) ⇒ Object
Browser History Actions
208 209 210 |
# File 'lib/turbo_power/stream_helper.rb', line 208 def history_back(**attributes) custom_action :history_back, attributes: attributes end |
#history_forward(**attributes) ⇒ Object
212 213 214 |
# File 'lib/turbo_power/stream_helper.rb', line 212 def history_forward(**attributes) custom_action :history_forward, attributes: attributes end |
#history_go(delta = 0, **attributes) ⇒ Object
216 217 218 |
# File 'lib/turbo_power/stream_helper.rb', line 216 def history_go(delta = 0, **attributes) custom_action :history_go, attributes: attributes.reverse_merge(delta: delta) end |
#inner_html(targets = nil, html = nil, **attributes, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/turbo_power/stream_helper.rb', line 26 def inner_html(targets = nil, html = nil, **attributes, &block) html = attributes[:html] || html custom_action_all :inner_html, targets: targets, content: html, attributes: attributes.except(:html), &block end |
#insert_adjacent_html(targets = nil, html = nil, position: "beforeend", **attributes, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/turbo_power/stream_helper.rb', line 32 def insert_adjacent_html(targets = nil, html = nil, position: "beforeend", **attributes, &block) html = attributes[:html] || html custom_action_all :insert_adjacent_html, targets: targets, content: html, attributes: attributes.merge(position: position).except(:html), &block end |
#insert_adjacent_text(targets = nil, text = nil, position: "beforebegin", **attributes) ⇒ Object
38 39 40 |
# File 'lib/turbo_power/stream_helper.rb', line 38 def insert_adjacent_text(targets = nil, text = nil, position: "beforebegin", **attributes) custom_action_all :insert_adjacent_text, targets: targets, attributes: attributes.reverse_merge(text: text, position: position) end |
#morph(targets = nil, html = nil, **attributes, &block) ⇒ Object
42 43 44 45 46 |
# File 'lib/turbo_power/stream_helper.rb', line 42 def morph(targets = nil, html = nil, **attributes, &block) html = attributes[:html] || html custom_action_all :morph, targets: targets, content: html, attributes: attributes.except(:html), &block end |
#notification(title = nil, **attributes) ⇒ Object
Notification Actions
240 241 242 |
# File 'lib/turbo_power/stream_helper.rb', line 240 def notification(title = nil, **attributes) custom_action :notification, attributes: attributes.reverse_merge(title: title) end |
#outer_html(targets = nil, html = nil, **attributes, &block) ⇒ Object
48 49 50 51 52 |
# File 'lib/turbo_power/stream_helper.rb', line 48 def outer_html(targets = nil, html = nil, **attributes, &block) html = attributes[:html] || html custom_action_all :outer_html, targets: targets, content: html, attributes: attributes.except(:html), &block end |
#push_state(url = nil, title = "", state = {}, **attributes) ⇒ Object
220 221 222 |
# File 'lib/turbo_power/stream_helper.rb', line 220 def push_state(url = nil, title = "", state = {}, **attributes) custom_action :push_state, attributes: attributes.reverse_merge(url: url, title: title, state: state) end |
#redirect_to(url = nil, turbo_action = "advance", turbo_frame = nil, **attributes) ⇒ Object
Turbo Actions
246 247 248 |
# File 'lib/turbo_power/stream_helper.rb', line 246 def redirect_to(url = nil, turbo_action = "advance", turbo_frame = nil, **attributes) custom_action :redirect_to, attributes: attributes.reverse_merge(url: url, turbo_action: turbo_action, turbo_frame: turbo_frame).compact end |
#reload(**attributes) ⇒ Object
Browser Actions
182 183 184 |
# File 'lib/turbo_power/stream_helper.rb', line 182 def reload(**attributes) custom_action :reload, attributes: attributes end |
#remove_attribute(targets = nil, attribute = nil, **attributes) ⇒ Object
71 72 73 |
# File 'lib/turbo_power/stream_helper.rb', line 71 def remove_attribute(targets = nil, attribute = nil, **attributes) custom_action_all :remove_attribute, targets: targets, attributes: attributes.reverse_merge(attribute: attribute) end |
#remove_css_class(targets = nil, classes = "", **attributes) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/turbo_power/stream_helper.rb', line 75 def remove_css_class(targets = nil, classes = "", **attributes) classes = attributes[:classes] || classes classes = classes.join(" ") if classes.is_a?(Array) custom_action_all :remove_css_class, targets: targets, attributes: attributes.merge(classes: classes) end |
#remove_local_storage_item(key = nil, **attributes) ⇒ Object
160 161 162 |
# File 'lib/turbo_power/stream_helper.rb', line 160 def remove_local_storage_item(key = nil, **attributes) remove_storage_item(key, "local", **attributes) end |
#remove_session_storage_item(key = nil, **attributes) ⇒ Object
164 165 166 |
# File 'lib/turbo_power/stream_helper.rb', line 164 def remove_session_storage_item(key = nil, **attributes) remove_storage_item(key, "session", **attributes) end |
#remove_storage_item(key = nil, type = nil, **attributes) ⇒ Object
156 157 158 |
# File 'lib/turbo_power/stream_helper.rb', line 156 def remove_storage_item(key = nil, type = nil, **attributes) custom_action :remove_storage_item, attributes: attributes.reverse_merge(key: key, type: type) end |
#replace_css_class(targets = nil, from = "", to = "", **attributes) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/turbo_power/stream_helper.rb', line 123 def replace_css_class(targets = nil, from = "", to = "", **attributes) from = attributes[:from] || from to = attributes[:to] || to custom_action_all :replace_css_class, targets: targets, attributes: attributes.merge(from: from, to: to) end |
#replace_state(url = nil, title = "", state = {}, **attributes) ⇒ Object
224 225 226 |
# File 'lib/turbo_power/stream_helper.rb', line 224 def replace_state(url = nil, title = "", state = {}, **attributes) custom_action :replace_state, attributes: attributes.reverse_merge(url: url, title: title, state: state) end |
#reset_form(targets = nil, **attributes) ⇒ Object
Form Actions
138 139 140 |
# File 'lib/turbo_power/stream_helper.rb', line 138 def reset_form(targets = nil, **attributes) custom_action_all :reset_form, targets: targets, attributes: attributes end |
#scroll_into_view(targets = nil, align_to_top = nil, **attributes) ⇒ Object
186 187 188 |
# File 'lib/turbo_power/stream_helper.rb', line 186 def scroll_into_view(targets = nil, align_to_top = nil, **attributes) custom_action_all :scroll_into_view, targets: targets, attributes: attributes.reverse_merge(align_to_top: align_to_top).compact end |
#set_attribute(targets = nil, attribute = nil, value = nil, **attributes) ⇒ Object
82 83 84 |
# File 'lib/turbo_power/stream_helper.rb', line 82 def set_attribute(targets = nil, attribute = nil, value = nil, **attributes) custom_action_all :set_attribute, targets: targets, attributes: attributes.reverse_merge(attribute: attribute, value: value) end |
#set_cookie(cookie = nil, **attributes) ⇒ Object
190 191 192 |
# File 'lib/turbo_power/stream_helper.rb', line 190 def ( = nil, **attributes) custom_action :set_cookie, attributes: attributes.reverse_merge(cookie: ) end |
#set_cookie_item(key = nil, value = nil, **attributes) ⇒ Object
194 195 196 |
# File 'lib/turbo_power/stream_helper.rb', line 194 def (key = nil, value = nil, **attributes) custom_action :set_cookie_item, attributes: attributes.reverse_merge(key: key, value: value) end |
#set_dataset_attribute(targets = nil, attribute = nil, value = nil, **attributes) ⇒ Object
86 87 88 |
# File 'lib/turbo_power/stream_helper.rb', line 86 def set_dataset_attribute(targets = nil, attribute = nil, value = nil, **attributes) custom_action_all :set_dataset_attribute, targets: targets, attributes: attributes.reverse_merge(attribute: attribute, value: value) end |
#set_focus(targets = nil, **attributes) ⇒ Object
198 199 200 |
# File 'lib/turbo_power/stream_helper.rb', line 198 def set_focus(targets = nil, **attributes) custom_action_all :set_focus, targets: targets, attributes: attributes end |
#set_local_storage_item(key = nil, value = nil, **attributes) ⇒ Object
172 173 174 |
# File 'lib/turbo_power/stream_helper.rb', line 172 def set_local_storage_item(key = nil, value = nil, **attributes) set_storage_item(key, value, "local", **attributes) end |
#set_meta(name = nil, content = nil, **attributes) ⇒ Object
58 59 60 |
# File 'lib/turbo_power/stream_helper.rb', line 58 def (name = nil, content = nil, **attributes) custom_action :set_meta, attributes: attributes.reverse_merge(name: name, content: content) end |
#set_property(targets = nil, name = nil, value = nil, **attributes) ⇒ Object
90 91 92 |
# File 'lib/turbo_power/stream_helper.rb', line 90 def set_property(targets = nil, name = nil, value = nil, **attributes) custom_action_all :set_property, targets: targets, attributes: attributes.reverse_merge(name: name, value: value) end |
#set_session_storage_item(key = nil, value = nil, **attributes) ⇒ Object
176 177 178 |
# File 'lib/turbo_power/stream_helper.rb', line 176 def set_session_storage_item(key = nil, value = nil, **attributes) set_storage_item(key, value, "session", **attributes) end |
#set_storage_item(key = nil, value = nil, type = nil, **attributes) ⇒ Object
168 169 170 |
# File 'lib/turbo_power/stream_helper.rb', line 168 def set_storage_item(key = nil, value = nil, type = nil, **attributes) custom_action :set_storage_item, attributes: attributes.reverse_merge(key: key, type: type, value: value) end |
#set_style(targets = nil, name = nil, value = nil, **attributes) ⇒ Object
94 95 96 |
# File 'lib/turbo_power/stream_helper.rb', line 94 def set_style(targets = nil, name = nil, value = nil, **attributes) custom_action_all :set_style, targets: targets, attributes: attributes.reverse_merge(name: name, value: value) end |
#set_styles(targets = nil, styles = nil, **attributes) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/turbo_power/stream_helper.rb', line 98 def set_styles(targets = nil, styles = nil, **attributes) styles = attributes[:styles] || styles styles = styles.map { |k, v| "#{k}: #{v}" }.join("; ") if styles.is_a?(Hash) custom_action_all :set_styles, targets: targets, attributes: attributes.merge(styles: styles) end |
#set_title(title = nil, **attributes) ⇒ Object
202 203 204 |
# File 'lib/turbo_power/stream_helper.rb', line 202 def set_title(title = nil, **attributes) custom_action :set_title, attributes: attributes.reverse_merge(title: title) end |
#set_value(targets = nil, value = nil, **attributes) ⇒ Object
105 106 107 |
# File 'lib/turbo_power/stream_helper.rb', line 105 def set_value(targets = nil, value = nil, **attributes) custom_action_all :set_value, targets: targets, attributes: attributes.reverse_merge(value: value) end |
#text_content(targets = nil, text = nil, **attributes) ⇒ Object
54 55 56 |
# File 'lib/turbo_power/stream_helper.rb', line 54 def text_content(targets = nil, text = nil, **attributes) custom_action_all :text_content, targets: targets, attributes: attributes.reverse_merge(text: text) end |
#toggle_attribute(targets = nil, attribute = "", force = "false", **attributes) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/turbo_power/stream_helper.rb', line 116 def toggle_attribute(targets = nil, attribute = "", force = "false", **attributes) attribute = attributes[:attribute] || attribute force = attributes[:force] || force custom_action_all :toggle_attribute, targets: targets, attributes: attributes.merge(attribute: attribute, force: force) end |
#toggle_css_class(targets = nil, classes = "", **attributes) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/turbo_power/stream_helper.rb', line 109 def toggle_css_class(targets = nil, classes = "", **attributes) classes = attributes[:classes] || classes classes = classes.join(" ") if classes.is_a?(Array) custom_action_all :toggle_css_class, targets: targets, attributes: attributes.merge(classes: classes) end |
#turbo_clear_cache(**attributes) ⇒ Object
250 251 252 |
# File 'lib/turbo_power/stream_helper.rb', line 250 def turbo_clear_cache(**attributes) custom_action :turbo_clear_cache, attributes: attributes end |
#turbo_frame_reload(target = nil, **attributes) ⇒ Object
Turbo Frame Actions
270 271 272 |
# File 'lib/turbo_power/stream_helper.rb', line 270 def turbo_frame_reload(target = nil, **attributes) custom_action :turbo_frame_reload, target: target, attributes: attributes end |
#turbo_frame_set_src(target = nil, src = nil, **attributes) ⇒ Object
274 275 276 |
# File 'lib/turbo_power/stream_helper.rb', line 274 def turbo_frame_set_src(target = nil, src = nil, **attributes) custom_action :turbo_frame_set_src, target: target, attributes: attributes.reverse_merge(src: src) end |
#turbo_progress_bar_hide(**attributes) ⇒ Object
260 261 262 |
# File 'lib/turbo_power/stream_helper.rb', line 260 def (**attributes) custom_action :turbo_progress_bar_hide, attributes: attributes end |
#turbo_progress_bar_set_value(value = nil, **attributes) ⇒ Object
264 265 266 |
# File 'lib/turbo_power/stream_helper.rb', line 264 def (value = nil, **attributes) custom_action :turbo_progress_bar_set_value, attributes: attributes.reverse_merge(value: value) end |
#turbo_progress_bar_show(**attributes) ⇒ Object
Turbo Progress Bar Actions
256 257 258 |
# File 'lib/turbo_power/stream_helper.rb', line 256 def (**attributes) custom_action :turbo_progress_bar_show, attributes: attributes end |