phlexible 0.4.2 → 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: e792518495712903ee8eb0ea65f89dce5d56918a0ffc966ebfc11339093ee5ab
4
- data.tar.gz: 5d260ec103129ec9c9b945e0f862830200d777b72bc3602866c04beb468f1945
3
+ metadata.gz: d396818a6eb976923deb622cc3a991b1d9720a1ae9866d98580634e0ac068072
4
+ data.tar.gz: 9c869afbe9da2ff0d7229b7101204e4b27b266c03679061468629cb663604e55
5
5
  SHA512:
6
- metadata.gz: 9e6bf020811e5e42b513c42420d437c8aa59676398bd08a8ac57c5e7c5239a1287f36e4ab5b2fb7f81226d6350ed937d0008a15da1b659efbf00f5bdf3e2e5b9
7
- data.tar.gz: c12372151829b8b5effbd308c4258731fd83d7c59edf3bdb6c3ec48cc9e2ac9c7862b20c8de1b2f3e3ebaf16a8f69e5dfd120bd22ba7a4b2f68ab4ebb562ebd7
6
+ metadata.gz: 86ef75286d70e4fc05cfcfa67f5bab635240f843e56415cf855344c75ce7ab0ee6e0bc5768b2c573f0294aa2a35b31fab1121a60a36718e88e5cb049222d54de
7
+ data.tar.gz: ae2b2b5805b40f559f3159b05e86607054e201f27c6db71fc4734c3a37597b9fd8354d68071abd4cd0d98fe1fb3d8d9f3adc5d78931eb78c89081be39965de86
data/.rubocop.yml CHANGED
@@ -3,16 +3,20 @@ AllCops:
3
3
  SuggestExtensions: false
4
4
  NewCops: enable
5
5
 
6
- Style/Documentation:
7
- Enabled: false
8
- Metrics/BlockLength:
9
- Exclude:
10
- - test/**/*
11
6
  Lint/ConstantDefinitionInBlock:
12
7
  Exclude:
13
8
  - test/**/*
9
+
10
+ Style/Documentation:
11
+ Enabled: false
14
12
  Style/ClassAndModuleChildren:
15
13
  Exclude:
16
14
  - fixtures/**/*
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - test/**/*
17
19
  Metrics/MethodLength:
18
- Max: 15
20
+ Max: 20
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 8
data/Gemfile CHANGED
@@ -8,5 +8,5 @@ gemspec
8
8
  gem 'combustion'
9
9
  gem 'phlex-testing-nokogiri'
10
10
  gem 'rake', '~> 13.0'
11
- gem 'rubocop', '~> 1.21'
12
- gem 'sus', '~> 0.20.0'
11
+ gem 'rubocop', '~> 1.55'
12
+ gem 'sus'
data/Gemfile.lock CHANGED
@@ -1,79 +1,80 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phlexible (0.4.1)
4
+ phlexible (0.5.0)
5
5
  phlex (~> 1.8.1)
6
6
  phlex-rails (~> 1.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.4.3)
12
- actionpack (= 7.0.4.3)
13
- activesupport (= 7.0.4.3)
11
+ actioncable (7.0.8)
12
+ actionpack (= 7.0.8)
13
+ activesupport (= 7.0.8)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.4.3)
17
- actionpack (= 7.0.4.3)
18
- activejob (= 7.0.4.3)
19
- activerecord (= 7.0.4.3)
20
- activestorage (= 7.0.4.3)
21
- activesupport (= 7.0.4.3)
16
+ actionmailbox (7.0.8)
17
+ actionpack (= 7.0.8)
18
+ activejob (= 7.0.8)
19
+ activerecord (= 7.0.8)
20
+ activestorage (= 7.0.8)
21
+ activesupport (= 7.0.8)
22
22
  mail (>= 2.7.1)
23
23
  net-imap
24
24
  net-pop
25
25
  net-smtp
26
- actionmailer (7.0.4.3)
27
- actionpack (= 7.0.4.3)
28
- actionview (= 7.0.4.3)
29
- activejob (= 7.0.4.3)
30
- activesupport (= 7.0.4.3)
26
+ actionmailer (7.0.8)
27
+ actionpack (= 7.0.8)
28
+ actionview (= 7.0.8)
29
+ activejob (= 7.0.8)
30
+ activesupport (= 7.0.8)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  net-imap
33
33
  net-pop
