lifeform 0.7 → 0.8.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: 0bd913233e25c58ae11c6e356383384f4fd995a35a530f62525524abbb3902f2
4
- data.tar.gz: a9cbb5ec298a1e291486fe993f14c69a6aff0ef35baf1ec061d9e9bc93e87b78
3
+ metadata.gz: 84cc7c165874ab122f164fe3edae5c7e7f68d7ba4936f115151f5fec3ecdd217
4
+ data.tar.gz: 690ab60f63f813cfedf830416d1fe3761ad4dfd090344dc227e598e62c5bb497
5
5
  SHA512:
6
- metadata.gz: 144a5f5b14116f6471acd45c66fb369119d2256a6da724a83df428819d694d3ff017f539c0a2fd7b0ff9f94237d57216116efdd60aac8524e11b3fdb93f801b2
7
- data.tar.gz: 892413ee58661eb72851f2fbd0ffc1b4a831cbab406eac8f61d17a03ced7c06e59c5b5716659d5e0df5b90c15ab65569e2819fbf3ccd3be30dcf0a2607a09751
6
+ metadata.gz: aec711376fecf90651b305a8a8f3a7044dcbdb022a4c17713e0433f8e90590f9502668794143183bc0c71d8d3a0de1dbe85cc3e989b764552190367234a10bed
7
+ data.tar.gz: f057b69cbf5d7f43f5cba4a30f79df5d0f3735af41fb363bf7147853d327b07315e730708c8feaae2063993a477ee39c9e9d22f0f1385f4c3c9991d9360a4a98
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifeform (0.7)
4
+ lifeform (0.8.0)
5
5
  activesupport (>= 6.0)
6
6
  phlex (~> 0.3)
7
7
  zeitwerk (~> 2.5)
@@ -43,7 +43,7 @@ GEM
43
43
  parallel (1.22.1)
44
44
  parser (3.1.2.1)
45
45
  ast (~> 2.4.1)
46
- phlex (0.3.1)
46
+ phlex (0.3.2)
47
47
  syntax_tree (~> 3.6)
48
48
  zeitwerk (~> 2.6)
49
49
  prettier_print (0.1.0)
@@ -89,7 +89,7 @@ GEM
89
89
  thor (~> 1.0)
90
90
  tilt (~> 2.0)
91
91
  yard (~> 0.9, >= 0.9.24)
92
- syntax_tree (3.6.1)
92
+ syntax_tree (3.6.2)
93
93
  prettier_print
94
94
  thor (1.2.1)
95
95
  tilt (2.0.11)
@@ -99,7 +99,7 @@ GEM
99
99
  webrick (1.7.0)
100
100
  yard (0.9.28)
101
101
  webrick (~> 1.7.0)
102
- zeitwerk (2.6.0)
102
+ zeitwerk (2.6.1)
103
103
 
104
104
  PLATFORMS
105
105
  arm64-darwin-21
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lifeform
2
2
 
3
- Component-centric form object rendering for Ruby.
3
+ Component-centric form object rendering for Ruby. Powered by [Phlex](https://www.phlex.fun)
4
4
 
5
5
  ## Installation
6
6
 
@@ -28,13 +28,25 @@ end
28
28
  And a template rendering of:
29
29
 
30
30
  ```erb
31
- <%= render TestForm.new(url: "/path") do %>
31
+ <!-- ERB -->
32
+ <%= render TestForm.new(url: "/path") do |f| %>
32
33
  <%= render f.field(:occupation) %>
33
34
  <%= render f.field(:age, value: 47) %>
34
35
  <%= render f.field(:submit) %>
35
36
  <% end %>
36
37
  ```
37
38
 
39
+ ```rb
40
+ # Or Phlex:
41
+ def template
42
+ render TestForm.new(url: "/path") do |f|
43
+ render f.field(:occupation)
44
+ render f.field(:age, value: 47)
45
+ render f.field(:submit)
46
+ end
47
+ end
48
+ ```
49
+
38
50
  You get the following HTML output:
39
51
 
40
52
  ```html
data/lib/lifeform/form.rb CHANGED
@@ -86,6 +86,16 @@ module Lifeform
86
86
  model.class.name.underscore.tr("/", "_")
87
87
  end
88
88
  end
89
+
90
+ # @return [Array<Symbol>]
91
+ def param_keys
92
+ fields.keys
93
+ end
94
+
95
+ # @return [Array<String>]
96
+ def param_string_keys
97
+ fields.keys.map(&:to_s)
98
+ end
89
99
  end
90
100
 
91
101
  # @return [Object]
@@ -114,7 +124,7 @@ module Lifeform
114
124
  @library = Libraries.const_get(@library_name.to_s.classify)
115
125
  @subform_instances = {}
116
126
 
117
- parameters[:method] ||= model.respond_to?(:persisted?) && model.persisted? ? :patch : :post
127
+ @method = parameters[:method] ||= model.respond_to?(:persisted?) && model.persisted? ? :patch : :post
118
128
  parameters[:accept_charset] ||= "UTF-8"
119
129
  verify_method
120
130
  end
@@ -142,7 +152,7 @@ module Lifeform
142
152
  method: parameters[:method].to_s.downcase
143
153
  })
144
154
  elsif helpers.respond_to?(:csrf_tag, true) # Roda
145
- helpers.send(:csrf_tag, action: parameters[:action].to_s, method: parameters[:method].to_s)
155
+ helpers.send(:csrf_tag, parameters[:action].to_s, @method.to_s)
146
156
  else
147
157
  raise Lifeform::Error, "Missing token tag helper. Override `add_authenticity_token' in your Form object"
148
158
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lifeform
4
- VERSION = "0.7"
4
+ VERSION = "0.8.0"
5
5
  end
data/lib/lifeform.rb CHANGED
@@ -10,3 +10,12 @@ loader.setup
10
10
  module Lifeform
11
11
  class Error < StandardError; end
12
12
  end
13
+
14
+ if defined?(Bridgetown)
15
+ # Check compatibility
16
+ raise "The Lifeform support for Bridgetown requires v1.2 or newer" if Bridgetown::VERSION.to_f < 1.2
17
+
18
+ Bridgetown.initializer :lifeform do |config|
19
+ # no extra config at the moment
20
+ end
21
+ 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.7'
4
+ version: 0.8.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-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport