phlex 2.2.1 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8d05844fe20e2d1fb987433eb837bcd1c3d62fc745d46fc879e3dbbe5698baf
4
- data.tar.gz: f8b6ed610858b14466b4bd60fe54b4ccb852da4ee255bd8902b96239feee3b25
3
+ metadata.gz: 43c33e9802643a8519ff45f208bccd4d8f6430cd642187e75ca2c7a8dbba7ea2
4
+ data.tar.gz: 8963d6c803fe8b20fc7143a5ff3c447f99a420b0ceb8556e697e844b2782a9f5
5
5
  SHA512:
6
- metadata.gz: 54e1bd698e847402f6cf49bff42001b7d28291b944a30b640e001309558d74d61a69006c199aca5c91166a60ac9ca5c520d5c872d0f6daa7c4f1c45a00008c6f
7
- data.tar.gz: e95f25405f6c07511e3caae42d2d346ca0f6461e2caf2e68a3089139687e69d7984067602d46ceebbdf11a11e7f95bebb425ccc1ccea4dd6d0fe4c59c4b3ced7
6
+ metadata.gz: cfd387e534c132acb663c28b3e5e1c28cba54251d1fc3ed1c1ceb649cd41825b243e6eb54eeb32f91934fc3493f8d473cd73f1d036995a97a09f2211b6b0ce61
7
+ data.tar.gz: 0b5f88d2d1f291719e61494a9027dd47e20a33eabe8987f01e4492ec0d16f01b1029177b5c8116402bf00f02f3d14f81f9604289ced1cd216cd05373f7db7220
data/lib/phlex/csv.rb CHANGED
@@ -139,32 +139,30 @@ class Phlex::CSV
139
139
  ","
140
140
  end
141
141
 
142
- private
143
-
144
- def column(header = nil, value)
142
+ private def column(header = nil, value)
145
143
  @_row_buffer << [header, value]
146
144
  end
147
145
 
148
- def each_item(&)
146
+ private def each_item(&)
149
147
  collection.each(&)
150
148
  end
151
149
 
152
150
  # Override and set to `false` to disable rendering headers.
153
- def render_headers?
151
+ private def render_headers?
154
152
  true
155
153
  end
156
154
 
157
155
  # Override and set to `true` to strip leading and trailing whitespace from values.
158
- def trim_whitespace?
156
+ private def trim_whitespace?
159
157
  false
160
158
  end
161
159
 
162
160
  # Override and set to `false` to disable CSV injection escapes or `true` to enable.
163
- def escape_csv_injection?
161
+ private def escape_csv_injection?
164
162
  UNDEFINED
165
163
  end
166
164
 
167
- def __escape__(buffer, value, escape_csv_injection:, strip_whitespace:, escape_regex:)
165
+ private def __escape__(buffer, value, escape_csv_injection:, strip_whitespace:, escape_regex:)
168
166
  value = case value
169
167
  when String
170
168
  value
@@ -218,12 +216,12 @@ class Phlex::CSV
218
216
  end
219
217
 
220
218
  # Handle legacy `view_template` method
221
- def respond_to_missing?(method_name, include_private)
219
+ private def respond_to_missing?(method_name, include_private)
222
220
  (method_name == :row_template && respond_to?(:view_template)) || super
223
221
  end
224
222
 
225
223
  # Handle legacy `view_template` method
226
- def method_missing(method_name, ...)
224
+ private def method_missing(method_name, ...)
227
225
  if method_name == :row_template && respond_to?(:view_template)
228
226
  warn "Deprecated: Use `row_template` instead of `view_template` in Phlex CSVs."
229
227
  self.class.alias_method :row_template, :view_template
@@ -233,7 +231,7 @@ class Phlex::CSV
233
231
  end
234
232
  end
235
233
 
236
- def ensure_escape_csv_injection_configured!
234
+ private def ensure_escape_csv_injection_configured!
237
235
  if escape_csv_injection? == UNDEFINED
238
236
  raise <<~MESSAGE
239
237
  You need to define `escape_csv_injection?` in #{self.class.name}.
@@ -28,9 +28,7 @@ class Phlex::FIFOCacheStore
28
28
  @fifo.clear
29
29
  end
30
30
 
31
- private
32
-
33
- def map_key(value)
31
+ private def map_key(value)
34
32
  case value
35
33
  when Array
36
34
  value.map { |it| map_key(it) }
data/lib/phlex/helpers.rb CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  # @api private
4
4
  module Phlex::Helpers
5
- private
6
-
7
- def mix(*args)
5
+ private def mix(*args)
8
6
  args.each_with_object({}) do |object, result|
9
7
  result.merge!(object) do |_key, old, new|
10
8
  case [old, new].freeze
@@ -43,7 +41,7 @@ module Phlex::Helpers
43
41
  end
44
42
  end
45
43
 
46
- def grab(**bindings)
44
+ private def grab(**bindings)
47
45
  if bindings.size > 1
48
46
  bindings.values
49
47
  else
