phlexible 2.2.0 → 3.1.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 +4 -4
- data/.rubocop.yml +44 -12
- data/.ruby-version +1 -0
- data/Appraisals +25 -0
- data/README.md +85 -2
- data/Rakefile +4 -4
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/phlex1_rails7.gemfile +24 -0
- data/gemfiles/phlex1_rails7.gemfile.lock +464 -0
- data/gemfiles/phlex1_rails8.gemfile +24 -0
- data/gemfiles/phlex1_rails8.gemfile.lock +463 -0
- data/gemfiles/phlex2_rails7.gemfile +24 -0
- data/gemfiles/phlex2_rails7.gemfile.lock +471 -0
- data/gemfiles/phlex2_rails8.gemfile +24 -0
- data/gemfiles/phlex2_rails8.gemfile.lock +470 -0
- data/lib/phlexible/page_title.rb +13 -13
- data/lib/phlexible/process_attributes.rb +56 -0
- data/lib/phlexible/rails/a_element.rb +7 -1
- data/lib/phlexible/rails/action_controller/implicit_render.rb +15 -7
- data/lib/phlexible/rails/button_to.rb +0 -113
- data/lib/phlexible/rails/button_to_concerns.rb +141 -0
- data/lib/phlexible/rails/controller_variables.rb +52 -46
- data/lib/phlexible/rails/meta_tags_component.rb +3 -1
- data/lib/phlexible/rails/view_assigns.rb +17 -0
- data/lib/phlexible/version.rb +1 -1
- data/lib/phlexible.rb +6 -5
- metadata +58 -27
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -169
- data/config/sus.rb +0 -8
- data/config/view_helper.rb +0 -16
- data/fixtures/dummy/app/controllers/articles_controller.rb +0 -4
- data/fixtures/dummy/app/views/articles/index.html.erb +0 -1
- data/fixtures/dummy/app/views/articles/link.rb +0 -9
- data/fixtures/dummy/app/views/articles/show.rb +0 -7
- data/fixtures/dummy/config/database.yml +0 -3
- data/fixtures/dummy/config/routes.rb +0 -5
- data/fixtures/dummy/config/storage.yml +0 -3
- data/fixtures/dummy/db/schema.rb +0 -6
- data/fixtures/dummy/log/.gitignore +0 -1
- data/fixtures/dummy/public/favicon.ico +0 -0
- data/fixtures/rails_helper.rb +0 -10
- data/lib/phlexible/rails.rb +0 -20
- data/phlexible.gemspec +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4d390495147c1fddfdf6eb14e2297dbb7d93526f4cfc3887d0833067950f893a
|
|
4
|
+
data.tar.gz: 1cd7d1fca0f0bb57f9e0fa9c5f066dc6749f42f4ebe0fd0f31c54f2c4984b044
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e768da8e19b5b62e373859bca93d5b46c70ffe888208983a358cb59148ef3d0d37ecdf550c9281075a1715b87ec1226be6d25c621d8603acff2636fdd5339deb
|
|
7
|
+
data.tar.gz: 06260c6309159d5536dbd7cd8c7515ab285e3f1ff37e8e991a8a4112165f9b1d1dc95ebbaa0aa4a41a0378a7fc2c3704a6601a8e3f5ab5ad2538c92827bbc4bf
|
data/.rubocop.yml
CHANGED
|
@@ -1,22 +1,54 @@
|
|
|
1
|
+
plugins:
|
|
2
|
+
- rubocop-rails
|
|
3
|
+
- rubocop-minitest
|
|
4
|
+
- rubocop-disable_syntax
|
|
5
|
+
- rubocop-packaging
|
|
6
|
+
- rubocop-rake
|
|
7
|
+
- rubocop-performance
|
|
8
|
+
|
|
1
9
|
AllCops:
|
|
2
|
-
TargetRubyVersion: 3.3
|
|
3
|
-
SuggestExtensions: false
|
|
10
|
+
TargetRubyVersion: 3.3
|
|
4
11
|
NewCops: enable
|
|
12
|
+
SuggestExtensions: false
|
|
13
|
+
Exclude:
|
|
14
|
+
- "gemfiles/**/*"
|
|
15
|
+
|
|
16
|
+
Naming/FileName:
|
|
17
|
+
Exclude:
|
|
18
|
+
- "lib/proscenium-phlex.rb"
|
|
19
|
+
|
|
20
|
+
Layout/LineLength:
|
|
21
|
+
Max: 100
|
|
22
|
+
Layout/IndentationConsistency:
|
|
23
|
+
EnforcedStyle: indented_internal_methods
|
|
5
24
|
|
|
6
25
|
Lint/ConstantDefinitionInBlock:
|
|
7
26
|
Exclude:
|
|
8
|
-
- test/**/*
|
|
27
|
+
- "test/**/*"
|
|
28
|
+
Lint/ItWithoutArgumentsInBlock:
|
|
29
|
+
Enabled: false
|
|
30
|
+
Lint/MissingSuper:
|
|
31
|
+
Enabled: false
|
|
9
32
|
|
|
33
|
+
Metrics:
|
|
34
|
+
Enabled: false
|
|
35
|
+
|
|
36
|
+
Style/DisableSyntax:
|
|
37
|
+
DisableSyntax:
|
|
38
|
+
- unless
|
|
39
|
+
- and_or_not
|
|
40
|
+
- numbered_parameters
|
|
41
|
+
|
|
42
|
+
Style/CaseEquality:
|
|
43
|
+
Enabled: false
|
|
10
44
|
Style/Documentation:
|
|
11
45
|
Enabled: false
|
|
12
46
|
Style/ClassAndModuleChildren:
|
|
13
|
-
|
|
14
|
-
|
|
47
|
+
Enabled: false
|
|
48
|
+
Style/NegatedIf:
|
|
49
|
+
Enabled: false
|
|
15
50
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Max: 20
|
|
21
|
-
Metrics/CyclomaticComplexity:
|
|
22
|
-
Max: 8
|
|
51
|
+
Minitest/EmptyLineBeforeAssertionMethods:
|
|
52
|
+
Enabled: false
|
|
53
|
+
Minitest/MultipleAssertions:
|
|
54
|
+
Enabled: false
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.3.8
|
data/Appraisals
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
appraise 'phlex1/rails7' do
|
|
4
|
+
gem 'phlex', '~> 1.11.0'
|
|
5
|
+
gem 'phlex-rails', '~> 1.2.1'
|
|
6
|
+
gem 'rails', '~> 7.2.0'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
appraise 'phlex1/rails8' do
|
|
10
|
+
gem 'phlex', '~> 1.11.0'
|
|
11
|
+
gem 'phlex-rails', '~> 1.2.1'
|
|
12
|
+
gem 'rails', '>= 8.0.0'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
appraise 'phlex2/rails7' do
|
|
16
|
+
gem 'phlex', '>= 2.1.0', '< 3.0.0'
|
|
17
|
+
gem 'phlex-rails', '>= 2.1.0', '< 3.0.0'
|
|
18
|
+
gem 'rails', '~> 7.2.0'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
appraise 'phlex2/rails8' do
|
|
22
|
+
gem 'phlex', '>= 2.1.0', '< 3.0.0'
|
|
23
|
+
gem 'phlex-rails', '>= 2.1.0', '< 3.0.0'
|
|
24
|
+
gem 'rails', '>= 8.0.0'
|
|
25
|
+
end
|
data/README.md
CHANGED
|
@@ -36,6 +36,26 @@ class UsersController
|
|
|
36
36
|
end
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
##### View Resolution
|
|
40
|
+
|
|
41
|
+
By default, views are resolved using the `phlex_view_path` method, which constructs a path based on the controller and action name. For example, `UsersController#index` will look for `Users::IndexView`.
|
|
42
|
+
|
|
43
|
+
You can customize this behavior by overriding `phlex_view_path` in your controller:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
class UsersController
|
|
47
|
+
include Phlexible::Rails::ActionController::ImplicitRender
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def phlex_view_path(action_name)
|
|
52
|
+
"views/#{controller_path}/#{action_name}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This would resolve `UsersController#index` to `Views::Users::Index` instead.
|
|
58
|
+
|
|
39
59
|
#### `Callbacks`
|
|
40
60
|
|
|
41
61
|
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.
|
|
@@ -251,7 +271,7 @@ end
|
|
|
251
271
|
|
|
252
272
|
### PageTitle
|
|
253
273
|
|
|
254
|
-
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:
|
|
274
|
+
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:
|
|
255
275
|
|
|
256
276
|
```ruby
|
|
257
277
|
class MyView
|
|
@@ -261,9 +281,72 @@ end
|
|
|
261
281
|
|
|
262
282
|
Then call the `page_title` method in the `<head>` of your page.
|
|
263
283
|
|
|
284
|
+
### `ProcessAttributes`
|
|
285
|
+
|
|
286
|
+
> This functionality is already built in to **Phlex >= 1**. This module is only needed for **Phlex >= 2**.
|
|
287
|
+
|
|
288
|
+
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.
|
|
289
|
+
|
|
290
|
+
Extend your view class with `Phlexible::ProcessAttributes` and define a `process_attributes` instance method that receives the attributes hash and returns the modified hash.
|
|
291
|
+
|
|
292
|
+
```ruby
|
|
293
|
+
class MyView < Phlex::HTML
|
|
294
|
+
extend Phlexible::ProcessAttributes
|
|
295
|
+
|
|
296
|
+
def process_attributes(attrs)
|
|
297
|
+
# Add a default class to all elements
|
|
298
|
+
attrs[:class] ||= 'my-default-class'
|
|
299
|
+
attrs
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
def view_template
|
|
303
|
+
div(id: 'container') { 'Hello' }
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
This will output:
|
|
309
|
+
|
|
310
|
+
```html
|
|
311
|
+
<div id="container" class="my-default-class">Hello</div>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
The `process_attributes` method is called for all standard HTML elements and void elements, as well as any custom elements registered with `register_element`.
|
|
315
|
+
|
|
316
|
+
```ruby
|
|
317
|
+
class MyView < Phlex::HTML
|
|
318
|
+
extend Phlexible::ProcessAttributes
|
|
319
|
+
|
|
320
|
+
register_element :my_custom_element
|
|
321
|
+
|
|
322
|
+
def process_attributes(attrs)
|
|
323
|
+
attrs[:data_processed] = true
|
|
324
|
+
attrs
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def view_template
|
|
328
|
+
my_custom_element(name: 'test') { 'Custom content' }
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
```
|
|
332
|
+
|
|
264
333
|
## Development
|
|
265
334
|
|
|
266
|
-
After checking out the repo,
|
|
335
|
+
After checking out the repo, install dependencies with:
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
bin/setup
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
This gem supports varios major Phlex versions, as defined in the `Appraisal` file.
|
|
342
|
+
|
|
343
|
+
To run tests for all supported Phlex versions:
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
bundle exec appraisal rails t
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
To run tests for a specific Phlex versions, call:
|
|
267
350
|
|
|
268
351
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
269
352
|
|
data/Rakefile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'bundler/
|
|
4
|
-
require 'rubocop/rake_task'
|
|
3
|
+
require 'bundler/setup'
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
|
6
|
+
load 'rails/tasks/engine.rake'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
require 'bundler/gem_tasks'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "amazing_print"
|
|
6
|
+
gem "appraisal"
|
|
7
|
+
gem "debug"
|
|
8
|
+
gem "rubocop-disable_syntax", require: false
|
|
9
|
+
gem "rubocop-minitest", require: false
|
|
10
|
+
gem "rubocop-packaging", require: false
|
|
11
|
+
gem "rubocop-performance", require: false
|
|
12
|
+
gem "rubocop-rails", require: false
|
|
13
|
+
gem "rubocop-rake", require: false
|
|
14
|
+
gem "capybara"
|
|
15
|
+
gem "maxitest"
|
|
16
|
+
gem "minitest", "~> 5.0"
|
|
17
|
+
gem "minitest-difftastic"
|
|
18
|
+
gem "minitest-focus"
|
|
19
|
+
gem "minitest-spec-rails"
|
|
20
|
+
gem "phlex", "~> 1.11.0"
|
|
21
|
+
gem "phlex-rails", "~> 1.2.1"
|
|
22
|
+
gem "rails", "~> 7.2.0"
|
|
23
|
+
|
|
24
|
+
gemspec path: "../"
|