turbo_reflex 0.0.23 → 0.0.26
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 +14 -14
- data/README.md +2 -1
- data/lib/turbo_reflex/attribute_set.rb +39 -0
- data/lib/turbo_reflex/base.rb +6 -14
- data/lib/turbo_reflex/engine.rb +15 -6
- data/lib/turbo_reflex/runner.rb +1 -0
- data/lib/turbo_reflex/state.rb +2 -2
- data/lib/turbo_reflex/state_manager.rb +2 -8
- data/lib/turbo_reflex/version.rb +1 -1
- data/package.json +1 -1
- data/tags +4681 -4403
- data/yarn.lock +147 -147
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54eb80fcd5f3e12b66c58770328a188c35da892dff8f5bf5997bbd2e8933d577
|
4
|
+
data.tar.gz: b2b58f76eb46a235913b47833758e6f6f625eec10207f3f4a766be1e3ed42329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e684166fcb0c77a18d18948d82cd51c092a0bff82bece9e5d359d0d3c156fc7ac8dfd4bae3354ea06b628ae1f8664a8bd309ff44f265408dbe668ecfa454ec0
|
7
|
+
data.tar.gz: f910af2bbe2db405159c9a09a74e3818b79ac6ba8494274bbf73bdc69613b6da50f4eb4460563f8a09cb1aaa8524f4090fe775d1ec831c31a896d6d41ad14373
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
turbo_reflex (0.0.
|
4
|
+
turbo_reflex (0.0.26)
|
5
5
|
rails (>= 6.1)
|
6
6
|
turbo-rails (>= 1.1)
|
7
7
|
turbo_ready (>= 0.1)
|
@@ -94,11 +94,11 @@ GEM
|
|
94
94
|
coderay (1.1.3)
|
95
95
|
concurrent-ruby (1.1.10)
|
96
96
|
crass (1.0.6)
|
97
|
-
cuprite (0.14.
|
97
|
+
cuprite (0.14.3)
|
98
98
|
capybara (~> 3.0)
|
99
|
-
ferrum (~> 0.
|
99
|
+
ferrum (~> 0.13.0)
|
100
100
|
erubi (1.11.0)
|
101
|
-
ferrum (0.
|
101
|
+
ferrum (0.13)
|
102
102
|
addressable (~> 2.5)
|
103
103
|
concurrent-ruby (~> 1.1)
|
104
104
|
webrick (~> 1.7)
|
@@ -190,22 +190,22 @@ GEM
|
|
190
190
|
zeitwerk (~> 2.5)
|
191
191
|
rainbow (3.1.1)
|
192
192
|
rake (13.0.6)
|
193
|
-
regexp_parser (2.6.
|
193
|
+
regexp_parser (2.6.1)
|
194
194
|
rexml (3.2.5)
|
195
195
|
rouge (4.0.0)
|
196
|
-
rubocop (1.
|
196
|
+
rubocop (1.39.0)
|
197
197
|
json (~> 2.3)
|
198
198
|
parallel (~> 1.10)
|
199
199
|
parser (>= 3.1.2.1)
|
200
200
|
rainbow (>= 2.2.2, < 4.0)
|
201
201
|
regexp_parser (>= 1.8, < 3.0)
|
202
202
|
rexml (>= 3.2.5, < 4.0)
|
203
|
-
rubocop-ast (>= 1.
|
203
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
204
204
|
ruby-progressbar (~> 1.7)
|
205
205
|
unicode-display_width (>= 1.4.0, < 3.0)
|
206
206
|
rubocop-ast (1.23.0)
|
207
207
|
parser (>= 3.1.1.0)
|
208
|
-
rubocop-performance (1.
|
208
|
+
rubocop-performance (1.15.1)
|
209
209
|
rubocop (>= 1.7.0, < 2.0)
|
210
210
|
rubocop-ast (>= 0.4.0)
|
211
211
|
ruby-progressbar (1.11.0)
|
@@ -222,15 +222,15 @@ GEM
|
|
222
222
|
actionpack (>= 5.2)
|
223
223
|
activesupport (>= 5.2)
|
224
224
|
sprockets (>= 3.0.0)
|
225
|
-
sqlite3 (1.5.
|
226
|
-
standard (1.
|
227
|
-
rubocop (= 1.
|
228
|
-
rubocop-performance (= 1.
|
225
|
+
sqlite3 (1.5.4-arm64-darwin)
|
226
|
+
standard (1.18.1)
|
227
|
+
rubocop (= 1.39.0)
|
228
|
+
rubocop-performance (= 1.15.1)
|
229
229
|
standardrb (1.0.1)
|
230
230
|
standard
|
231
|
-
tailwindcss-rails (2.0.
|
231
|
+
tailwindcss-rails (2.0.21-aarch64-linux)
|
232
232
|
railties (>= 6.0.0)
|
233
|
-
tailwindcss-rails (2.0.
|
233
|
+
tailwindcss-rails (2.0.21-arm64-darwin)
|
234
234
|
railties (>= 6.0.0)
|
235
235
|
thor (1.2.1)
|
236
236
|
timeout (0.3.0)
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
</h1>
|
9
9
|
<p align="center">
|
10
10
|
<a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/">
|
11
|
-
<img alt="Lines of Code" src="https://img.shields.io/badge/loc-
|
11
|
+
<img alt="Lines of Code" src="https://img.shields.io/badge/loc-1232-47d299.svg" />
|
12
12
|
</a>
|
13
13
|
<a href="https://codeclimate.com/github/hopsoft/turbo_reflex/maintainability">
|
14
14
|
<img src="https://api.codeclimate.com/v1/badges/fe1162a742fe83a4fdfd/maintainability" />
|
@@ -112,6 +112,7 @@ TurboReflex is a lightweight Turbo Frame extension... which means that reactivit
|
|
112
112
|
- [rails](https://rubygems.org/gems/rails) `>=6.1`
|
113
113
|
- [turbo-rails](https://rubygems.org/gems/turbo-rails) `>=1.1`
|
114
114
|
- [@hotwired/turbo-rails](https://yarnpkg.com/package/@hotwired/turbo-rails) `>=7.1`
|
115
|
+
- [ruby](https://github.com/ruby/ruby) `>=2.7`
|
115
116
|
|
116
117
|
## Setup
|
117
118
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TurboReflex::AttributeSet
|
4
|
+
def initialize(prefix, attributes: {})
|
5
|
+
prefix = prefix.to_s
|
6
|
+
attrs = attributes.to_h.transform_values(&:to_s)
|
7
|
+
|
8
|
+
attrs.each do |key, value|
|
9
|
+
key = key.to_s.strip
|
10
|
+
|
11
|
+
next unless key.start_with?(prefix)
|
12
|
+
|
13
|
+
name = key.parameterize.underscore.delete_prefix("#{prefix}_")
|
14
|
+
value = value.to_i if value.to_s.match?(/\A\d+\z/)
|
15
|
+
value = value == "true" if value.is_a?(String) && value.match?(/\A(true|false)\z/i)
|
16
|
+
instance_variable_set "@#{name}", value
|
17
|
+
|
18
|
+
next if orig_respond_to_missing?(name, false)
|
19
|
+
|
20
|
+
self.class.define_method(name) { instance_variable_get :"@#{name}" }
|
21
|
+
self.class.define_method("#{name}?") { public_send(name).present? }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to?(name, include_all = false)
|
26
|
+
respond_to_missing? name, include_all
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :orig_respond_to_missing?, :respond_to_missing?
|
30
|
+
|
31
|
+
def respond_to_missing?(name, include_all)
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_missing(name, *args)
|
36
|
+
return false if name.end_with?("?")
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
data/lib/turbo_reflex/base.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "attribute_set"
|
4
|
+
|
3
5
|
# TurboReflex base superclass.
|
4
6
|
# All TurboReflex classes should inherit from this class.
|
5
7
|
#
|
@@ -99,20 +101,10 @@ class TurboReflex::Base
|
|
99
101
|
def element
|
100
102
|
@element ||= begin
|
101
103
|
attributes = params[:element_attributes]
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
memo[:dataset][key[5..].parameterize.underscore.to_sym] = attributes[key]
|
107
|
-
elsif key.start_with?("aria_")
|
108
|
-
memo[:aria][key[5..].parameterize.underscore.to_sym] = attributes[key]
|
109
|
-
else
|
110
|
-
memo[key.parameterize.underscore.to_sym] = attributes[key]
|
111
|
-
end
|
112
|
-
end
|
113
|
-
attrs[:aria] = OpenStruct.new(attrs[:aria])
|
114
|
-
attrs[:dataset] = OpenStruct.new(attrs[:dataset])
|
115
|
-
OpenStruct.new attrs
|
104
|
+
OpenStruct.new attributes.merge(
|
105
|
+
aria: TurboReflex::AttributeSet.new(:aria, attributes: attributes),
|
106
|
+
dataset: TurboReflex::AttributeSet.new(:data, attributes: attributes)
|
107
|
+
)
|
116
108
|
end
|
117
109
|
end
|
118
110
|
|
data/lib/turbo_reflex/engine.rb
CHANGED
@@ -5,13 +5,22 @@ require_relative "version"
|
|
5
5
|
require_relative "base"
|
6
6
|
require_relative "controller_pack"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
module TurboReflex
|
9
|
+
def self.config
|
10
|
+
Rails.application.config.turbo_reflex
|
11
|
+
end
|
12
|
+
|
13
|
+
class Engine < ::Rails::Engine
|
14
|
+
config.turbo_reflex = ActiveSupport::OrderedOptions.new
|
15
|
+
config.turbo_reflex[:max_cookie_size] = ActionDispatch::Cookies::MAX_COOKIE_SIZE / 2
|
16
|
+
config.turbo_reflex[:validate_client_token] = true
|
17
|
+
|
18
|
+
initializer "turbo_reflex.configuration" do
|
19
|
+
Mime::Type.register "text/vnd.turbo-reflex.html", :turbo_reflex
|
12
20
|
|
13
|
-
|
14
|
-
|
21
|
+
ActiveSupport.on_load(:action_controller_base) do
|
22
|
+
include TurboReflex::Controller
|
23
|
+
end
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
data/lib/turbo_reflex/runner.rb
CHANGED
@@ -195,6 +195,7 @@ class TurboReflex::Runner
|
|
195
195
|
end
|
196
196
|
|
197
197
|
def valid_client_token?
|
198
|
+
return true unless Rails.configuration.turbo_reflex.validate_client_token
|
198
199
|
return false unless client_token.present?
|
199
200
|
return false unless message_verifier.valid_message?(client_token)
|
200
201
|
unmasked_client_token = message_verifier.verify(client_token)
|
data/lib/turbo_reflex/state.rb
CHANGED
@@ -92,13 +92,13 @@ class TurboReflex::State
|
|
92
92
|
return if internal_keys.blank?
|
93
93
|
return if internal_data.blank?
|
94
94
|
|
95
|
-
percentage = max_bytesize > 0 ? ordinal_payload.bytesize / max_bytesize.to_f : 0
|
95
|
+
percentage = (max_bytesize > 0) ? ordinal_payload.bytesize / max_bytesize.to_f : 0
|
96
96
|
while percentage > 1
|
97
97
|
keys_to_keep = internal_keys.slice((internal_keys.length - (internal_keys.length / percentage).floor)..-1)
|
98
98
|
keys_to_remove = internal_keys - keys_to_keep
|
99
99
|
@internal_keys = keys_to_keep
|
100
100
|
keys_to_remove.each { |key| internal_data.delete key }
|
101
|
-
percentage = max_bytesize > 0 ? ordinal_payload.bytesize / max_bytesize.to_f : 0
|
101
|
+
percentage = (max_bytesize > 0) ? ordinal_payload.bytesize / max_bytesize.to_f : 0
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -18,12 +18,6 @@ class TurboReflex::StateManager
|
|
18
18
|
include ActiveModel::Dirty
|
19
19
|
|
20
20
|
class << self
|
21
|
-
attr_writer :cookie_max_bytesize
|
22
|
-
|
23
|
-
def cookie_max_bytesize
|
24
|
-
@cookie_max_bytesize ||= 2.kilobytes
|
25
|
-
end
|
26
|
-
|
27
21
|
def state_override_blocks
|
28
22
|
@state_overrides ||= {}
|
29
23
|
end
|
@@ -130,12 +124,12 @@ class TurboReflex::StateManager
|
|
130
124
|
def ordinal_payload
|
131
125
|
provisional_state.clear
|
132
126
|
state.shrink!
|
133
|
-
state.prune! max_bytesize: TurboReflex
|
127
|
+
state.prune! max_bytesize: TurboReflex.config.max_cookie_size
|
134
128
|
state.ordinal_payload
|
135
129
|
end
|
136
130
|
|
137
131
|
def write_cookie
|
138
|
-
return unless changed?
|
132
|
+
return unless changed? || cookie.blank?
|
139
133
|
cookies.signed["turbo_reflex.state"] = {value: ordinal_payload, path: "/", expires: 1.day.from_now}
|
140
134
|
changes_applied
|
141
135
|
rescue => error
|
data/lib/turbo_reflex/version.rb
CHANGED
data/package.json
CHANGED