unpoly-rails 3.10.0.rc1 → 3.10.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.
@@ -97,12 +97,20 @@ module Unpoly
97
97
 
98
98
  define_method "write_#{method}_to_response_headers" do
99
99
  value = send(method)
100
- stringified = field.stringify(value)
100
+ if Util.blank?(value)
101
+ # Blank values like [] have a present serialization ("[]".present? => true),
102
+ # so we must check the Ruby value here.
103
+ return
104
+ end
101
105
 
102
- if stringified.present? # app servers don't like blank header values
103
- header_name = send("#{method}_response_header_name")
104
- response.headers[header_name] = stringified
106
+ stringified = field.stringify(value)
107
+ if Util.blank?(stringified)
108
+ # App servers don't like blank header values
109
+ return
105
110
  end
111
+
112
+ header_name = send("#{method}_response_header_name")
113
+ response.headers[header_name] = stringified
106
114
  end
107
115
 
108
116
  end
@@ -66,7 +66,11 @@ module Unpoly
66
66
  end
67
67
 
68
68
  def target_changed?
69
- # The target has changed if either:
69
+ # The target is present if the original request contained an X-Up-Target header.
70
+ # That means it is also present if it was never changed on the server.
71
+ #
72
+ # To check whether the server has *changed* the target, we must look at either condition:
73
+ #
70
74
  # (1) The #target= setter was called, setting @server_target
71
75
  # (2) An up[target] param was set to preserve a previously changed target through a redirect.
72
76
  (@server_target && @server_target != target_from_request_headers) || !!target_from_params
@@ -256,10 +260,7 @@ module Unpoly
256
260
 
257
261
  write_expire_cache_to_response_headers
258
262
  write_evict_cache_to_response_headers
259
-
260
- if context_changes.present?
261
- write_context_changes_to_response_headers
262
- end
263
+ write_context_changes_to_response_headers
263
264
 
264
265
  if target_changed?
265
266
  # Only write the target to the response if it has changed.
@@ -405,18 +406,32 @@ module Unpoly
405
406
  end
406
407
 
407
408
  def fields_as_params
408
- params = {}
409
-
410
409
  # When the browser sees a redirect it will automatically resend the request headers
411
410
  # from the original request. This means that headers we set on the client (X-Up-Target, X-Up-Mode, etc.)
412
411
  # are automatically preserved through redirects.
413
412
  #
414
413
  # We still need to handle all the response headers that we set on the server.
415
414
  # There are encoded as params.
416
- params[context_changes_param_name] = serialized_context_changes # server-set header must be sent if present
417
- params[events_param_name] = serialized_events # server-set header must be sent if present
418
- params[expire_cache_param_name] = serialized_expire_cache # server-set header must be sent if present
419
- params[evict_cache_param_name] = serialized_evict_cache # server-set header must be sent if present
415
+ params = {}
416
+
417
+ if Util.present?(context_changes)
418
+ # Don't send an empty hash as _up_context_changes=%7B%7D
419
+ params[context_changes_param_name] = serialized_context_changes
420
+ end
421
+
422
+ if Util.present?(events)
423
+ # Don't send an empty array as _up_events=%5B%5D
424
+ params[events_param_name] = serialized_events
425
+ end
426
+
427
+ if Util.present?(expire_cache)
428
+ # Note that we must support evict_cache == false for up.cache.keep
429
+ params[expire_cache_param_name] = serialized_expire_cache
430
+ end
431
+
432
+ if Util.present?(evict_cache)
433
+ params[evict_cache_param_name] = serialized_evict_cache
434
+ end
420
435
 
421
436
  if target_changed?
422
437
  # Only write the target to the response if it has changed.
@@ -37,6 +37,14 @@ module Unpoly
37
37
  unicode_string.gsub(/[[:^ascii:]]/) { |char| "\\u" + char.ord.to_s(16).rjust(4, "0") }
38
38
  end
39
39
 
40
+ def blank?(value)
41
+ value.blank? && value != false
42
+ end
43
+
44
+ def present?(value)
45
+ !blank?(value)
46
+ end
47
+
40
48
  end
41
49
  end
42
50
  end
@@ -3,6 +3,6 @@ module Unpoly
3
3
  ##
4
4
  # The current version of the unpoly-rails gem.
5
5
  # The first 3 digits should match the version of the Unpoly frontend code.
6
- VERSION = '3.10.0.rc1'
6
+ VERSION = '3.10.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unpoly-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0.rc1
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-20 00:00:00.000000000 Z
11
+ date: 2025-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -153,11 +153,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  version: 2.3.0
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - ">"
156
+ - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: 1.3.1
158
+ version: '0'
159
159
  requirements: []
160
- rubygems_version: 3.0.3
160
+ rubygems_version: 3.2.3
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Rails bindings for Unpoly, the unobtrusive JavaScript framework