34
34
  net-smtp
35
35
  rails-dom-testing (~> 2.0)
36
- actionpack (7.0.4.3)
37
- actionview (= 7.0.4.3)
38
- activesupport (= 7.0.4.3)
39
- rack (~> 2.0, >= 2.2.0)
36
+ actionpack (7.0.8)
37
+ actionview (= 7.0.8)
38
+ activesupport (= 7.0.8)
39
+ rack (~> 2.0, >= 2.2.4)
40
40
  rack-test (>= 0.6.3)
41
41
  rails-dom-testing (~> 2.0)
42
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.4.3)
44
- actionpack (= 7.0.4.3)
45
- activerecord (= 7.0.4.3)
46
- activestorage (= 7.0.4.3)
47
- activesupport (= 7.0.4.3)
43
+ actiontext (7.0.8)
44
+ actionpack (= 7.0.8)
45
+ activerecord (= 7.0.8)
46
+ activestorage (= 7.0.8)
47
+ activesupport (= 7.0.8)
48
48
  globalid (>= 0.6.0)
49
49
  nokogiri (>= 1.8.5)
50
- actionview (7.0.4.3)
51
- activesupport (= 7.0.4.3)
50
+ actionview (7.0.8)
51
+ activesupport (= 7.0.8)
52
52
  builder (~> 3.1)
53
53
  erubi (~> 1.4)
54
54
  rails-dom-testing (~> 2.0)
55
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.4.3)
57
- activesupport (= 7.0.4.3)
56
+ activejob (7.0.8)
57
+ activesupport (= 7.0.8)
58
58
  globalid (>= 0.3.6)
59
- activemodel (7.0.4.3)
60
- activesupport (= 7.0.4.3)
61
- activerecord (7.0.4.3)
62
- activemodel (= 7.0.4.3)
63
- activesupport (= 7.0.4.3)
64
- activestorage (7.0.4.3)
65
- actionpack (= 7.0.4.3)
66
- activejob (= 7.0.4.3)
67
- activerecord (= 7.0.4.3)
68
- activesupport (= 7.0.4.3)
59
+ activemodel (7.0.8)
60
+ activesupport (= 7.0.8)
61
+ activerecord (7.0.8)
62
+ activemodel (= 7.0.8)
63
+ activesupport (= 7.0.8)
64
+ activestorage (7.0.8)
65
+ actionpack (= 7.0.8)
66
+ activejob (= 7.0.8)
67
+ activerecord (= 7.0.8)
68
+ activesupport (= 7.0.8)
69
69
  marcel (~> 1.0)
70
70
  mini_mime (>= 1.1.0)
71
- activesupport (7.0.4.3)
71
+ activesupport (7.0.8)
72
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
73
73
  i18n (>= 1.6, < 2)
74
74
  minitest (>= 5.1)
75
75
  tzinfo (~> 2.0)
76
76
  ast (2.4.2)
77
+ base64 (0.1.1)
77
78
  builder (3.2.4)
78
79
  cgi (0.3.6)
79
80
  combustion (1.3.7)
@@ -83,17 +84,18 @@ GEM
83
84
  concurrent-ruby (1.2.2)
84
85
  crass (1.0.6)
85
86
  date (3.3.3)
86
- erb (4.0.2)
87
+ erb (4.0.3)
87
88
  cgi (>= 0.3.3)
88
89
  erubi (1.12.0)
89
- globalid (1.1.0)
90
- activesupport (>= 5.0)
91
- i18n (1.12.0)
90
+ globalid (1.2.1)
91
+ activesupport (>= 6.1)
92
+ i18n (1.14.1)
92
93
  concurrent-ruby (~> 1.0)
93
94
  json (2.6.3)
94
- loofah (2.20.0)
95
+ language_server-protocol (3.17.0.3)
96
+ loofah (2.21.3)
95
97
  crass (~> 1.0.2)
96
- nokogiri (>= 1.5.9)
98
+ nokogiri (>= 1.12.0)
97
99
  mail (2.8.1)
98
100
  mini_mime (>= 0.1.1)
99
101
  net-imap
@@ -101,9 +103,9 @@ GEM
101
103
  net-smtp
102
104
  marcel (1.0.2)
