lifeform 0.10.0 → 0.11.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: fef99043fb289f536c1a3b6986a48675dc741854ffef6e99c596c5d9abca303a
4
- data.tar.gz: 61821150d087888c5b243e2c52916534f7fc8b4fb8a14ced79692d3bb1ed1f45
3
+ metadata.gz: 3f4e4bde45197eefcdc0b683d50f2f3474fc7ebdd5f270c8f00fb3e59443c50c
4
+ data.tar.gz: 40a91e75586e7335bb0322c13f0acb98de1eb7b83623f229aebb10a4f0a9f395
5
5
  SHA512:
6
- metadata.gz: 8b64f7550a79f0e7667ac422a9cecb364943c544e9583f724842326d4cb9b28b74ae0dee19427be1121fcfd4e9b1a9e5e7878ff1cc8a2e22ee65dd734a0c69e1
7
- data.tar.gz: adec1d8e7d8a800f667953ef4e91f90935878a9e1dc6095a82536625bf675ee9f1be74ee3ed31f1857807c9ee75dcd3b36f95a42c32ba79aa10cca0395240dc8
6
+ metadata.gz: e6e3a2dfe4a53d67c9cb9f902113e44721a0cc05c23ffb997c93af5363de15f9a265abf32e9a66da3157066004e9ebc371107857f04b6dee6e874df03385412e
7
+ data.tar.gz: a3881f17b6db8e0b33fff0ad609f8a2f0bf48cd276a5bb9cf06cbf4e55892308f2df5155c2cdd1649c30004680d9aea64d2a6a2ba98cd51a831c78d55f6257fa
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ require:
3
3
  - rubocop-rake
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.0
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - lib/lifeform/phlex_renderable.rb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.11.0] - 2023-06-22
6
+
7
+ - Upgrade to Phlex 1.7+, Ruby 3.0+
8
+ - Provide a form-wide configuration object
9
+ - Allow field definitions to be added via `fields` block (useful for when you need to reference runtime configuration)
10
+
5
11
  ## [0.10.0] - 2022-12-23
6
12
 
7
13
  - Support Phlex 1.0 and conditional `render_in` support for Bridgetown
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifeform (0.10.0)
5
- activesupport (>= 6.0)
6
- phlex (~> 1.0)
4
+ lifeform (0.11.0)
5
+ activesupport (>= 7.0)
6
+ phlex (>= 1.7)
7
7
  zeitwerk (~> 2.5)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.4)
12
+ activesupport (7.0.5)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
@@ -19,59 +19,65 @@ GEM
19
19
  backport (1.2.0)
20
20
  benchmark (0.2.1)
21
21
  builder (3.2.4)
22
- concurrent-ruby (1.1.10)
22
+ cgi (0.3.6)
23
+ concurrent-ruby (1.2.2)
23
24
  diff-lcs (1.5.0)
24
25
  e2mmap (0.1.0)
25
- i18n (1.12.0)
26
+ erb (4.0.2)
27
+ cgi (>= 0.3.3)
28
+ i18n (1.14.1)
26
29
  concurrent-ruby (~> 1.0)
27
- jaro_winkler (1.5.4)
30
+ jaro_winkler (1.5.6)
28
31
  json (2.6.3)
29
32
  kramdown (2.4.0)
30
33
  rexml
31
34
  kramdown-parser-gfm (1.1.0)
32
35
  kramdown (~> 2.0)
33
- minitest (5.16.3)
34
- minitest-reporters (1.5.0)
36
+ minitest (5.18.1)
37
+ minitest-reporters (1.6.0)
35
38
  ansi
36
39
  builder
37
40
  minitest (>= 5.0)
38
41
  ruby-progressbar
39
- nokogiri (1.13.10-arm64-darwin)
42
+ nokogiri (1.15.2-arm64-darwin)
40
43
  racc (~> 1.4)
