Module: TurboPower::StreamHelper

Includes:
AttributeTransformations
Included in:
RenderHelper
Defined in:
lib/turbo_power/stream_helper.rb

Instance Method Summary collapse

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



141
142
143
# File 'lib/turbo_power/stream_helper.rb', line 141

def clear_local_storage(**attributes)
  clear_storage("local", **attributes)
end

#clear_session_storage(**attributes) ⇒ Object



145
146
147
# File 'lib/turbo_power/stream_helper.rb', line 145

def clear_session_storage(**attributes)
  clear_storage("session", **attributes)
end

#clear_storage(type = nil, **attributes) ⇒ Object

Storage Actions



137
138
139
# File 'lib/turbo_power/stream_helper.rb', line 137

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



223
224
225
# File 'lib/turbo_power/stream_helper.rb', line 223

def console_log(message = nil, level = :log, **attributes)
  custom_action :console_log, attributes: attributes.reverse_merge(message: message, level: level)
end

#console_table(data = [], columns = [], **attributes) ⇒ Object



227
228
229
# File 'lib/turbo_power/stream_helper.rb', line 227

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



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



125
126
127
# File 'lib/turbo_power/stream_helper.rb', line 125

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



201
202
203
# File 'lib/turbo_power/stream_helper.rb', line 201

def history_back(**attributes)
  custom_action :history_back, attributes: attributes
end

#history_forward(**attributes) ⇒ Object



205
206
207
# File 'lib/turbo_power/stream_helper.rb', line 205

def history_forward(**attributes)
  custom_action :history_forward, attributes: attributes
end

#history_go(delta = 0, **attributes) ⇒ Object



209
210
211
# File 'lib/turbo_power/stream_helper.rb', line 209

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



233
234
235
# File 'lib/turbo_power/stream_helper.rb', line 233

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



213
214
215
# File 'lib/turbo_power/stream_helper.rb', line 213

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



239
240
241
# File 'lib/turbo_power/stream_helper.rb', line 239

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



175
176
177
# File 'lib/turbo_power/stream_helper.rb', line 175

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



153
154
155
# File 'lib/turbo_power/stream_helper.rb', line 153

def remove_local_storage_item(key = nil, **attributes)
  remove_storage_item(key, "local", **attributes)
end

#remove_session_storage_item(key = nil, **attributes) ⇒ Object



157
158
159
# File 'lib/turbo_power/stream_helper.rb', line 157

def remove_session_storage_item(key = nil, **attributes)
  remove_storage_item(key, "session", **attributes)
end

#remove_storage_item(key = nil, type = nil, **attributes) ⇒ Object



149
150
151
# File 'lib/turbo_power/stream_helper.rb', line 149

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



116
117
118
119
120
121
# File 'lib/turbo_power/stream_helper.rb', line 116

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



217
218
219
# File 'lib/turbo_power/stream_helper.rb', line 217

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



131
132
133
# File 'lib/turbo_power/stream_helper.rb', line 131

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



179
180
181
# File 'lib/turbo_power/stream_helper.rb', line 179

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


183
184
185
# File 'lib/turbo_power/stream_helper.rb', line 183

def set_cookie(cookie = nil, **attributes)
  custom_action :set_cookie, attributes: attributes.reverse_merge(cookie: cookie)
end


187
188
189
# File 'lib/turbo_power/stream_helper.rb', line 187

def set_cookie_item(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



191
192
193
# File 'lib/turbo_power/stream_helper.rb', line 191

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



165
166
167
# File 'lib/turbo_power/stream_helper.rb', line 165

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 set_meta(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



169
170
171
# File 'lib/turbo_power/stream_helper.rb', line 169

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



161
162
163
# File 'lib/turbo_power/stream_helper.rb', line 161

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



195
196
197
# File 'lib/turbo_power/stream_helper.rb', line 195

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_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



243
244
245
# File 'lib/turbo_power/stream_helper.rb', line 243

def turbo_clear_cache(**attributes)
  custom_action :turbo_clear_cache, attributes: attributes
end

#turbo_frame_reload(target = nil, **attributes) ⇒ Object

Turbo Frame Actions



263
264
265
# File 'lib/turbo_power/stream_helper.rb', line 263

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



267
268
269
# File 'lib/turbo_power/stream_helper.rb', line 267

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



253
254
255
# File 'lib/turbo_power/stream_helper.rb', line 253

def turbo_progress_bar_hide(**attributes)
  custom_action :turbo_progress_bar_hide, attributes: attributes
end

#turbo_progress_bar_set_value(value = nil, **attributes) ⇒ Object



257
258
259
# File 'lib/turbo_power/stream_helper.rb', line 257

def turbo_progress_bar_set_value(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



249
250
251
# File 'lib/turbo_power/stream_helper.rb', line 249

def turbo_progress_bar_show(**attributes)
  custom_action :turbo_progress_bar_show, attributes: attributes
end