phlex-slotable 0.4.0 → 1.0.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/CHANGELOG.md +8 -1
- data/README.md +33 -9
- data/benchmark/main.rb +15 -5
- data/lib/phlex/slotable/version.rb +1 -1
- data/lib/phlex/slotable.rb +22 -17
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 810c73b60d034b69e40450d09c717d2657eb85e216c1d6d0097763888a82ba91
|
4
|
+
data.tar.gz: '049b8f8a4f9fdeb0ae8448f8936e06a3a51aa8985431a48c578f9e54b2a42b96'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a3b2960e4add904feb0e196be56ea502cd2c842bf7f307712c9c6497d0b1636dda95b120bdbf8763ba451deb4f048890c82c1715c75b1857f65d654b437644
|
7
|
+
data.tar.gz: 631e23380c93a533152a70210494fc45c42521fd4e25fc60c690098fc5f3e7e5220e5db2222e13c498159f52e437550b4eddd59a49c1767d9d10cafd54c36a99
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
## [
|
1
|
+
## [1.0.0] - 2025-03-01
|
2
|
+
- Reimplement DeferredRender module
|
3
|
+
|
4
|
+
## [0.5.0] - 2024-09-08
|
5
|
+
- Prepare for Phlex 2.0 💪
|
6
|
+
- Drop Ruby 2.7, 3.0 and 3.1 support
|
7
|
+
- Add Phlex::Kit compatibility tests
|
8
|
+
- Make `Phlex::Slotable::VERSION` available by default
|
2
9
|
|
3
10
|
## [0.4.0] - 2024-02-14
|
4
11
|
- [BREAKING CHANGE] Rename `many` option to `collection`.
|
data/README.md
CHANGED
@@ -13,6 +13,7 @@ Phlex::Slotable enables slots feature to [Phlex](https://www.phlex.fun/) views.
|
|
13
13
|
- [Component slot](#component-slot)
|
14
14
|
- [Lambda slot](#lambda-slot)
|
15
15
|
- [Polymorphic slot](#polymorphic-slot)
|
16
|
+
- [Performance](#performance)
|
16
17
|
- [Development](#development)
|
17
18
|
- [Contributing](#contributing)
|
18
19
|
|
@@ -85,7 +86,7 @@ Returning:
|
|
85
86
|
|
86
87
|
```html
|
87
88
|
<header>
|
88
|
-
|
89
|
+
<h1>Hello World!</h1>
|
89
90
|
</header>
|
90
91
|
```
|
91
92
|
|
@@ -98,7 +99,7 @@ class PageComponent < Phlex::HTML
|
|
98
99
|
slot :title
|
99
100
|
|
100
101
|
def template
|
101
|
-
|
102
|
+
if header_slot?
|
102
103
|
header { render title_slot }
|
103
104
|
else
|
104
105
|
plain "No title"
|
@@ -113,7 +114,7 @@ A slot collection denotes a slot capable of being rendered multiple times within
|
|
113
114
|
|
114
115
|
```ruby
|
115
116
|
class ListComponent < Phlex::HTML
|
116
|
-
|
117
|
+
include Phlex::Slotable
|
117
118
|
|
118
119
|
slot :item, collection: true
|
119
120
|
end
|
@@ -123,7 +124,7 @@ To render a collection of slots, iterate over the `{slot_name}_slots` collection
|
|
123
124
|
|
124
125
|
```ruby
|
125
126
|
class ListComponent < Phlex::HTML
|
126
|
-
|
127
|
+
include Phlex::Slotable
|
127
128
|
|
128
129
|
slot :item, collection: true
|
129
130
|
|
@@ -210,8 +211,8 @@ Returning:
|
|
210
211
|
|
211
212
|
<ul>
|
212
213
|
<li class="active">Item A</li>
|
213
|
-
|
214
|
-
|
214
|
+
<li>Item B</li>
|
215
|
+
<li>Item C</li>
|
215
216
|
</ul>
|
216
217
|
</div>
|
217
218
|
```
|
@@ -235,7 +236,7 @@ class ListComponent < Phlex::HTML
|
|
235
236
|
|
236
237
|
slot :header, ->(size:, &content) do
|
237
238
|
render HeaderComponent.new(size: size, color: "primary")
|
238
|
-
|
239
|
+
end
|
239
240
|
slot :item, ->(href:, &content) { li { a(href: href, &content) } }, collection: true
|
240
241
|
|
241
242
|
def template
|
@@ -293,7 +294,7 @@ class IconComponent < Phlex::HTML
|
|
293
294
|
end
|
294
295
|
|
295
296
|
class ImageComponent < Phlex::HTML
|
296
|
-
|
297
|
+
# omitted code
|
297
298
|
end
|
298
299
|
|
299
300
|
class CardComponent < Phlex::HTML
|
@@ -304,7 +305,7 @@ class CardComponent < Phlex::HTML
|
|
304
305
|
def template
|
305
306
|
if avatar_slot?
|
306
307
|
div id: "avatar" do
|
307
|
-
|
308
|
+
render avatar_slot
|
308
309
|
end
|
309
310
|
end
|
310
311
|
end
|
@@ -343,6 +344,29 @@ Note that you need to use `with_{type}_{slot_name}` to set slot content. In the
|
|
343
344
|
> }
|
344
345
|
> ```
|
345
346
|
|
347
|
+
## Performance
|
348
|
+
Using Phlex::Slotable you don't suffer a performance penalty compared to using Phlex::DeferredRender, sometimes it can even be a little faster.
|
349
|
+
|
350
|
+
```
|
351
|
+
Generated using `ruby benchmark/main.rb`
|
352
|
+
|
353
|
+
Phlex 1.11.0
|
354
|
+
Phlex::Slotable 0.5.0
|
355
|
+
|
356
|
+
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23]
|
357
|
+
Warming up --------------------------------------
|
358
|
+
Deferred 22.176k i/100ms
|
359
|
+
Slotable 23.516k i/100ms
|
360
|
+
Calculating -------------------------------------
|
361
|
+
Deferred 222.727k (± 0.8%) i/s (4.49 μs/i) - 1.131M in 5.078157s
|
362
|
+
Slotable 237.405k (± 0.6%) i/s (4.21 μs/i) - 1.199M in 5.051936s
|
363
|
+
|
364
|
+
Comparison:
|
365
|
+
Slotable: 237405.0 i/s
|
366
|
+
Deferred: 222726.8 i/s - 1.07x slower
|
367
|
+
```
|
368
|
+
|
369
|
+
|
346
370
|
## Development
|
347
371
|
|
348
372
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/benchmark/main.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
+
RubyVM::YJIT.enable
|
2
|
+
|
1
3
|
require "benchmark"
|
2
4
|
require "benchmark/ips"
|
3
5
|
require_relative "../lib/phlex/slotable"
|
4
6
|
|
7
|
+
require "phlex/version"
|
8
|
+
|
9
|
+
puts "Phlex #{Phlex::VERSION}"
|
10
|
+
puts "Phlex::Slotable #{Phlex::Slotable::VERSION}"
|
11
|
+
|
5
12
|
class DeferredList < Phlex::HTML
|
6
|
-
|
13
|
+
def before_template(&)
|
14
|
+
vanish(&)
|
15
|
+
super
|
16
|
+
end
|
7
17
|
|
8
18
|
def initialize
|
9
19
|
@items = []
|
10
20
|
end
|
11
21
|
|
12
|
-
def
|
22
|
+
def view_template
|
13
23
|
if @header
|
14
24
|
h1(class: "header", &@header)
|
15
25
|
end
|
@@ -36,7 +46,7 @@ class SlotableList < Phlex::HTML
|
|
36
46
|
slot :header
|
37
47
|
slot :item, collection: true
|
38
48
|
|
39
|
-
def
|
49
|
+
def view_template
|
40
50
|
if header_slot
|
41
51
|
h1(class: "header", &header_slot)
|
42
52
|
end
|
@@ -50,7 +60,7 @@ class SlotableList < Phlex::HTML
|
|
50
60
|
end
|
51
61
|
|
52
62
|
class DeferredListExample < Phlex::HTML
|
53
|
-
def
|
63
|
+
def view_template
|
54
64
|
render DeferredList.new do |list|
|
55
65
|
list.header do
|
56
66
|
"Header"
|
@@ -68,7 +78,7 @@ class DeferredListExample < Phlex::HTML
|
|
68
78
|
end
|
69
79
|
|
70
80
|
class SlotableListExample < Phlex::HTML
|
71
|
-
def
|
81
|
+
def view_template
|
72
82
|
render SlotableList.new do |list|
|
73
83
|
list.with_header do
|
74
84
|
"Header"
|
data/lib/phlex/slotable.rb
CHANGED
@@ -4,13 +4,22 @@ require "phlex"
|
|
4
4
|
|
5
5
|
module Phlex
|
6
6
|
module Slotable
|
7
|
+
autoload :VERSION, "./slotable/version"
|
8
|
+
|
9
|
+
module DeferredRender
|
10
|
+
def before_template(&)
|
11
|
+
vanish(&)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
7
16
|
def self.included(base)
|
8
17
|
base.extend(ClassMethods)
|
9
18
|
end
|
10
19
|
|
11
20
|
module ClassMethods
|
12
21
|
def slot(slot_name, callable = nil, types: nil, collection: false)
|
13
|
-
include
|
22
|
+
include DeferredRender
|
14
23
|
|
15
24
|
if types
|
16
25
|
types.each do |type, callable|
|
@@ -44,7 +53,7 @@ module Phlex
|
|
44
53
|
RUBY
|
45
54
|
end
|
46
55
|
|
47
|
-
class_eval(setter_method, __FILE__, __LINE__
|
56
|
+
class_eval(setter_method, __FILE__, __LINE__)
|
48
57
|
define_lambda_method(slot_name_with_type, callable) if callable.is_a?(Proc)
|
49
58
|
end
|
50
59
|
|
@@ -56,41 +65,37 @@ module Phlex
|
|
56
65
|
def define_getter_method(slot_name, collection:)
|
57
66
|
getter_method = if collection
|
58
67
|
<<-RUBY
|
59
|
-
def #{slot_name}_slots
|
60
|
-
|
61
|
-
end
|
68
|
+
def #{slot_name}_slots = @#{slot_name}_slots ||= []
|
69
|
+
|
62
70
|
private :#{slot_name}_slots
|
63
71
|
RUBY
|
64
72
|
else
|
65
73
|
<<-RUBY
|
66
|
-
def #{slot_name}_slot
|
67
|
-
|
68
|
-
end
|
74
|
+
def #{slot_name}_slot = @#{slot_name}_slot
|
75
|
+
|
69
76
|
private :#{slot_name}_slot
|
70
77
|
RUBY
|
71
78
|
end
|
72
79
|
|
73
|
-
class_eval(getter_method, __FILE__, __LINE__
|
80
|
+
class_eval(getter_method, __FILE__, __LINE__)
|
74
81
|
end
|
75
82
|
|
76
83
|
def define_predicate_method(slot_name, collection:)
|
77
84
|
predicate_method = if collection
|
78
85
|
<<-RUBY
|
79
|
-
def #{slot_name}_slots?
|
80
|
-
|
81
|
-
end
|
86
|
+
def #{slot_name}_slots? = #{slot_name}_slots.any?
|
87
|
+
|
82
88
|
private :#{slot_name}_slots?
|
83
89
|
RUBY
|
84
90
|
else
|
85
91
|
<<-RUBY
|
86
|
-
def #{slot_name}_slot?
|
87
|
-
|
88
|
-
end
|
92
|
+
def #{slot_name}_slot? = !#{slot_name}_slot.nil?
|
93
|
+
|
89
94
|
private :#{slot_name}_slot?
|
90
95
|
RUBY
|
91
96
|
end
|
92
97
|
|
93
|
-
class_eval(predicate_method, __FILE__, __LINE__
|
98
|
+
class_eval(predicate_method, __FILE__, __LINE__)
|
94
99
|
end
|
95
100
|
|
96
101
|
def callable_value(slot_name, callable)
|
@@ -98,7 +103,7 @@ module Phlex
|
|
98
103
|
when nil
|
99
104
|
%(block)
|
100
105
|
when Proc
|
101
|
-
%(-> {
|
106
|
+
%(-> { __call_#{slot_name}__(*args, **kwargs, &block) })
|
102
107
|
else
|
103
108
|
%(#{callable}.new(*args, **kwargs, &block))
|
104
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex-slotable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stephann
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-01 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: phlex
|
@@ -16,15 +15,20 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
18
|
+
version: '2'
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
26
|
- - ">="
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
|
28
|
+
version: '2'
|
29
|
+
- - "<"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '3'
|
28
32
|
email:
|
29
33
|
- 3025661+stephannv@users.noreply.github.com
|
30
34
|
executables: []
|
@@ -45,7 +49,6 @@ licenses:
|
|
45
49
|
- MIT
|
46
50
|
metadata:
|
47
51
|
homepage_uri: https://github.com/stephannv/phlex-slotable
|
48
|
-
post_install_message:
|
49
52
|
rdoc_options: []
|
50
53
|
require_paths:
|
51
54
|
- lib
|
@@ -53,15 +56,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
56
|
requirements:
|
54
57
|
- - ">="
|
55
58
|
- !ruby/object:Gem::Version
|
56
|
-
version: 2
|
59
|
+
version: '3.2'
|
57
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
61
|
requirements:
|
59
62
|
- - ">="
|
60
63
|
- !ruby/object:Gem::Version
|
61
64
|
version: '0'
|
62
65
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
64
|
-
signing_key:
|
66
|
+
rubygems_version: 3.6.2
|
65
67
|
specification_version: 4
|
66
68
|
summary: Enable Slot API for Phlex views
|
67
69
|
test_files: []
|