lifeform 0.3.0 → 0.4.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/Gemfile.lock +1 -1
- data/README.md +6 -0
- data/lib/lifeform/libraries/default/button.rb +52 -0
- data/lib/lifeform/libraries/default/submit_button.rb +16 -0
- data/lib/lifeform/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f1e91a0e3977e9c1ee9bf2fadc00d427efa8f7fcf720ba0670905832e89e41c
|
4
|
+
data.tar.gz: 458c2edd232353260115c6eb794ebfcc7298696723e3ec5f49518ed8ccb68e19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8c0c7b398b5375cc50f0fb9d59ad5f759dcd05cd355fba4ed8c24c6c1e3e11c2447d888592f0c2ccb799a596bdfc23902fd822bd397cbf731c2ef77f453effc
|
7
|
+
data.tar.gz: e96679b59c1abae814f740ba190659eb29a4bae5c1fcc8809bff3336b138b13aded6f87d5bf0a2522ec86de80f8c98c1586eb8fcb81986edd242093294c0d1b0
|
data/Gemfile.lock
CHANGED
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
|
data/lib/lifeform/version.rb
CHANGED
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.
|
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
|