103
105
  method_source (1.0.0)
104
- mini_mime (1.1.2)
105
- minitest (5.18.0)
106
- net-imap (0.3.4)
106
+ mini_mime (1.1.5)
107
+ minitest (5.20.0)
108
+ net-imap (0.3.7)
107
109
  date
108
110
  net-protocol
109
111
  net-pop (0.1.2)
@@ -113,15 +115,16 @@ GEM
113
115
  net-smtp (0.3.3)
114
116
  net-protocol
115
117
  nio4r (2.5.9)
116
- nokogiri (1.14.3-arm64-darwin)
118
+ nokogiri (1.15.4-arm64-darwin)
117
119
  racc (~> 1.4)
118
- nokogiri (1.14.3-x86_64-darwin)
120
+ nokogiri (1.15.4-x86_64-darwin)
119
121
  racc (~> 1.4)
120
- nokogiri (1.14.3-x86_64-linux)
122
+ nokogiri (1.15.4-x86_64-linux)
121
123
  racc (~> 1.4)
122
124
  parallel (1.23.0)
123
- parser (3.2.2.1)
125
+ parser (3.2.2.3)
124
126
  ast (~> 2.4.1)
127
+ racc
125
128
  phlex (1.8.1)
126
129
  concurrent-ruby (~> 1.2)
127
130
  erb (>= 4)
@@ -133,63 +136,67 @@ GEM
133
136
  phlex-testing-nokogiri (0.1.0)
134
137
  nokogiri (~> 1.13)
135
138
  phlex (>= 0.5)
136
- racc (1.6.2)
137
- rack (2.2.6.4)
139
+ racc (1.7.1)
140
+ rack (2.2.8)
138
141
  rack-test (2.1.0)
139
142
  rack (>= 1.3)
140
- rails (7.0.4.3)
141
- actioncable (= 7.0.4.3)
142
- actionmailbox (= 7.0.4.3)
143
- actionmailer (= 7.0.4.3)
144
- actionpack (= 7.0.4.3)
145
- actiontext (= 7.0.4.3)
146
- actionview (= 7.0.4.3)
147
- activejob (= 7.0.4.3)
148
- activemodel (= 7.0.4.3)
149
- activerecord (= 7.0.4.3)
150
- activestorage (= 7.0.4.3)
151
- activesupport (= 7.0.4.3)
143
+ rails (7.0.8)
144
+ actioncable (= 7.0.8)
145
+ actionmailbox (= 7.0.8)
146
+ actionmailer (= 7.0.8)
147
+ actionpack (= 7.0.8)
148
+ actiontext (= 7.0.8)
149
+ actionview (= 7.0.8)
150
+ activejob (= 7.0.8)
151
+ activemodel (= 7.0.8)
152
+ activerecord (= 7.0.8)
153
+ activestorage (= 7.0.8)
154
+ activesupport (= 7.0.8)
152
155
  bundler (>= 1.15.0)
153
- railties (= 7.0.4.3)
154
- rails-dom-testing (2.0.3)
155
- activesupport (>= 4.2.0)
156
+ railties (= 7.0.8)
157
+ rails-dom-testing (2.2.0)
158
+ activesupport (>= 5.0.0)
159
+ minitest
156
160
  nokogiri (>= 1.6)
157
- rails-html-sanitizer (1.5.0)
158
- loofah (~> 2.19, >= 2.19.1)
159
- railties (7.0.4.3)
160
- actionpack (= 7.0.4.3)
161
- activesupport (= 7.0.4.3)
161
+ rails-html-sanitizer (1.6.0)
162
+ loofah (~> 2.21)
163
+ nokogiri (~> 1.14)
164
+ railties (7.0.8)
165
+ actionpack (= 7.0.8)
166
+ activesupport (= 7.0.8)
162
167
  method_source
163
168
  rake (>= 12.2)
164
169
  thor (~> 1.0)
165
170
  zeitwerk (~> 2.5)
166
171
  rainbow (3.1.1)
167
172
  rake (13.0.6)
168
- regexp_parser (2.8.0)
169
- rexml (3.2.5)
170
- rubocop (1.50.2)
173
+ regexp_parser (2.8.1)
174
+ rexml (3.2.6)
175
+ rubocop (1.56.3)
176
+ base64 (~> 0.1.1)
171
177
  json (~> 2.3)
