phlexible 3.0.0 → 3.1.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +42 -8
  3. data/.ruby-version +1 -1
  4. data/Appraisals +18 -4
  5. data/README.md +71 -7
  6. data/Rakefile +4 -4
  7. data/gemfiles/phlex1_rails7.gemfile +24 -0
  8. data/gemfiles/phlex1_rails7.gemfile.lock +464 -0
  9. data/gemfiles/phlex1_rails8.gemfile +24 -0
  10. data/gemfiles/phlex1_rails8.gemfile.lock +463 -0
  11. data/gemfiles/phlex2_rails7.gemfile +24 -0
  12. data/gemfiles/phlex2_rails7.gemfile.lock +471 -0
  13. data/gemfiles/phlex2_rails8.gemfile +24 -0
  14. data/gemfiles/phlex2_rails8.gemfile.lock +470 -0
  15. data/lib/phlexible/page_title.rb +13 -13
  16. data/lib/phlexible/process_attributes.rb +58 -0
  17. data/lib/phlexible/rails/action_controller/implicit_render.rb +15 -7
  18. data/lib/phlexible/rails/button_to_concerns.rb +71 -70
  19. data/lib/phlexible/rails/controller_variables.rb +52 -49
  20. data/lib/phlexible/version.rb +1 -1
  21. metadata +13 -27
  22. data/Gemfile +0 -13
  23. data/Gemfile.lock +0 -257
  24. data/config/render_helper.rb +0 -27
  25. data/config/sus.rb +0 -8
  26. data/fixtures/dummy/app/controllers/articles_controller.rb +0 -4
  27. data/fixtures/dummy/app/views/articles/index.html.erb +0 -1
  28. data/fixtures/dummy/app/views/articles/link.rb +0 -9
  29. data/fixtures/dummy/app/views/articles/show.rb +0 -7
  30. data/fixtures/dummy/config/database.yml +0 -3
  31. data/fixtures/dummy/config/routes.rb +0 -5
  32. data/fixtures/dummy/config/storage.yml +0 -3
  33. data/fixtures/dummy/db/schema.rb +0 -6
  34. data/fixtures/dummy/log/.gitignore +0 -1
  35. data/fixtures/dummy/public/favicon.ico +0 -0
  36. data/fixtures/rails_helper.rb +0 -11
  37. data/gemfiles/phlex_1.gemfile +0 -14
  38. data/gemfiles/phlex_1.gemfile.lock +0 -253
  39. data/gemfiles/phlex_2.gemfile +0 -14
  40. data/gemfiles/phlex_2.gemfile.lock +0 -254
  41. data/phlexible.gemspec +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af9a39dba0e25b8381fc0f513111e488e27e6fa6d31d3d41ec7d7b7d4aa07cd1
4
- data.tar.gz: b1e271a6e412e7e05aabed4b8c4f3a35157a04c6a7e0723ee70b9414beb65565
3
+ metadata.gz: 335d7a198a6dd2e58d52abe064552a739cfd77c9910f294022bd4a96adf4ef92
4
+ data.tar.gz: ee505e0e79afba25172584437407b99bc9ab52609d0d7c02cf2e29edc91ac20f
5
5
  SHA512:
6
- metadata.gz: 27635a6f6135a15af61920b630269372199777701ec92b216f6e7309880fd46d93705890ef8545fb7d47101d295ad0744406cc1cd9beddfdf81fe03c3b849f71
7
- data.tar.gz: c22b9d2d997f94ee86ee3c3c854ec631e2864f549c76d3ffc10138de0df0e2eeafbb2c7c5d9f6e15f2cea4fa1bb1a2982ed38e784878f433edef563f1d6bf8f6
6
+ metadata.gz: 58bd0f6dba980c3328127363960d501e9abbc2e84543b3264d418eb30a5e0a3fad8e25a7fa5a1f9a2b3aaa2b4f0e2bc4057813cdc963a63c7c276611052e6502
7
+ data.tar.gz: 7c082ee6bdfc6ae5f46f680d872b16e6d125dadfd94771b7da5d87151655a4405faf4c5616ae4bb5d56277a3df8dcfa45cfd928b7b0d97f678bcf2543d65f84d
data/.rubocop.yml CHANGED
@@ -1,20 +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.0
3
- SuggestExtensions: false
10
+ TargetRubyVersion: 3.3
4
11
  NewCops: enable
12
+ SuggestExtensions: false
13
+ Exclude:
14
+ - "gemfiles/**/*"
15
+
16
+ Naming/FileName:
5
17
  Exclude:
6
- - "vendor/**/*"
7
- - gemfiles/**/*
18
+ - "lib/proscenium-phlex.rb"
19
+
20
+ Layout/LineLength:
21
+ Max: 100
22
+ Layout/IndentationConsistency:
23
+ EnforcedStyle: indented_internal_methods
8
24
 
9
25
  Lint/ConstantDefinitionInBlock:
10
26
  Exclude:
11
- - test/**/*
27
+ - "test/**/*"
28
+ Lint/ItWithoutArgumentsInBlock:
29
+ Enabled: false
30
+ Lint/MissingSuper:
31
+ Enabled: false
32
+
33
+ Metrics:
34
+ Enabled: false
35
+
36
+ Style/DisableSyntax:
37
+ DisableSyntax:
38
+ - unless
39
+ - and_or_not
40
+ - numbered_parameters
12
41
 
42
+ Style/CaseEquality:
43
+ Enabled: false
13
44
  Style/Documentation:
14
45
  Enabled: false
15
46
  Style/ClassAndModuleChildren:
16
- Exclude:
17
- - fixtures/**/*
47
+ Enabled: false
48
+ Style/NegatedIf:
49
+ Enabled: false
18
50
 
19
- Metrics:
51
+ Minitest/EmptyLineBeforeAssertionMethods:
52
+ Enabled: false
53
+ Minitest/MultipleAssertions:
20
54
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.6
1
+ 3.3.8
data/Appraisals CHANGED
@@ -1,11 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'phlex-1' do
4
- gem 'phlex', '>= 1.10.0', '< 2.0.0'
5
- gem 'phlex-rails', '>= 1.2.1', '< 2.0.0'
3
+ appraise 'phlex1/rails7' do
4
+ gem 'phlex', '~> 1.11.0'
5
+ gem 'phlex-rails', '~> 1.2.1'
6
+ gem 'rails', '~> 7.2.0'
6
7
  end
7
8
 
8
- appraise 'phlex-2' do
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
9
22
  gem 'phlex', '>= 2.1.0', '< 3.0.0'
10
23
  gem 'phlex-rails', '>= 2.1.0', '< 3.0.0'
24
+ gem 'rails', '>= 8.0.0'
11
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,6 +281,55 @@ 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
335
  After checking out the repo, install dependencies with:
@@ -274,16 +343,11 @@ This gem supports varios major Phlex versions, as defined in the `Appraisal` fil
274
343
  To run tests for all supported Phlex versions:
275
344
 
276
345
  ```
277
- bundle exec appraisal sus
346
+ bundle exec appraisal rails t
278
347
  ```
279
348
 
280
349
  To run tests for a specific Phlex versions, call:
281
350
 
282
- ```bash
283
- bundle exec appraisal phlex-1 sus
284
- bundle exec appraisal phlex-2 sus
285
- ```
286
-
287
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).
288
352
 
289
353
  ## Contributing
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rubocop/rake_task'
3
+ require 'bundler/setup'
5
4
 
6
- RuboCop::RakeTask.new
5
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
7
7
 
8
- task default: :rubocop
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: "../"