41
- nokogiri (1.13.10-x86_64-linux)
44
+ nokogiri (1.15.2-x86_64-linux)
42
45
  racc (~> 1.4)
43
- parallel (1.22.1)
44
- parser (3.1.3.0)
46
+ parallel (1.23.0)
47
+ parser (3.2.2.3)
45
48
  ast (~> 2.4.1)
46
- phlex (1.0.0)
49
+ racc
50
+ phlex (1.8.1)
51
+ concurrent-ruby (~> 1.2)
52
+ erb (>= 4)
47
53
  zeitwerk (~> 2.6)
48
- racc (1.6.1)
54
+ racc (1.7.1)
49
55
  rails-dom-testing (2.0.3)
50
56
  activesupport (>= 4.2.0)
51
57
  nokogiri (>= 1.6)
52
58
  rainbow (3.1.1)
53
59
  rake (13.0.6)
54
- regexp_parser (2.6.1)
60
+ regexp_parser (2.8.1)
55
61
  reverse_markdown (2.1.1)
56
62
  nokogiri
57
63
  rexml (3.2.5)
58
- rubocop (1.40.0)
64
+ rubocop (1.52.1)
59
65
  json (~> 2.3)
60
66
  parallel (~> 1.10)
61
- parser (>= 3.1.2.1)
67
+ parser (>= 3.2.2.3)
62
68
  rainbow (>= 2.2.2, < 4.0)
63
69
  regexp_parser (>= 1.8, < 3.0)
64
70
  rexml (>= 3.2.5, < 4.0)
65
- rubocop-ast (>= 1.23.0, < 2.0)
71
+ rubocop-ast (>= 1.28.0, < 2.0)
66
72
  ruby-progressbar (~> 1.7)
67
- unicode-display_width (>= 1.4.0, < 3.0)
68
- rubocop-ast (1.24.0)
69
- parser (>= 3.1.1.0)
73
+ unicode-display_width (>= 2.4.0, < 3.0)
74
+ rubocop-ast (1.29.0)
75
+ parser (>= 3.2.1.0)
70
76
  rubocop-minitest (0.20.1)
71
77
  rubocop (>= 0.90, < 2.0)
72
78
  rubocop-rake (0.6.0)
73
79
  rubocop (~> 1.0)
74
- ruby-progressbar (1.11.0)
80
+ ruby-progressbar (1.13.0)
75
81
  solargraph (0.45.0)
76
82
  backport (~> 1.2)
77
83
  benchmark
@@ -87,15 +93,13 @@ GEM
87
93
  thor (~> 1.0)
88
94
  tilt (~> 2.0)
89
95
  yard (~> 0.9, >= 0.9.24)
90
- thor (1.2.1)
91
- tilt (2.0.11)
92
- tzinfo (2.0.5)
96
+ thor (1.2.2)
97
+ tilt (2.2.0)
98
+ tzinfo (2.0.6)
93
99
  concurrent-ruby (~> 1.0)
94
- unicode-display_width (2.3.0)
95
- webrick (1.7.0)
96
- yard (0.9.28)
97
- webrick (~> 1.7.0)
98
- zeitwerk (2.6.6)
100
+ unicode-display_width (2.4.2)
101
+ yard (0.9.34)
102
+ zeitwerk (2.6.8)
99
103
 
100
104
  PLATFORMS
101
105
  arm64-darwin-21
data/lib/lifeform/form.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/core_ext/string/inflections"
4
+ require "active_support/ordered_options"
4
5
 
5
6
  module Lifeform
6
7
  FieldDefinition = Struct.new(:type, :library, :parameters)
@@ -17,19 +18,27 @@ module Lifeform
17
18
  end
18
19
 
19
20
  # Helper to point to `I18n.t` method
20
- def t(...)
21
- I18n.t(...)
22
- end
21
+ def t(...) = I18n.t(...)
22
+
23
+ def configuration = @configuration ||= ActiveSupport::OrderedOptions.new
23
24
 