178
+ language_server-protocol (>= 3.17.0)
172
179
  parallel (~> 1.10)
173
- parser (>= 3.2.0.0)
180
+ parser (>= 3.2.2.3)
174
181
  rainbow (>= 2.2.2, < 4.0)
175
182
  regexp_parser (>= 1.8, < 3.0)
176
183
  rexml (>= 3.2.5, < 4.0)
177
- rubocop-ast (>= 1.28.0, < 2.0)
184
+ rubocop-ast (>= 1.28.1, < 2.0)
178
185
  ruby-progressbar (~> 1.7)
179
186
  unicode-display_width (>= 2.4.0, < 3.0)
180
- rubocop-ast (1.28.0)
187
+ rubocop-ast (1.29.0)
181
188
  parser (>= 3.2.1.0)
182
189
  ruby-progressbar (1.13.0)
183
- sus (0.20.3)
184
- thor (1.2.1)
185
- timeout (0.3.2)
190
+ sus (0.23.0)
191
+ thor (1.2.2)
192
+ timeout (0.4.0)
186
193
  tzinfo (2.0.6)
187
194
  concurrent-ruby (~> 1.0)
188
195
  unicode-display_width (2.4.2)
189
- websocket-driver (0.7.5)
196
+ websocket-driver (0.7.6)
190
197
  websocket-extensions (>= 0.1.0)
191
198
  websocket-extensions (0.1.5)
192
- zeitwerk (2.6.7)
199
+ zeitwerk (2.6.11)
193
200
 
194
201
  PLATFORMS
195
202
  arm64-darwin-22
@@ -201,8 +208,8 @@ DEPENDENCIES
201
208
  phlex-testing-nokogiri
202
209
  phlexible!
203
210
  rake (~> 13.0)
204
- rubocop (~> 1.21)
205
- sus (~> 0.20.0)
211
+ rubocop (~> 1.55)
212
+ sus
206
213
 
207
214
  BUNDLED WITH
208
215
  2.4.1
data/README.md CHANGED
@@ -38,8 +38,7 @@ end
38
38
 
39
39
  #### `ControllerAttributes`
40
40
 
41
- Include this module in your Phlex views to get access to the controller's instance variables. It
42
- provides an explicit interface for accessing controller instance variables from the view.
41
+ 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 the view.
43
42
 
44
43
  ```ruby
45
44
  class Views::Users::Index < Views::Base
@@ -64,9 +63,7 @@ controller_attribute :users, attr_reader: true, alias: :my_users
64
63
 
65
64
  #### `Responder`
66
65
 
67
- If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to
68
- support implicit rendering similar to `ActionController::ImplicitRender` above. It will render the
69
- Phlex view using `respond_with` if one exists, and fall back to default rendering.
66
+ If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to support implicit rendering similar to `ActionController::ImplicitRender` above. It will render the Phlex view using `respond_with` if one exists, and fall back to default rendering.
70
67
 
71
68
  Just include it in your ApplicationResponder:
72
69
 
@@ -91,20 +88,15 @@ class UsersController < ApplicationController
91
88
  end
92
89
  ```
93
90
 
94
- This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include
95
- that in your `ApplicationController`.
91
+ This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include that in your `ApplicationController`.
96
92
 
97
- If you use `ControllerAttributes` in your view, and define a `resource` attribute, the responder
98
- will pass that to your view.
93
+ If you use `ControllerAttributes` in your view, and define a `resource` attribute, the responder will pass that to your view.
99
94
 
100
95
  #### `AElement`
101
96
 
102
- No need to call Rails `link_to` helper, when you can simply render an anchor tag directly with
103
- Phlex. But unfortunately that means you lose some of the magic that `link_to` provides. Especially
104
- the automatic resolution of URL's and Rails routes.
97
+ 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.
105
98
 
106
- The `Phlexible::Rails::AElement` module passes through the `href` attribute to Rails `url_for`
107
- helper. So you can do this:
99
+ The `Phlexible::Rails::AElement` module passes through the `href` attribute to Rails `url_for` helper. So you can do this:
108
100
 
