phlex-slotable 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47c3384e49460492a4ff914af1ecd7c6a16fa2841f90d49a4b83b84c305cf892
4
- data.tar.gz: aed5afef686e5f630b98842de12b18cc9f5634dd9f099b07273a7aa281f2915a
3
+ metadata.gz: 663b35110ae8bfad98b0a05e7a5a30afc296f16fc088b4271499ef02b03b9ba2
4
+ data.tar.gz: eb7153fef5861841d353e5404498dbbaadb8ad1bc7e7f83d6ae82f9bebc0551e
5
5
  SHA512:
6
- metadata.gz: 02c8d0105b65526025feea5fe1aadd7851a96e8406ccb574c0b7bb45d732e54dc85c98f6fbb182af5f57ae8f404cbe17a879bafad42ef6ce9ecd0c168c286d75
7
- data.tar.gz: 76a8bfd794fd7a7040bf1699db0dd3001f9d7de0cac0f641515494307a3cb370ab173588e2ba3610553c601f907d1da3990d5580702c1308c008e6d2ce11a327
6
+ metadata.gz: 7e7fcf450ddbd8bbab8b6eeb22fa54f0de68d9e5611da5c8c1f71e87bd27d2b7497eecdff21b9d61d40006ea7d1f0f782dfa1b4213284a46e8ae8988b8357394
7
+ data.tar.gz: ad39d88df8841cd7e7599b50b64d48e9b7faefc9abb44b3856749e728bad37c672dbd09fff420324d6b59257f1aaf65d5aef00af614a9a2f509b71e32fb923b3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2025-09-08
4
+ - Prepare for Phlex 2.0 💪
5
+ - Drop Ruby 2.7, 3.0 and 3.1 support
6
+ - Add Phlex::Kit compatibility tests
7
+ - Make `Phlex::Slotable::VERSION` available by default
8
+
3
9
  ## [0.4.0] - 2024-02-14
4
10
  - [BREAKING CHANGE] Rename `many` option to `collection`.
5
11
 
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
- <h1>Hello World!</h1>
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
- if header_slot?
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
- include Phlex::Slotable
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
- include Phlex::Slotable
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
- <li>Item B</li>
214
- <li>Item C</li>
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
- end
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
- # omitted code
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
- render avatar_slot
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
@@ -2,6 +2,11 @@ require "benchmark"
2
2
  require "benchmark/ips"
3
3
  require_relative "../lib/phlex/slotable"
4
4
 
5
+ require "phlex/version"
6
+
7
+ puts "Phlex #{Phlex::VERSION}"
8
+ puts "Phlex::Slotable #{Phlex::Slotable::VERSION}"
9
+
5
10
  class DeferredList < Phlex::HTML
6
11
  include Phlex::DeferredRender
7
12
 
@@ -9,7 +14,7 @@ class DeferredList < Phlex::HTML
9
14
  @items = []
10
15
  end
11
16
 
12
- def template
17
+ def view_template
13
18
  if @header
14
19
  h1(class: "header", &@header)
15
20
  end
@@ -36,7 +41,7 @@ class SlotableList < Phlex::HTML
36
41
  slot :header
37
42
  slot :item, collection: true
38
43
 
39
- def template
44
+ def view_template
40
45
  if header_slot
41
46
  h1(class: "header", &header_slot)
42
47
  end
@@ -50,7 +55,7 @@ class SlotableList < Phlex::HTML
50
55
  end
51
56
 
52
57
  class DeferredListExample < Phlex::HTML
53
- def template
58
+ def view_template
54
59
  render DeferredList.new do |list|
55
60
  list.header do
56
61
  "Header"
@@ -68,7 +73,7 @@ class DeferredListExample < Phlex::HTML
68
73
  end
69
74
 
70
75
  class SlotableListExample < Phlex::HTML
71
- def template
76
+ def view_template
72
77
  render SlotableList.new do |list|
73
78
  list.with_header do
74
79
  "Header"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Slotable
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "phlex"
4
+ require_relative "slotable/version"
4
5
 
5
6
  module Phlex
6
7
  module Slotable
@@ -44,7 +45,7 @@ module Phlex
44
45
  RUBY
45
46
  end
46
47
 
47
- class_eval(setter_method, __FILE__, __LINE__ + 1)
48
+ class_eval(setter_method, __FILE__, __LINE__)
48
49
  define_lambda_method(slot_name_with_type, callable) if callable.is_a?(Proc)
49
50
  end
50
51
 
@@ -56,41 +57,37 @@ module Phlex
56
57
  def define_getter_method(slot_name, collection:)
57
58
  getter_method = if collection
58
59
  <<-RUBY
59
- def #{slot_name}_slots
60
- @#{slot_name}_slots ||= []
61
- end
60
+ def #{slot_name}_slots = @#{slot_name}_slots ||= []
61
+
62
62
  private :#{slot_name}_slots
63
63
  RUBY
64
64
  else
65
65
  <<-RUBY
66
- def #{slot_name}_slot
67
- @#{slot_name}_slot
68
- end
66
+ def #{slot_name}_slot = @#{slot_name}_slot
67
+
69
68
  private :#{slot_name}_slot
70
69
  RUBY
71
70
  end
72
71
 
73
- class_eval(getter_method, __FILE__, __LINE__ + 1)
72
+ class_eval(getter_method, __FILE__, __LINE__)
74
73
  end
75
74
 
76
75
  def define_predicate_method(slot_name, collection:)
77
76
  predicate_method = if collection
78
77
  <<-RUBY
79
- def #{slot_name}_slots?
80
- #{slot_name}_slots.any?
81
- end
78
+ def #{slot_name}_slots? = #{slot_name}_slots.any?
79
+
82
80
  private :#{slot_name}_slots?
83
81
  RUBY
84
82
  else
85
83
  <<-RUBY
86
- def #{slot_name}_slot?
87
- !#{slot_name}_slot.nil?
88
- end
84
+ def #{slot_name}_slot? = !#{slot_name}_slot.nil?
85
+
89
86
  private :#{slot_name}_slot?
90
87
  RUBY
91
88
  end
92
89
 
93
- class_eval(predicate_method, __FILE__, __LINE__ + 1)
90
+ class_eval(predicate_method, __FILE__, __LINE__)
94
91
  end
95
92
 
96
93
  def callable_value(slot_name, callable)
@@ -98,7 +95,7 @@ module Phlex
98
95
  when nil
99
96
  %(block)
100
97
  when Proc
101
- %(-> { self.class.instance_method(:"__call_#{slot_name}__").bind_call(self, *args, **kwargs, &block) })
98
+ %(-> { __call_#{slot_name}__(*args, **kwargs, &block) })
102
99
  else
103
100
  %(#{callable}.new(*args, **kwargs, &block))
104
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-slotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - stephann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-15 00:00:00.000000000 Z
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
27
33
  description:
28
34
  email:
29
35
  - 3025661+stephannv@users.noreply.github.com
@@ -53,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
59
  requirements:
54
60
  - - ">="
55
61
  - !ruby/object:Gem::Version
56
- version: 2.7.0
62
+ version: 3.2.0
57
63
  required_rubygems_version: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - ">="
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
68
  requirements: []
63
- rubygems_version: 3.5.6
69
+ rubygems_version: 3.5.18
64
70
  signing_key:
65
71
  specification_version: 4
66
72
  summary: Enable Slot API for Phlex views