@@ -1,6 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex::SGML::Elements
4
+ COMMA_SEPARATED_TOKENS = {
5
+ img: <<~RUBY,
6
+ if Array === (srcset_attribute = attributes[:srcset])
7
+ attributes[:srcset] = __nested_tokens__(srcset_attribute, ", ")
8
+ end
9
+ RUBY
10
+ link: <<~RUBY,
11
+ if Array === (media_attribute = attributes[:media])
12
+ attributes[:media] = __nested_tokens__(media_attribute, ", ")
13
+ end
14
+
15
+ if Array === (sizes_attribute = attributes[:sizes])
16
+ attributes[:sizes] = __nested_tokens__(sizes_attribute, ", ")
17
+ end
18
+
19
+ if Array === (imagesrcset_attribute = attributes[:imagesrcset])
20
+ rel_attribute = attributes[:rel] || attributes["rel"]
21
+ as_attribute = attributes[:as] || attributes["as"]
22
+
23
+ if ("preload" == rel_attribute || :preload == rel_attribute) && ("image" == as_attribute || :image == as_attribute)
24
+ attributes[:imagesrcset] = __nested_tokens__(imagesrcset_attribute, ", ")
25
+ end
26
+ end
27
+ RUBY
28
+ input: <<~RUBY,
29
+ if Array === (accept_attribute = attributes[:accept])
30
+ type_attribute = attributes[:type] || attributes["type"]
31
+
32
+ if "file" == type_attribute || :file == type_attribute
33
+ attributes[:accept] = __nested_tokens__(accept_attribute, ", ")
34
+ end
35
+ end
36
+ RUBY
37
+ }.freeze
38
+
4
39
  def __registered_elements__
5
40
  @__registered_elements__ ||= {}
6
41
  end
@@ -23,6 +58,7 @@ module Phlex::SGML::Elements
23
58
  if block_given # with content block
24
59
  buffer << "<#{tag}"
25
60
  begin
61
+ #{COMMA_SEPARATED_TOKENS[method_name]}
26
62
  buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes))
27
63
  ensure
28
64
  buffer << ">"
@@ -53,6 +89,7 @@ module Phlex::SGML::Elements
53
89
  else # without content
54
90
  buffer << "<#{tag}"
55
91
  begin
92
+ #{COMMA_SEPARATED_TOKENS[method_name]}
56
93
  buffer << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes))
57
94
  ensure
58
95
  buffer << "></#{tag}>"
@@ -114,6 +151,7 @@ module Phlex::SGML::Elements
114
151
  if attributes.length > 0 # with attributes
115
152
  buffer << "<#{tag}"
116
153
  begin
154
+ #{COMMA_SEPARATED_TOKENS[method_name]}
117
155
  buffer << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes))
118
156
  ensure
119
157
  buffer << ">"
data/lib/phlex/sgml.rb CHANGED
@@ -25,7 +25,7 @@ class Phlex::SGML
25
25
  end
26
26
 
27
27
  # Create a new instance of the component.
28
- # @note The block will not be delegated {#initialize}. Instead, it will be sent to {#template} when rendering.
28
+ # @note The block will not be delegated to {#initialize}. Instead, it will be sent to {#view_template} when rendering.
29
29
  def new(*a, **k, &block)
30
30
  if block
31
31
  object = super(*a, **k, &nil)
@@ -284,12 +284,12 @@ class Phlex::SGML
284
284
  location = caller_locations(1, 1)[0]
285
285
 
286
286
  full_key = [
287
- app_version_key, # invalidates the key when deploying new code in case of changes
287
+ app_version_key, # invalidates the key when deploying new code in case of changes
288
288
  self.class.name, # prevents collisions between classes
289
289
  (self.class.object_id if enable_cache_reloading?), # enables reloading
290
290
  location.base_label, # prevents collisions between different methods
291
291
  location.lineno, # prevents collisions between different lines
292
- cache_key, # allows for custom cache keys
292
+ cache_key, # allows for custom cache keys
293
293
  ].freeze
294
294
 
295
295
  low_level_cache(full_key, **, &content)
@@ -336,52 +336,50 @@ class Phlex::SGML
336
336
  ERB::Util.json_escape(string)
337
337
  end
338
338
 
339
- private
340
-
341
339
  # Override this method to use a different deployment key.
342
- def app_version_key
340
+ private def app_version_key
343
341
  Phlex::DEPLOYED_AT
344
342
  end
345
343
 
346
344
  # Override this method to use a different cache store.
347
- def cache_store
345
+ private def cache_store
348
346
  raise "Cache store not implemented."
349
347
  end
350
348
 
351
- def enable_cache_reloading?
349
+ private def enable_cache_reloading?
352
350
  false
353
351
  end
354
352
 
355
- def vanish(...)
353
+ private def vanish(...)
356
354
  capture(...)
357
355
  nil
358
356
  end
359
357
 
360
- def render?
358
+ private def render?
361
359
  true
362
360
  end
363
361
 
364
- def format_object(object)
362
+ private def format_object(object)
365
363
  case object
366
364
  when Float, Integer