25
+ # @param block [Proc, nil]
24
26
  # @return [Hash<Symbol, FieldDefinition>]
25
- def fields
27
+ def fields(&block)
26
28
  @fields ||= {}
29
+ @fields_setup_block = block if block_given?
30
+
31
+ @fields
27
32
  end
28
33
 
29
- def subforms
30
- @subforms ||= {}
34
+ def initialize_field_definitions!
35
+ return unless @fields_setup_block
36
+
37
+ @fields_setup_block.(configuration)
31
38
  end
32
39
 
40
+ def subforms = @subforms ||= {}
41
+
33
42
  def field(name, type: :text, library: self.library, **parameters)
34
43
  parameters[:name] = name.to_sym
35
44
  fields[name] = FieldDefinition.new(type, Libraries.const_get(library.to_s.classify), parameters)
@@ -88,14 +97,10 @@ module Lifeform
88
97
  end
89
98
 
90
99
  # @return [Array<Symbol>]
91
- def param_keys
92
- fields.keys
93
- end
100
+ def param_keys = fields.keys
94
101
 
95
102
  # @return [Array<String>]
96
- def param_string_keys
97
- fields.keys.map(&:to_s)
98
- end
103
+ def param_string_keys = fields.keys.map(&:to_s)
99
104
  end
100
105
 
101
106
  # @return [Object]
@@ -124,6 +129,8 @@ module Lifeform
124
129
  @library = Libraries.const_get(@library_name.to_s.classify)
125
130
  @subform_instances = {}
126
131
 
132
+ self.class.initialize_field_definitions!
133
+
127
134
  @method = parameters[:method] ||= model.respond_to?(:persisted?) && model.persisted? ? :patch : :post
128
135
  parameters[:accept_charset] ||= "UTF-8"
129
136
  verify_method
@@ -191,8 +198,6 @@ module Lifeform
191
198
  end
192
199
  end
193
200
 
194
- def auto_render_fields
195
- self.class.fields.map { |k, _v| render(field(k)) }
196
- end
201
+ def auto_render_fields = self.class.fields.map { |k, _v| render(field(k)) }
197
202
  end
198
203
  end
@@ -40,9 +40,7 @@ module Lifeform
40
40
  form.parent_name ? "#{form.parent_name}[#{name_of_model}]" : name_of_model
41
41
  end
42
42
 
43
- def value_for_model
44
- @model.send(attributes[:name])
45
- end
43
+ def value_for_model = @model.send(attributes[:name])
46
44
 
47
45
  def handle_labels
48
46
  label_text = attributes[:label].to_s
@@ -62,9 +62,7 @@ module Lifeform
62
62
  end
63
63
  end
64
64
 
65
- def capture
66
- super.html_safe
67
- end
65
+ def capture = super.html_safe
68
66
 
69
67
  # Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
70
68
  def set_original_view_context(view_context)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lifeform
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.0"
5
5
  end
data/lifeform.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Component-centric form object rendering for Ruby"
12
12
  spec.homepage = "https://github.com/bridgetownrb/lifeform"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.7"
14
+ spec.required_ruby_version = ">= 3.0"
15
15
  spec.metadata["rubygems_mfa_required"] = "true"
16
16
 
17
17
  # Specify which files should be added to the gem when it is released.
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  # Uncomment to register a new dependency of your gem
27
- spec.add_dependency "activesupport", ">= 6.0"
28
- spec.add_dependency "phlex", "~> 1.0"
27
+ spec.add_dependency "activesupport", ">= 7.0"
28
+ spec.add_dependency "phlex", ">= 1.7"
29
29
  spec.add_dependency "zeitwerk", "~> 2.5"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifeform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-23 00:00:00.000000000 Z
11
+ date: 2023-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: phlex
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '1.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: zeitwerk
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: '2.7'
101
+ version: '3.0'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="