109
101
  ```ruby
110
102
  Rails.application.routes.draw do
@@ -126,8 +118,7 @@ end
126
118
 
127
119
  Generates a form containing a single button that submits to the URL created by the set of options.
128
120
 
129
- It is similar to Rails `button_to` helper, which accepts the URL or route helper as the first
130
- argument, and the value/content of the button as the block.
121
+ It is similar to Rails `button_to` helper, which accepts the URL or route helper as the first argument, and the value/content of the button as the block.
131
122
 
132
123
  ```ruby
133
124
  Phlexible::Rails::ButtonTo.new(:root) { 'My Button' }
@@ -135,8 +126,7 @@ Phlexible::Rails::ButtonTo.new(:root) { 'My Button' }
135
126
 
136
127
  The url argument accepts the same options as Rails `url_for`.
137
128
 
138
- The form submits a POST request by default. You can specify a different HTTP verb via the :method
139
- option.
129
+ The form submits a POST request by default. You can specify a different HTTP verb via the :method option.
140
130
 
141
131
  ```ruby
142
132
  Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
@@ -144,11 +134,11 @@ Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
144
134
 
145
135
  ##### Options
146
136
 
147
- - `:class` - Specify the HTML class name of the button (not the form).
137
+ - `:class` - Specify the HTML class name of the button (not the form).
148
138
  - `:form_class` - Specify the HTML class name of the form (default: 'button_to').
149
- - `:data` - This option can be used to add custom data attributes.
150
- - `:method` - Symbol of the HTTP verb. Supported verbs are :post (default), :get, :delete, :patch,
151
- and :put.
139
+ - `:data` - This option can be used to add custom data attributes.
140
+ - `:params` - Hash of parameters to be rendered as hidden fields within the form.
141
+ - `:method` - Symbol of the HTTP verb. Supported verbs are :post (default), :get, :delete, :patch, and :put.
152
142
 
153
143
  ### `AliasView`
154
144
 
@@ -184,9 +174,7 @@ end
184
174
 
185
175
  ### PageTitle
186
176
 
187
- Helper to assist in defining page titles within Phlex views. Also includes support for nested views,
188
- where each desendent view class will have its title prepended to the page title. Simply assign the
189
- title to the `page_title` class variable:
177
+ 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 assign the title to the `page_title` class variable:
190
178
 
191
179
  ```ruby
192
180
  class MyView
@@ -204,7 +192,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
204
192
 
205
193
  ## Contributing
206
194
 
207
- Bug reports and pull requests are welcome on GitHub at https://github.com/joelmoss/phlexible. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joelmoss/phlexible/blob/master/CODE_OF_CONDUCT.md).
195
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/joelmoss/phlexible>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joelmoss/phlexible/blob/master/CODE_OF_CONDUCT.md).
208
196
 
209
197
  ## License
210
198
 
data/config/sus.rb CHANGED
@@ -5,4 +5,4 @@ require 'bundler'
5
5
 
6
6
  Bundler.require :test
7
7
 
8
- require_relative './view_helper'
8
+ require_relative 'view_helper'
@@ -6,7 +6,7 @@
6
6
  # def index
7
7
  # render Views::Users::Index.new
8
8
  # end
9
-
9
+ #
10
10
  # def show
11
11
  # render Views::Users::Show.new(user)
12
12
  # end
@@ -30,6 +30,8 @@ module Phlexible
30
30
  pview.tap do |view|
31
31
  if view.respond_to?(:__controller_attributes__)
32
32
  view.__controller_attributes__.each do |attr|
33
+ raise ControllerAttributes::UndefinedVariable, attr unless view_assigns.key?(attr.to_s)
34
+
33
35
  view.instance_variable_set :"@#{attr}", view_assigns[attr.to_s]
34
36
  end
35
37
  end
@@ -5,11 +5,18 @@
5
5
  #
6
6
  # The form submits a POST request by default. You can specify a different HTTP verb via the :method
7
7
  # option.
8
+ #
9
+ # Additional arguments are passed through to the button element, with a few exceptions:
10
+ # - :method - Symbol of HTTP verb. Supported verbs are :post, :get, :delete, :patch, and :put. By
11
+ # default it will be :post.
12
+ # - :form_class - This controls the class of the form within which the submit button will be
13
+ # placed. By default it will be 'button_to'.
14
+ # - :params - Hash of parameters to be rendered as hidden fields within the form.
8
15
  module Phlexible