367
365
  object.to_s
368
366
  end
369
367
  end
370
368
 
371
- def around_template
369
+ private def around_template
372
370
  yield
373
371
  nil
374
372
  end
375
373
 
376
- def before_template
374
+ private def before_template
377
375
  nil
378
376
  end
379
377
 
380
- def after_template
378
+ private def after_template
381
379
  nil
382
380
  end
383
381
 
384
- def __yield_content__
382
+ private def __yield_content__
385
383
  return unless block_given?
386
384
 
387
385
  buffer = @_state.buffer
@@ -393,7 +391,7 @@ class Phlex::SGML
393
391
  nil
394
392
  end
395
393
 
396
- def __yield_content_with_no_yield_args__
394
+ private def __yield_content_with_no_yield_args__
397
395
  return unless block_given?
398
396
 
399
397
  buffer = @_state.buffer
@@ -405,7 +403,7 @@ class Phlex::SGML
405
403
  nil
406
404
  end
407
405
 
408
- def __yield_content_with_args__(*a)
406
+ private def __yield_content_with_args__(*a)
409
407
  return unless block_given?
410
408
 
411
409
  buffer = @_state.buffer
@@ -417,7 +415,7 @@ class Phlex::SGML
417
415
  nil
418
416
  end
419
417
 
420
- def __implicit_output__(content)
418
+ private def __implicit_output__(content)
421
419
  state = @_state
422
420
  return true unless state.should_render?
423
421
 
@@ -442,7 +440,7 @@ class Phlex::SGML
442
440
  end
443
441
 
444
442
  # same as __implicit_output__ but escapes even `safe` objects
445
- def __text__(content)
443
+ private def __text__(content)
446
444
  state = @_state
447
445
  return true unless state.should_render?
448
446
 
@@ -464,7 +462,7 @@ class Phlex::SGML
464
462
  true
465
463
  end
466
464
 
467
- def __attributes__(attributes, buffer = +"")
465
+ private def __attributes__(attributes, buffer = +"")
468
466
  attributes.each do |k, v|
469
467
  next unless v
470
468
 
@@ -483,6 +481,10 @@ class Phlex::SGML
483
481
  v.name.tr("_", "-").gsub('"', "&quot;")
484
482
  when Integer, Float
485
483
  v.to_s
484
+ when Date
485
+ v.iso8601
486
+ when Time
487
+ v.respond_to?(:iso8601) ? v.iso8601 : v.strftime("%Y-%m-%dT%H:%M:%S%:z")
486
488
  when Hash
487
489
  case k
488
490
  when :style
@@ -557,7 +559,7 @@ class Phlex::SGML
557
559
 
558
560
  # Provides the nested-attributes case for serializing out attributes.
559
561
  # This allows us to skip many of the checks the `__attributes__` method must perform.
560
- def __nested_attributes__(attributes, base_name, buffer = +"")
562
+ private def __nested_attributes__(attributes, base_name, buffer = +"")
561
563
  attributes.each do |k, v|
562
564
  next unless v
563
565
 
@@ -606,7 +608,7 @@ class Phlex::SGML
606
608
  end
607
609
  end
608
610
 
609
- def __nested_tokens__(tokens)
611
+ private def __nested_tokens__(tokens, sep = " ")
610
612
  buffer = +""
611
613
 
612
614
  i, length = 0, tokens.length
@@ -617,28 +619,28 @@ class Phlex::SGML
617
619
  case token
618
620
  when String
619
621
  if i > 0
620
- buffer << " " << token
622
+ buffer << sep << token
621
623
  else
622
624
  buffer << token
623
625
  end
624
626
  when Symbol
625
627
  if i > 0
626
- buffer << " " << token.name.tr("_", "-")
628
+ buffer << sep << token.name.tr("_", "-")
627
629
  else
628
630
  buffer << token.name.tr("_", "-")
629
631
  end
630
632
  when Integer, Float, Phlex::SGML::SafeObject
631
633
  if i > 0
632
- buffer << " " << token.to_s
634
+ buffer << sep << token.to_s
633
635
  else
634
636
  buffer << token.to_s
635
637
  end
636
638
  when Array
637
639
  if token.length > 0
638
640
  if i > 0
639
- buffer << " " << __nested_tokens__(token)
641
+ buffer << sep << __nested_tokens__(token, sep)
640
642
  else
641
- buffer << __nested_tokens__(token)
643
+ buffer << __nested_tokens__(token, sep)
642
644
  end
643
645
  end
644
646
  when nil
@@ -654,7 +656,7 @@ class Phlex::SGML
654
656
  end
655
657
 
656
658
  # Result is **unsafe**, so it should be escaped!
657
- def __styles__(styles)
659
+ private def __styles__(styles)
658
660
  case styles
659
661
  when Array, Set
660
662
  styles.filter_map do |s|
data/lib/phlex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex
4
- VERSION = "2.2.1"
4
+ VERSION = "2.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  - Will Cosgrove
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-04 00:00:00.000000000 Z
11
+ date: 2025-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk