phlexible 3.2.0 → 3.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: ba0c7764b691fdb2ea92f5d8ef9389e1eb31bd97483f210e1b5e8f7c9fcd0c09
4
- data.tar.gz: 80b397992cf20e11e9e971d744f6a7cea5bfa56a1b1186c4a629ec04bb836624
3
+ metadata.gz: 4752fe1e276560bb8cca4c2115aabb11c36958588672cc5ec36d20bd3599d82e
4
+ data.tar.gz: 854eba7f90f061528db3de98a120bc457a679421103ef84eced0373457b1e3f1
5
5
  SHA512:
6
- metadata.gz: 375b7283fa50d41cf9e94bdc131f5faa469d73f67c8f2f8fdf34badb6c722edf193c9d9d64ffb7fee6f565d7d2a7a853a91f2d3f4ffed901e8d8b4421b967e9b
7
- data.tar.gz: b5fba4880d3a63faca0e67fe09a422a34b12b322ae6dd73ebca5b3a4b0137db0b80f177df306f18b27942a9d57fcd1501da6a2b8d9bafc5c3f6899fa729f4b90
6
+ metadata.gz: 1ce11414a8a6a792e6a50b20ded0135037dc946267ee802f4ae9f9bb031b22a3689b5eadf821029ad4d29f1ce4599e6d9ffa96ac1b3c4d15285df7f1c37415f9
7
+ data.tar.gz: 3a825528fc039dffedbbe35a588c52bd9e3c5cdbd336e0e23793d316d1949cbad2dd090a69fb36fe911b57f2b69e46983d17c3022c10177aebc8704975c49f3a
data/README.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  A bunch of helpers and goodies intended to make life with [Phlex](https://phlex.fun) even easier!
4
4
 
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [AliasView](#aliasview)
10
+ - [Callbacks](#callbacks)
11
+ - [PageTitle](#pagetitle)
12
+ - [ProcessAttributes](#processattributes)
13
+ - [Rails::ActionController::ImplicitRender](#railsactioncontrollerimplicitrender)
14
+ - [Rails::ControllerVariables](#railscontrollervariables)
15
+ - [Rails::AutoLayout](#railsautolayout)
16
+ - [Rails::AElement](#railsaelement)
17
+ - [Rails::ButtonTo](#railsbuttonto)
18
+ - [Rails::MetaTags](#railsmetatags)
19
+ - [Rails::Responder](#railsresponder)
20
+ - [Development](#development)
21
+ - [Contributing](#contributing)
22
+ - [License](#license)
23
+ - [Code of Conduct](#code-of-conduct)
24
+
5
25
  ## Installation
6
26
 
7
27
  Install the gem and add to the application's Gemfile by executing:
@@ -14,6 +34,128 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
34
 
15
35
  ## Usage
16
36
 
37
+ ### `AliasView`
38
+
39
+ Create an alias at a given `element`, to the given view class.
40
+
41
+ So instead of:
42
+
43
+ ```ruby
44
+ class MyView < Phlex::HTML
45
+ def view_template
46
+ div do
47
+ render My::Awesome::Component.new
48
+ end
49
+ end
50
+ end
51
+ ```
52
+
53
+ You can instead do:
54
+
55
+ ```ruby
56
+ class MyView < Phlex::HTML
57
+ extend Phlexible::AliasView
58
+
59
+ alias_view :awesome, -> { My::Awesome::Component }
60
+
61
+ def view_template
62
+ div do
63
+ awesome
64
+ end
65
+ end
66
+ end
67
+ ```
68
+
69
+ ### `Callbacks`
70
+
71
+ While Phlex does have `before_template`, `after_template`, and `around_template` hooks, they must be defined as regular Ruby methods, meaning you have to always remember to call `super` when redefining any hook method.
72
+
73
+ This module provides a more Rails-like interface for defining callbacks in your Phlex views, using `ActiveSupport::Callbacks`. It implements the same `before_template`, `after_template`, and `around_template` hooks as callbacks.
74
+
75
+ ```ruby
76
+ class Views::Users::Index < Views::Base
77
+ include Phlexible::Callbacks
78
+
79
+ before_template :set_title
80
+
81
+ def view_template
82
+ h1 { @title }
83
+ end
84
+
85
+ private
86
+
87
+ def set_title
88
+ @title = 'Users'
89
+ end
90
+ end
91
+ ```
92
+
93
+ You can still use the regular `before_template`, `after_template`, and `around_template` hooks as well, but I recommend that if you include this module, that you use callbacks instead.
94
+
95
+ When used with `Rails::AutoLayout`, layout callbacks (`before_layout`, `after_layout`, `around_layout`) are also available. See the `Rails::AutoLayout` section below.
96
+
97
+ ### `PageTitle`
98
+
99
+ Helper to assist in defining page titles within Phlex views. Also includes support for nested views, where each desendent view class will have its title prepended to the page title. Simply include *Phlexible::PageTitle* module and assign the title to the `page_title` class variable:
100
+
101
+ ```ruby
102
+ class MyView
103
+ include Phlexible::PageTitle
104
+ self.page_title = 'My Title'
105
+ end
106
+ ```
107
+
108
+ Then call the `page_title` method in the `<head>` of your page.
109
+
110
+ ### `ProcessAttributes`
111
+
112
+ > This functionality is already built in to **Phlex >= 1**. This module is only needed for **Phlex >= 2**.
113
+
114
+ Allows you to intercept and modify HTML element attributes before they are rendered. This is useful for adding default attributes, transforming values, or conditionally modifying attributes based on other attributes.
115
+
116
+ Extend your view class with `Phlexible::ProcessAttributes` and define a `process_attributes` instance method that receives the attributes hash and returns the modified hash.
117
+
118
+ ```ruby
119
+ class MyView < Phlex::HTML
120
+ extend Phlexible::ProcessAttributes
121
+
122
+ def process_attributes(attrs)
123
+ # Add a default class to all elements
124
+ attrs[:class] ||= 'my-default-class'
125
+ attrs
126
+ end
127
+
128
+ def view_template
129
+ div(id: 'container') { 'Hello' }
130
+ end
131
+ end
132
+ ```
133
+
134
+ This will output:
135
+
136
+ ```html
137
+ <div id="container" class="my-default-class">Hello</div>
138
+ ```
139
+
140
+ The `process_attributes` method is called for all standard HTML elements and void elements, as well as any custom elements registered with `register_element`.
141
+
142
+ ```ruby
143
+ class MyView < Phlex::HTML
144
+ extend Phlexible::ProcessAttributes
145
+
146
+ register_element :my_custom_element
147
+
148
+ def process_attributes(attrs)
149
+ attrs[:data_processed] = true
150
+ attrs
151
+ end
152
+
153
+ def view_template
154
+ my_custom_element(name: 'test') { 'Custom content' }
155
+ end
156
+ end
157
+ ```
158
+
17
159
  ### `Rails::ActionController::ImplicitRender`
18
160
 
19
161
  Adds support for default and `action_missing` rendering of Phlex views. So instead of this:
@@ -58,33 +200,48 @@ end
58
200
 
59
201
  This would resolve `UsersController#index` to `Views::Users::Index` instead.
60
202
 
61
- ### `Callbacks`
203
+ ### `Rails::ControllerVariables`
62
204
 
63
- While Phlex does have `before_template`, `after_template`, and `around_template` hooks, they must be defined as regular Ruby methods, meaning you have to always remember to call `super` when redefining any hook method.
205
+ > **NOTE:** Prior to **1.0.0**, this module was called `ControllerAttributes` with a very different API. This is no longer available since **1.0.0**.
64
206
 
65
- This module provides a more Rails-like interface for defining callbacks in your Phlex views, using `ActiveSupport::Callbacks`. It implements the same `before_template`, `after_template`, and `around_template` hooks as callbacks.
207
+ Include this module in your Phlex views to get access to the controller's instance variables. It provides an explicit interface for accessing controller instance variables from within the view.
66
208
 
67
209
  ```ruby
68
210
  class Views::Users::Index < Views::Base
69
- include Phlexible::Callbacks
211
+ include Phlexible::Rails::ControllerVariables
70
212
 
71
- before_template :set_title
213
+ controller_variable :first_name, :last_name
72
214
 
73
215
  def view_template
74
- h1 { @title }
216
+ h1 { "#{@first_name} #{@last_name}" }
75
217
  end
218
+ end
219
+ ```
76
220
 
77
- private
221
+ #### Options
78
222
 
79
- def set_title
80
- @title = 'Users'
81
- end
223
+ `controller_variable` accepts one or many symbols, or a hash of symbols to options.
224
+
225
+ - `as:` - If set, the given attribute will be renamed to the given value. Helpful to avoid naming conflicts.
226
+ - `allow_undefined:` - By default, if the instance variable is not defined in the controller, an
227
+ exception will be raised. If this option is to `true`, an error will not be raised.
228
+
229
+ You can also pass a hash of attributes to `controller_variable`, where the key is the controller
230
+ attribute, and the value is the renamed value, or options hash.
231
+
232
+ ```ruby
233
+ class Views::Users::Index < Views::Base
234
+ include Phlexible::Rails::ControllerVariables
235
+
236
+ controller_variable last_name: :surname, first_name: { as: :given_name, allow_undefined: true }
237
+
238
+ def view_template
239
+ h1 { "#{@given_name} #{@surname}" }
240
+ end
82
241
  end
83
242
  ```
84
243
 
85
- You can still use the regular `before_template`, `after_template`, and `around_template` hooks as well, but I recommend that if you include this module, that you use callbacks instead.
86
-
87
- When used with `Rails::AutoLayout`, layout callbacks (`before_layout`, `after_layout`, `around_layout`) are also available. See the `Rails::AutoLayout` section below.
244
+ Please note that defining a variable with the same name as an existing variable in the view will be overwritten.
88
245
 
89
246
  ### `Rails::AutoLayout`
90
247
 
@@ -182,80 +339,6 @@ end
182
339
 
183
340
  Layout resolution is cached per class in production. In development (when `Rails.configuration.enable_reloading` is enabled), layouts are resolved fresh on each render. You can manually clear the cache with `reset_resolved_layout!`.
184
341
 
185
- ### `Rails::ControllerVariables`
186
-
187
- > **NOTE:** Prior to **1.0.0**, this module was called `ControllerAttributes` with a very different API. This is no longer available since **1.0.0**.
188
-
189
- Include this module in your Phlex views to get access to the controller's instance variables. It provides an explicit interface for accessing controller instance variables from within the view.
190
-
191
- ```ruby
192
- class Views::Users::Index < Views::Base
193
- include Phlexible::Rails::ControllerVariables
194
-
195
- controller_variable :first_name, :last_name
196
-
197
- def view_template
198
- h1 { "#{@first_name} #{@last_name}" }
199
- end
200
- end
201
- ```
202
-
203
- #### Options
204
-
205
- `controller_variable` accepts one or many symbols, or a hash of symbols to options.
206
-
207
- - `as:` - If set, the given attribute will be renamed to the given value. Helpful to avoid naming conflicts.
208
- - `allow_undefined:` - By default, if the instance variable is not defined in the controller, an
209
- exception will be raised. If this option is to `true`, an error will not be raised.
210
-
211
- You can also pass a hash of attributes to `controller_variable`, where the key is the controller
212
- attribute, and the value is the renamed value, or options hash.
213
-
214
- ```ruby
215
- class Views::Users::Index < Views::Base
216
- include Phlexible::Rails::ControllerVariables
217
-
218
- controller_variable last_name: :surname, first_name: { as: :given_name, allow_undefined: true }
219
-
220
- def view_template
221
- h1 { "#{@given_name} #{@surname}" }
222
- end
223
- end
224
- ```
225
-
226
- Please note that defining a variable with the same name as an existing variable in the view will be overwritten.
227
-
228
- ### `Rails::Responder`
229
-
230
- If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to support implicit rendering similar to `Rails::ActionController::ImplicitRender` above. It will render the Phlex view using `respond_with` if one exists, and fall back to default rendering.
231
-
232
- Just include it in your ApplicationResponder:
233
-
234
- ```ruby
235
- class ApplicationResponder < ActionController::Responder
236
- include Phlexible::Rails::ActionController::ImplicitRender
237
- include Phlexible::Rails::Responder
238
- end
239
- ```
240
-
241
- Then simply `respond_with` in your action method as normal:
242
-
243
- ```ruby
244
- class UsersController < ApplicationController
245
- def new
246
- respond_with User.new
247
- end
248
-
249
- def index
250
- respond_with User.all
251
- end
252
- end
253
- ```
254
-
255
- This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include that in your `ApplicationController`.
256
-
257
- If you use `Rails::ControllerVariables` in your view, and define a `resource` attribute, the responder will pass that to your view.
258
-
259
342
  ### `Rails::AElement`
260
343
 
261
344
  No need to call Rails `link_to` helper, when you can simply render an anchor tag directly with Phlex. But unfortunately that means you lose some of the magic that `link_to` provides. Especially the automatic resolution of URL's and Rails routes.
@@ -278,6 +361,12 @@ class MyView < Phlex::HTML
278
361
  end
279
362
  ```
280
363
 
364
+ You can also pass `:back` as the `href` value, which will use the referrer URL if available, or fall back to `javascript:history.back()`:
365
+
366
+ ```ruby
367
+ a(href: :back) { 'Go back' }
368
+ ```
369
+
281
370
  ### `Rails::ButtonTo`
282
371
 
283
372
  Generates a form containing a single button that submits to the URL created by the set of options.
@@ -333,99 +422,36 @@ class MyView < Phlex::HTML
333
422
  end
334
423
  ```
335
424
 
336
- ### `AliasView`
337
-
338
- Create an alias at a given `element`, to the given view class.
339
-
340
- So instead of:
341
-
342
- ```ruby
343
- class MyView < Phlex::HTML
344
- def view_template
345
- div do
346
- render My::Awesome::Component.new
347
- end
348
- end
349
- end
350
- ```
351
-
352
- You can instead do:
353
-
354
- ```ruby
355
- class MyView < Phlex::HTML
356
- extend Phlexible::AliasView
357
-
358
- alias_view :awesome, -> { My::Awesome::Component }
359
-
360
- def view_template
361
- div do
362
- awesome
363
- end
364
- end
365
- end
366
- ```
425
+ ### `Rails::Responder`
367
426
 
368
- ### `PageTitle`
427
+ If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to support implicit rendering similar to `Rails::ActionController::ImplicitRender` above. It will render the Phlex view using `respond_with` if one exists, and fall back to default rendering.
369
428
 
370
- Helper to assist in defining page titles within Phlex views. Also includes support for nested views, where each desendent view class will have its title prepended to the page title. Simply include *Phlexible::PageTitle* module and assign the title to the `page_title` class variable:
429
+ Just include it in your ApplicationResponder:
371
430
 
372
431
  ```ruby
373
- class MyView
374
- include Phlexible::PageTitle
375
- self.page_title = 'My Title'
432
+ class ApplicationResponder < ActionController::Responder
433
+ include Phlexible::Rails::ActionController::ImplicitRender
434
+ include Phlexible::Rails::Responder
376
435
  end
377
436
  ```
378
437
 
379
- Then call the `page_title` method in the `<head>` of your page.
380
-
381
- ### `ProcessAttributes`
382
-
383
- > This functionality is already built in to **Phlex >= 1**. This module is only needed for **Phlex >= 2**.
384
-
385
- Allows you to intercept and modify HTML element attributes before they are rendered. This is useful for adding default attributes, transforming values, or conditionally modifying attributes based on other attributes.
386
-
387
- Extend your view class with `Phlexible::ProcessAttributes` and define a `process_attributes` instance method that receives the attributes hash and returns the modified hash.
438
+ Then simply `respond_with` in your action method as normal:
388
439
 
389
440
  ```ruby
390
- class MyView < Phlex::HTML
391
- extend Phlexible::ProcessAttributes
392
-
393
- def process_attributes(attrs)
394
- # Add a default class to all elements
395
- attrs[:class] ||= 'my-default-class'
396
- attrs
441
+ class UsersController < ApplicationController
442
+ def new
443
+ respond_with User.new
397
444
  end
398
445
 
399
- def view_template
400
- div(id: 'container') { 'Hello' }
446
+ def index
447
+ respond_with User.all
401
448
  end
402
449
  end
403
450
  ```
404
451
 
405
- This will output:
406
-
407
- ```html
408
- <div id="container" class="my-default-class">Hello</div>
409
- ```
410
-
411
- The `process_attributes` method is called for all standard HTML elements and void elements, as well as any custom elements registered with `register_element`.
412
-
413
- ```ruby
414
- class MyView < Phlex::HTML
415
- extend Phlexible::ProcessAttributes
416
-
417
- register_element :my_custom_element
418
-
419
- def process_attributes(attrs)
420
- attrs[:data_processed] = true
421
- attrs
422
- end
452
+ This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include that in your `ApplicationController`.
423
453
 
424
- def view_template
425
- my_custom_element(name: 'test') { 'Custom content' }
426
- end
427
- end
428
- ```
454
+ If you use `Rails::ControllerVariables` in your view, and define a `resource` attribute, the responder will pass that to your view.
429
455
 
430
456
  ## Development
431
457
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- phlexible (3.1.1)
4
+ phlexible (3.3.0)
5
5
  phlex (>= 1.10.0, < 3.0.0)
6
6
  phlex-rails (>= 1.2.0, < 3.0.0)
7
7
  rails (>= 7.2.0, < 9.0.0)
@@ -416,7 +416,7 @@ CHECKSUMS
416
416
  parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
417
417
  phlex (1.11.0) sha256=979548e79a205c981612f1ab613addc8fa128c8092694d02f41aad4cea905e73
418
418
  phlex-rails (1.2.2) sha256=a20218449e71bc9fa5a71b672fbede8a654c6b32a58f1c4ea83ddc1682307a4c
419
- phlexible (3.1.1)
419
+ phlexible (3.3.0)
420
420
  pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
421
421
  pretty_please (0.2.0) sha256=1f00296f946ae8ffd53db25803ed3998d615b9cc07526517dc75fcca6af3a0d3
422
422
  prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- phlexible (3.1.1)
4
+ phlexible (3.3.0)
5
5
  phlex (>= 1.10.0, < 3.0.0)
6
6
  phlex-rails (>= 1.2.0, < 3.0.0)
7
7
  rails (>= 7.2.0, < 9.0.0)
@@ -414,7 +414,7 @@ CHECKSUMS
414
414
  parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
415
415
  phlex (1.11.0) sha256=979548e79a205c981612f1ab613addc8fa128c8092694d02f41aad4cea905e73
416
416
  phlex-rails (1.2.2) sha256=a20218449e71bc9fa5a71b672fbede8a654c6b32a58f1c4ea83ddc1682307a4c
417
- phlexible (3.1.1)
417
+ phlexible (3.3.0)
418
418
  pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
419
419
  pretty_please (0.2.0) sha256=1f00296f946ae8ffd53db25803ed3998d615b9cc07526517dc75fcca6af3a0d3
420
420
  prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- phlexible (3.1.1)
4
+ phlexible (3.3.0)
5
5
  phlex (>= 1.10.0, < 3.0.0)
6
6
  phlex-rails (>= 1.2.0, < 3.0.0)
7
7
  rails (>= 7.2.0, < 9.0.0)
@@ -422,7 +422,7 @@ CHECKSUMS
422
422
  parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
423
423
  phlex (2.4.0) sha256=8aad2f0cd792d7b1bd287f15a1f89474c9cacac28120dc33d2a81467ae934067
424
424
  phlex-rails (2.4.0) sha256=2bcddbd488681acb25753bab1887d3ac150e644244ff8ba307f2171a4d0195f5
425
- phlexible (3.1.1)
425
+ phlexible (3.3.0)
426
426
  pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
427
427
  pretty_please (0.2.0) sha256=1f00296f946ae8ffd53db25803ed3998d615b9cc07526517dc75fcca6af3a0d3
428
428
  prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- phlexible (3.1.1)
4
+ phlexible (3.3.0)
5
5
  phlex (>= 1.10.0, < 3.0.0)
6
6
  phlex-rails (>= 1.2.0, < 3.0.0)
7
7
  rails (>= 7.2.0, < 9.0.0)
@@ -420,7 +420,7 @@ CHECKSUMS
420
420
  parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
421
421
  phlex (2.4.0) sha256=8aad2f0cd792d7b1bd287f15a1f89474c9cacac28120dc33d2a81467ae934067
422
422
  phlex-rails (2.4.0) sha256=2bcddbd488681acb25753bab1887d3ac150e644244ff8ba307f2171a4d0195f5
423
- phlexible (3.1.1)
423
+ phlexible (3.3.0)
424
424
  pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
425
425
  pretty_please (0.2.0) sha256=1f00296f946ae8ffd53db25803ed3998d615b9cc07526517dc75fcca6af3a0d3
426
426
  prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'phlex/version'
4
+
3
5
  module Phlexible
4
6
  module Rails
5
- # Calls `url_for` for the `href` attribute.
7
+ # Calls `url_for` for the `href` attribute, and supports a `:back` `href` value.
6
8
  module AElement
7
9
  extend ActiveSupport::Concern
8
10
 
@@ -10,9 +12,43 @@ module Phlexible
10
12
  include Phlex::Rails::Helpers::URLFor
11
13
  end
12
14
 
13
- def a(href:, **, &)
14
- super(href: url_for(href), **, &)
15
+ def a(href:, **attrs, &)
16
+ attrs[:href] = href == :back ? _back_url : url_for(href)
17
+
18
+ super(**attrs, &)
15
19
  end
20
+
21
+ private
22
+
23
+ JAVASCRIPT_BACK = 'javascript:history.back()'
24
+ private_constant :JAVASCRIPT_BACK
25
+
26
+ if Phlex::VERSION >= '2.0.0'
27
+ def _back_url
28
+ _filtered_referrer || safe(JAVASCRIPT_BACK)
29
+ end
30
+ else
31
+ # Wraps a value to bypass Phlex 1.x's javascript: href stripping.
32
+ SafeHref = Struct.new(:value) do
33
+ def to_phlex_attribute_value = value
34
+ def to_s = ''
35
+ end
36
+ private_constant :SafeHref
37
+
38
+ def _back_url
39
+ _filtered_referrer || SafeHref.new(JAVASCRIPT_BACK)
40
+ end
41
+ end
42
+
43
+ def _filtered_referrer # :nodoc:
44
+ controller = respond_to?(:view_context) ? view_context : helpers
45
+
46
+ if controller.respond_to?(:request)
47
+ referrer = controller.request.env['HTTP_REFERER']
48
+ referrer if referrer && URI(referrer).scheme != 'javascript'
49
+ end
50
+ rescue URI::InvalidURIError # rubocop:disable Lint/SuppressedException
51
+ end
16
52
  end
17
53
  end
18
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlexible
4
- VERSION = '3.2.0'
4
+ VERSION = '3.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexible
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Moss