turbo_power 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -0
- data/app/jobs/turbo_power/streams/action_broadcast_job.rb +9 -0
- data/lib/turbo_power/broadcastable.rb +30 -0
- data/lib/turbo_power/broadcasts.rb +32 -0
- data/lib/turbo_power/engine.rb +9 -1
- data/lib/turbo_power/stream_helper.rb +14 -0
- data/lib/turbo_power/version.rb +1 -1
- data/lib/turbo_power.rb +2 -0
- data/turbo_power.gemspec +1 -1
- metadata +9 -7
- data/CHANGELOG.md +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c978af0e8802736440fb1efdaefb241555a5f0c459aef82b19d5b025c74cc22f
|
4
|
+
data.tar.gz: 3aae4c0251a81ce63c8b8d3309439d6bed7cacd9481951ffac2c448eaaac0d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69834c88a1c011c11056a602f0ef2cb58f7de402dbd9ddf98b9f5aea2fc042f2594552e79e909eb5505f4eeceaee9b5a0232af861e6600274a92673ee3664048
|
7
|
+
data.tar.gz: d15b8707abaa450e0a791a860d6457462be7325ed718887ad99be53d640f5ef88c21a3cc86198029aca6ced23504eb975149d86ccd2f9f641cf9ae40e212fd29
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -108,6 +108,8 @@ import 'controllers'
|
|
108
108
|
* `turbo_stream.set_style(targets, name, value, **attributes)`
|
109
109
|
* `turbo_stream.set_styles(targets, styles, **attributes)`
|
110
110
|
* `turbo_stream.set_value(targets, value, **attributes)`
|
111
|
+
* `turbo_stream.toggle_css_class(targets, classes, **attributes)`
|
112
|
+
* `turbo_stream.replace_css_class(targets, from, to, **attributes)`
|
111
113
|
|
112
114
|
|
113
115
|
### Event Actions
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# The job that powers all the <tt>custom_broadcast_$action_later</tt> broadcasts available in <tt>TurboPower::Broadcasts</tt>.
|
2
|
+
|
3
|
+
class TurboPower::Streams::ActionBroadcastJob < ActiveJob::Base
|
4
|
+
discard_on ActiveJob::DeserializationError
|
5
|
+
|
6
|
+
def perform(stream, action:, **attributes)
|
7
|
+
Turbo::StreamsChannel.custom_broadcast_action_to stream, action: action, **attributes
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboPower
|
4
|
+
module Broadcastable
|
5
|
+
ACTIONS = TurboPower::StreamHelper.instance_methods.sort
|
6
|
+
|
7
|
+
ACTIONS.each do |action|
|
8
|
+
action_name = "broadcast_#{action}"
|
9
|
+
action_name_to = "broadcast_#{action}_to"
|
10
|
+
action_name_later = "broadcast_#{action}_later"
|
11
|
+
action_name_later_to = "broadcast_#{action}_later_to"
|
12
|
+
|
13
|
+
define_method(action_name) do |**attributes|
|
14
|
+
Turbo::StreamsChannel.send(action_name_to, self, action: action, **attributes)
|
15
|
+
end
|
16
|
+
|
17
|
+
define_method(action_name_to) do |*streamables, **attributes|
|
18
|
+
Turbo::StreamsChannel.send(action_name_to, *streamables, action: action, **attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method(action_name_later) do |**attributes|
|
22
|
+
Turbo::StreamsChannel.send(action_name_later_to, self, action: action, **attributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
define_method(action_name_later_to) do |*streamables, **attributes|
|
26
|
+
Turbo::StreamsChannel.send(action_name_later_to, *streamables, action: action, **attributes)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboPower
|
4
|
+
module Broadcasts
|
5
|
+
ACTIONS = TurboPower::StreamHelper.instance_methods.sort
|
6
|
+
|
7
|
+
ACTIONS.each do |action|
|
8
|
+
define_method("broadcast_#{action}_to") do |*streamables, **attributes|
|
9
|
+
custom_broadcast_action_to(*streamables, action: action, **attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
define_method("broadcast_#{action}_later_to") do |*streamables, **attributes|
|
13
|
+
custom_broadcast_action_later_to(*streamables, action: action, **attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def custom_broadcast_action_to(*streamables, action:, **attributes)
|
18
|
+
broadcast_stream_to(
|
19
|
+
*streamables,
|
20
|
+
content: turbo_stream_action_tag(action, **attributes)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def custom_broadcast_action_later_to(*streamables, action:, **attributes)
|
25
|
+
TurboPower::Streams::ActionBroadcastJob.perform_later(
|
26
|
+
stream_name_from(streamables),
|
27
|
+
action: action,
|
28
|
+
**attributes
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/turbo_power/engine.rb
CHANGED
@@ -4,8 +4,16 @@ require "rails/engine"
|
|
4
4
|
|
5
5
|
module TurboPower
|
6
6
|
class Engine < Rails::Engine
|
7
|
-
initializer "turbo_power.
|
7
|
+
initializer "turbo_power.stream_helpers", after: :initialize do
|
8
8
|
Turbo::Streams::TagBuilder.include(TurboPower::StreamHelper)
|
9
9
|
end
|
10
|
+
|
11
|
+
initializer "turbo_power.broadcasts", after: :initialize do
|
12
|
+
Turbo::Streams::Broadcasts.include(TurboPower::Broadcasts)
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer "turbo_power.broadcastable", after: :initialize do
|
16
|
+
Turbo::Broadcastable.include(TurboPower::Broadcastable)
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
@@ -106,6 +106,20 @@ module TurboPower
|
|
106
106
|
custom_action_all :set_value, targets: targets, attributes: attributes.reverse_merge(value: value)
|
107
107
|
end
|
108
108
|
|
109
|
+
def toggle_css_class(targets = nil, classes = "", **attributes)
|
110
|
+
classes = attributes[:classes] || classes
|
111
|
+
classes = classes.join(" ") if classes.is_a?(Array)
|
112
|
+
|
113
|
+
custom_action_all :toggle_css_class, targets: targets, attributes: attributes.merge(classes: classes)
|
114
|
+
end
|
115
|
+
|
116
|
+
def replace_css_class(targets = nil, from = "", to = "", **attributes)
|
117
|
+
from = attributes[:from] || from
|
118
|
+
to = attributes[:to] || to
|
119
|
+
|
120
|
+
custom_action_all :replace_css_class, targets: targets, attributes: attributes.merge(from: from, to: to)
|
121
|
+
end
|
122
|
+
|
109
123
|
# Event Actions
|
110
124
|
|
111
125
|
def dispatch_event(targets = nil, name = nil, detail: {}, **attributes)
|
data/lib/turbo_power/version.rb
CHANGED
data/lib/turbo_power.rb
CHANGED
@@ -6,6 +6,8 @@ require_relative "turbo_power/version"
|
|
6
6
|
require_relative "turbo_power/engine"
|
7
7
|
require_relative "turbo_power/attribute_transformations"
|
8
8
|
require_relative "turbo_power/stream_helper"
|
9
|
+
require_relative "turbo_power/broadcasts"
|
10
|
+
require_relative "turbo_power/broadcastable"
|
9
11
|
|
10
12
|
module TurboPower
|
11
13
|
end
|
data/turbo_power.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo_power
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Roth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: turbo-rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.3.0
|
27
27
|
description: Power-pack for Turbo Streams
|
28
28
|
email:
|
29
29
|
- marco.roth@hey.com
|
@@ -31,17 +31,19 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- CHANGELOG.md
|
35
34
|
- CODE_OF_CONDUCT.md
|
36
35
|
- Gemfile
|
37
36
|
- Gemfile.lock
|
38
37
|
- LICENSE.txt
|
39
38
|
- README.md
|
40
39
|
- Rakefile
|
40
|
+
- app/jobs/turbo_power/streams/action_broadcast_job.rb
|
41
41
|
- bin/console
|
42
42
|
- bin/setup
|
43
43
|
- lib/turbo_power.rb
|
44
44
|
- lib/turbo_power/attribute_transformations.rb
|
45
|
+
- lib/turbo_power/broadcastable.rb
|
46
|
+
- lib/turbo_power/broadcasts.rb
|
45
47
|
- lib/turbo_power/engine.rb
|
46
48
|
- lib/turbo_power/stream_helper.rb
|
47
49
|
- lib/turbo_power/version.rb
|