9
16
  module Rails
10
17
  module ButtonToConcerns
11
18
  BUTTON_TAG_METHOD_VERBS = %w[patch put delete].freeze
12
- DEFAULT_OPTIONS = { method: 'post', form_class: 'button_to' }.freeze
19
+ DEFAULT_OPTIONS = { method: 'post', form_class: 'button_to', params: {} }.freeze
13
20
 
14
21
  def initialize(url, options = nil)
15
22
  @url = url
@@ -27,6 +34,7 @@ module Phlexible
27
34
  form action: action, class: @options.delete(:form_class), method: form_method do
28
35
  method_tag method
29
36
  form_method == 'post' && token_input(action, method.empty? ? 'post' : method)
37
+ param_inputs
30
38
 
31
39
  block_given? ? button(**button_attrs, &block) : button(**button_attrs) { @name }
32
40
  end
@@ -66,6 +74,52 @@ module Phlexible
66
74
 
67
75
  input type: 'hidden', name: '_method', value: method.to_s, autocomplete: 'off'
68
76
  end
77
+
78
+ def param_inputs
79
+ return unless (params = @options.delete(:params))
80
+
81
+ to_form_params(params).each do |param|
82
+ input type: 'hidden', name: param[:name], value: param[:value], autocomplete: 'off'
83
+ end
84
+ end
85
+
86
+ # Returns an array of hashes each containing :name and :value keys
87
+ # suitable for use as the names and values of form input fields:
88
+ #
89
+ # to_form_params(name: 'David', nationality: 'Danish')
90
+ # # => [{name: 'name', value: 'David'}, {name: 'nationality', value: 'Danish'}]
91
+ #
92
+ # to_form_params(country: { name: 'Denmark' })
93
+ # # => [{name: 'country[name]', value: 'Denmark'}]
94
+ #
95
+ # to_form_params(countries: ['Denmark', 'Sweden']})
96
+ # # => [{name: 'countries[]', value: 'Denmark'}, {name: 'countries[]', value: 'Sweden'}]
97
+ #
98
+ # An optional namespace can be passed to enclose key names:
99
+ #
100
+ # to_form_params({ name: 'Denmark' }, 'country')
101
+ # # => [{name: 'country[name]', value: 'Denmark'}]
102
+ def to_form_params(attribute, namespace = nil)
103
+ attribute = attribute.to_h if attribute.respond_to?(:permitted?)
104
+
105
+ params = []
106
+ case attribute
107
+ when Hash
108
+ attribute.each do |key, value|
109
+ prefix = namespace ? "#{namespace}[#{key}]" : key
110
+ params.push(*to_form_params(value, prefix))
111
+ end
112
+ when Array
113
+ array_prefix = "#{namespace}[]"
114
+ attribute.each do |value|
115
+ params.push(*to_form_params(value, array_prefix))
116
+ end
117
+ else
118
+ params << { name: namespace.to_s, value: attribute.to_param }
119
+ end
120
+
121
+ params.sort_by { |pair| pair[:name] }
122
+ end
69
123
  end
70
124
 
71
125
  class ButtonTo < Phlex::HTML
@@ -18,11 +18,21 @@
18
18
  # - `attr_reader:` - If set to `true`, an `attr_reader` will be defined for the given attributes.
19
19
  # - `alias:` - If set, the given attribute will be aliased to the given alias value.
20
20
  #
21
+ # NOTE: Phlexible::Rails::ActionController::ImplicitRender is required for this to work.
22
+ #
21
23
  module Phlexible
22
24
  module Rails
23
25
  module ControllerAttributes
24
26
  extend ActiveSupport::Concern
25
27
 
28
+ class UndefinedVariable < NameError
29
+ def initialize(name)
30
+ @variable_name = name
31
+ super "Attempted to expose controller attribute `#{@variable_name}`, but instance " \
32
+ 'variable is not defined in the controller.'
33
+ end
34
+ end
35
+
26
36
  included do
27
37
  class_attribute :__controller_attributes__, instance_predicate: false, default: Set.new
28
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlexible
4
- VERSION = '0.4.2'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-24 00:00:00.000000000 Z
11
+ date: 2023-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.4.13
101
+ rubygems_version: 3.4.17
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: A bunch of helpers and goodies intended to make life with Phlex even easier!