simple_calendar 3.1.1 → 3.1.3

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: 3df222c3d574cf3bbba06405c5552970bae59906ac0c791d97cc8f34fbe163ae
4
- data.tar.gz: d07dcabf52be54fbfef5044f2b7f18cf67775927ca093d6dd24fe51cdbc6bb87
3
+ metadata.gz: ff7274d9f8305cdc76ae38121b4722d5279eb9e548e0fcf15496952bf1bf96cd
4
+ data.tar.gz: 5fd6aa597857b392849405a1bb21ef1ef810857b58dfc1e53c096087c2f09374
5
5
  SHA512:
6
- metadata.gz: bdae22824856309b506f53182bc7763ca58328622b67635d157154dec4e2c31538225cb990509f59f8535a5a141a7c813a3b455b9b9d72b91d815cc268d0b861
7
- data.tar.gz: 379e36d12c03683e64eed2e6e0e3d4a65629ce111776cbd0738724022c98c20b21347d90a271bb3da1d608d35dbc1e5635c6bced2c5d19c029330dc23a3aac14
6
+ metadata.gz: 2dfd685ac91b3df7126c3705d7e9bf40141dc8e094b416cb01ee68ddb3d50528493844601fabebe2b2996edacc1a12b04af1816dbbf87e624eb2c469dd1f76aa
7
+ data.tar.gz: a44fd4ac691982e753d79b51ae60ebc1a72a202cb62c89d950939bbe42dd499f48772d3e9ee22ace84ebed9c8cf90bb0165a1dbe62414f83c461f200e85f406f
@@ -4,6 +4,14 @@ module SimpleCalendar
4
4
  class Calendar
5
5
  PARAM_KEY_BLACKLIST = :authenticity_token, :commit, :utf8, :_method, :script_name
6
6
 
7
+ # Keys url_for treats as URL options instead of query params. The built-in links don't
8
+ # need these dropped (see url_for_date), but custom calendars that copied the old
9
+ # `url_for(@params.merge(...))` override pass @params straight to url_for, so they're
10
+ # left out of @params to keep those links from being pointed at another host, etc.
11
+ URL_OPTION_KEYS = :host, :protocol, :port, :subdomain, :domain, :tld_length,
12
+ :trailing_slash, :anchor, :params, :only_path, :original_script_name,
13
+ :relative_url_root, :user, :password, :use_route, :_recall
14
+
7
15
  attr_accessor :view_context, :options
8
16
 
9
17
  def initialize(view_context, options = {}, &block)
@@ -13,12 +21,15 @@ module SimpleCalendar
13
21
  @block = block
14
22
 
15
23
  # Next and previous view links should use the same params as the current view
16
- @params = @view_context.respond_to?(:params) ? @view_context.params : {}
17
- @params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
18
- @params = @params.with_indifferent_access.except(*PARAM_KEY_BLACKLIST)
24
+ @request_params = @view_context.respond_to?(:params) ? @view_context.params : {}
25
+ @request_params = @request_params.to_unsafe_h if @request_params.respond_to?(:to_unsafe_h)
26
+ @request_params = @request_params.with_indifferent_access.except(*PARAM_KEY_BLACKLIST)
27
+
28
+ # Params passed in by the developer are trusted, so they're allowed to be url_for options
29
+ @calendar_params = @options.fetch(:params, {}).to_h.symbolize_keys
19
30
 
20
- # Add in any additional params the user passed in
21
- @params.merge!(@options.fetch(:params, {}))
31
+ # Nothing in here uses @params anymore, but custom calendars still build their own links from it
32
+ @params = @request_params.except(*URL_OPTION_KEYS).merge(@calendar_params)
22
33
  end
23
34
 
24
35
  def render_in(view_context, &block)
@@ -65,15 +76,25 @@ module SimpleCalendar
65
76
  end
66
77
 
67
78
  def url_for_next_view
68
- view_context.url_for(@params.merge(start_date_param => (date_range.last + 1.day).iso8601))
79
+ url_for_date(date_range.last + 1.day)
69
80
  end
70
81
 
71
82
  def url_for_previous_view
72
- view_context.url_for(@params.merge(start_date_param => (date_range.first - date_range.count.days).iso8601))
83
+ url_for_date(date_range.first - date_range.count.days)
73
84
  end
74
85
 
75
86
  def url_for_today_view
76
- view_context.url_for(@params.merge(start_date_param => Time.current.to_date.iso8601))
87
+ url_for_date(Time.current.to_date)
88
+ end
89
+
90
+ # Only routing params and params passed in by the developer are given to url_for as
91
+ # options. Everything else from the request goes under `params:`, which url_for always
92
+ # treats as query params, so no request param can be read as a URL option. Route
93
+ # segments named like a URL option (say `servers/:host`) are left to url_for, which
94
+ # fills them in from the current request as path segments.
95
+ def url_for_date(date)
96
+ url_options = path_parameters.except(*URL_OPTION_KEYS).merge(@calendar_params).merge(start_date_param => date.iso8601)
97
+ view_context.url_for(url_options.merge(params: @request_params.except(*path_parameters.keys, *url_options.keys)))
77
98
  end
78
99
 
79
100
  def date_range
@@ -139,6 +160,10 @@ module SimpleCalendar
139
160
 
140
161
  private
141
162
 
163
+ def path_parameters
164
+ view_context.try(:request)&.path_parameters || {}
165
+ end
166
+
142
167
  def start_date_from_params
143
168
  view_context.params[start_date_param].try(:to_date)
144
169
  rescue ArgumentError # Date::Error inherits from ArgumentError
@@ -5,7 +5,7 @@ module SimpleCalendar
5
5
  end
6
6
 
7
7
  def url_for_previous_view
8
- view_context.url_for(@params.merge(start_date_param => (date_range.first - 1.day).iso8601))
8
+ url_for_date(date_range.first - 1.day)
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "3.1.1"
2
+ VERSION = "3.1.3"
3
3
  end
@@ -21,7 +21,7 @@ module SimpleCalendar
21
21
  end
22
22
 
23
23
  def url_for_previous_view
24
- view_context.url_for(@params.merge(start_date_param => (date_range.first - 1.day).iso8601))
24
+ url_for_date(date_range.first - 1.day)
25
25
  end
26
26
 
27
27
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-12 00:00:00.000000000 Z
11
+ date: 2026-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails