lifeform 0.3.0 → 0.4.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: 43833cf5f9112ae7e24d2f14e24f41629e7a728740ee768383c7072e9484eb69
4
- data.tar.gz: db8424032dc11a96dc91ac8bb653e317bca8215de44c15664fed68c8b91f97de
3
+ metadata.gz: 6f1e91a0e3977e9c1ee9bf2fadc00d427efa8f7fcf720ba0670905832e89e41c
4
+ data.tar.gz: 458c2edd232353260115c6eb794ebfcc7298696723e3ec5f49518ed8ccb68e19
5
5
  SHA512:
6
- metadata.gz: edd2ea3eabdad15d8dc27d2da4cf07b04bc0d00302761ecef5562a0dd999ffa5badf9f7c9eb53a322a309dee7d75cf1475aa952f1f1944cb5ff065517f0f0120
7
- data.tar.gz: 33fb2e8b4276da626de9736cd568a6c34be23cade8eed0a0672cb1e909b5b911aca8136334d61e07d5b04937b450b7126066dfa1ebfb7c46d8af719d518147ec
6
+ metadata.gz: f8c0c7b398b5375cc50f0fb9d59ad5f759dcd05cd355fba4ed8c24c6c1e3e11c2447d888592f0c2ccb799a596bdfc23902fd822bd397cbf731c2ef77f453effc
7
+ data.tar.gz: e96679b59c1abae814f740ba190659eb29a4bae5c1fcc8809bff3336b138b13aded6f87d5bf0a2522ec86de80f8c98c1586eb8fcb81986edd242093294c0d1b0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifeform (0.3.0)
4
+ lifeform (0.4.0)
5
5
  activesupport (>= 6.0)
6
6
  papercraft (~> 0.24)
7
7
  zeitwerk (~> 2.5)
data/README.md CHANGED
@@ -20,6 +20,8 @@ Given a form object of:
20
20
  class TestForm < Lifeform::Form
21
21
  field :occupation, label: "Your Job", id: "your-occupation", required: true
22
22
  field :age, library: :shoelace, label: "Your Age"
23
+
24
+ field :submit, type: :submit_button, label: "Save", class: "font-bold"
23
25
  end
24
26
  ```
25
27
 
@@ -29,6 +31,7 @@ And a template rendering of:
29
31
  <%= render TestForm.new(url: "/path") do %>
30
32
  <%= render f.field(:occupation) %>
31
33
  <%= render f.field(:age, value: 47) %>
34
+ <%= render f.field(:submit) %>
32
35
  <% end %>
33
36
  ```
34
37
 
@@ -44,6 +47,9 @@ You get the following HTML output:
44
47
  <form-field name="age">
45
48
  <sl-input type="text" label="Your Age" name="age" value="47" id="age"></sl-input>
46
49
  </form-field>
50
+ <form-button name="commit">
51
+ <button class="font-bold" name="commit" type="submit">Save</button>
52
+ </form-button>
47
53
  </form>
48
54
  ```
49
55
 
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lifeform
4
+ module Libraries
5
+ class Default
6
+ class Button
7
+ attr_reader :form, :field_definition, :attributes
8
+
9
+ WRAPPER_TAG = :form_button
10
+ BUTTON_TAG = :button
11
+
12
+ def initialize(form, field_definition, **attributes)
13
+ @form = form
14
+ @field_definition = field_definition
15
+ @attributes = Lifeform::Form.parameters_to_attributes(field_definition.parameters).merge(attributes)
16
+ @if = @attributes.delete(:if)
17
+ @label = @attributes.delete(:label) || "Unlabeled Button"
18
+ @attributes[:type] ||= :button
19
+ end
20
+
21
+ def render_in(view_context, &block)
22
+ @view_context = view_context
23
+ @content = block
24
+ return "" if !@if.nil? && !@if
25
+
26
+ template
27
+ end
28
+
29
+ def template # rubocop:disable Metrics/AbcSize
30
+ Papercraft.html do |wrapper_tag:, button_tag:, attributes:, field_data:|
31
+ field_body = proc {
32
+ send(button_tag, **attributes) do
33
+ emit field_data[:content] || field_data[:label]
34
+ end
35
+ }
36
+ next field_body.call unless wrapper_tag
37
+
38
+ send wrapper_tag, name: attributes[:name], &field_body
39
+ end.render(
40
+ wrapper_tag: self.class.const_get(:WRAPPER_TAG),
41
+ button_tag: self.class.const_get(:BUTTON_TAG),
42
+ attributes: attributes,
43
+ field_data: {
44
+ label: @label,
45
+ content: @content && @view_context.capture(&@content)
46
+ }
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lifeform
4
+ module Libraries
5
+ class Default
6
+ class SubmitButton < Button
7
+ def initialize(form, field_definition, **attributes)
8
+ attributes[:name] ||= "commit"
9
+ attributes[:type] = :submit
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lifeform
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifeform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
@@ -74,7 +74,9 @@ files:
74
74
  - lib/lifeform.rb
75
75
  - lib/lifeform/form.rb
76
76
  - lib/lifeform/libraries/default.rb
77
+ - lib/lifeform/libraries/default/button.rb
77
78
  - lib/lifeform/libraries/default/input.rb
79
+ - lib/lifeform/libraries/default/submit_button.rb
78
80
  - lib/lifeform/libraries/shoelace.rb
79
81
  - lib/lifeform/libraries/shoelace/input.rb
80
82
  - lib/lifeform/version.rb