lifeform 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +14 -18
- data/README.md +3 -1
- data/lib/lifeform/capturing_renderable.rb +1 -1
- data/lib/lifeform/form.rb +4 -4
- data/lib/lifeform/libraries/default/button.rb +3 -2
- data/lib/lifeform/libraries/default/input.rb +3 -2
- data/lib/lifeform/phlex_renderable.rb +75 -0
- data/lib/lifeform/version.rb +1 -1
- data/lib/lifeform.rb +10 -2
- data/lifeform.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fef99043fb289f536c1a3b6986a48675dc741854ffef6e99c596c5d9abca303a
|
4
|
+
data.tar.gz: 61821150d087888c5b243e2c52916534f7fc8b4fb8a14ced79692d3bb1ed1f45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b64f7550a79f0e7667ac422a9cecb364943c544e9583f724842326d4cb9b28b74ae0dee19427be1121fcfd4e9b1a9e5e7878ff1cc8a2e22ee65dd734a0c69e1
|
7
|
+
data.tar.gz: adec1d8e7d8a800f667953ef4e91f90935878a9e1dc6095a82536625bf675ee9f1be74ee3ed31f1857807c9ee75dcd3b36f95a42c32ba79aa10cca0395240dc8
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lifeform (0.
|
4
|
+
lifeform (0.10.0)
|
5
5
|
activesupport (>= 6.0)
|
6
|
-
phlex (~> 0
|
6
|
+
phlex (~> 1.0)
|
7
7
|
zeitwerk (~> 2.5)
|
8
8
|
|
9
9
|
GEM
|
@@ -17,7 +17,7 @@ GEM
|
|
17
17
|
ansi (1.5.0)
|
18
18
|
ast (2.4.2)
|
19
19
|
backport (1.2.0)
|
20
|
-
benchmark (0.2.
|
20
|
+
benchmark (0.2.1)
|
21
21
|
builder (3.2.4)
|
22
22
|
concurrent-ruby (1.1.10)
|
23
23
|
diff-lcs (1.5.0)
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
i18n (1.12.0)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
jaro_winkler (1.5.4)
|
28
|
-
json (2.6.
|
28
|
+
json (2.6.3)
|
29
29
|
kramdown (2.4.0)
|
30
30
|
rexml
|
31
31
|
kramdown-parser-gfm (1.1.0)
|
@@ -36,38 +36,36 @@ GEM
|
|
36
36
|
builder
|
37
37
|
minitest (>= 5.0)
|
38
38
|
ruby-progressbar
|
39
|
-
nokogiri (1.13.
|
39
|
+
nokogiri (1.13.10-arm64-darwin)
|
40
40
|
racc (~> 1.4)
|
41
|
-
nokogiri (1.13.
|
41
|
+
nokogiri (1.13.10-x86_64-linux)
|
42
42
|
racc (~> 1.4)
|
43
43
|
parallel (1.22.1)
|
44
|
-
parser (3.1.
|
44
|
+
parser (3.1.3.0)
|
45
45
|
ast (~> 2.4.1)
|
46
|
-
phlex (0.
|
47
|
-
syntax_tree (~> 3.6)
|
46
|
+
phlex (1.0.0)
|
48
47
|
zeitwerk (~> 2.6)
|
49
|
-
|
50
|
-
racc (1.6.0)
|
48
|
+
racc (1.6.1)
|
51
49
|
rails-dom-testing (2.0.3)
|
52
50
|
activesupport (>= 4.2.0)
|
53
51
|
nokogiri (>= 1.6)
|
54
52
|
rainbow (3.1.1)
|
55
53
|
rake (13.0.6)
|
56
|
-
regexp_parser (2.6.
|
54
|
+
regexp_parser (2.6.1)
|
57
55
|
reverse_markdown (2.1.1)
|
58
56
|
nokogiri
|
59
57
|
rexml (3.2.5)
|
60
|
-
rubocop (1.
|
58
|
+
rubocop (1.40.0)
|
61
59
|
json (~> 2.3)
|
62
60
|
parallel (~> 1.10)
|
63
61
|
parser (>= 3.1.2.1)
|
64
62
|
rainbow (>= 2.2.2, < 4.0)
|
65
63
|
regexp_parser (>= 1.8, < 3.0)
|
66
64
|
rexml (>= 3.2.5, < 4.0)
|
67
|
-
rubocop-ast (>= 1.
|
65
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
68
66
|
ruby-progressbar (~> 1.7)
|
69
67
|
unicode-display_width (>= 1.4.0, < 3.0)
|
70
|
-
rubocop-ast (1.
|
68
|
+
rubocop-ast (1.24.0)
|
71
69
|
parser (>= 3.1.1.0)
|
72
70
|
rubocop-minitest (0.20.1)
|
73
71
|
rubocop (>= 0.90, < 2.0)
|
@@ -89,8 +87,6 @@ GEM
|
|
89
87
|
thor (~> 1.0)
|
90
88
|
tilt (~> 2.0)
|
91
89
|
yard (~> 0.9, >= 0.9.24)
|
92
|
-
syntax_tree (3.6.3)
|
93
|
-
prettier_print
|
94
90
|
thor (1.2.1)
|
95
91
|
tilt (2.0.11)
|
96
92
|
tzinfo (2.0.5)
|
@@ -99,7 +95,7 @@ GEM
|
|
99
95
|
webrick (1.7.0)
|
100
96
|
yard (0.9.28)
|
101
97
|
webrick (~> 1.7.0)
|
102
|
-
zeitwerk (2.6.
|
98
|
+
zeitwerk (2.6.6)
|
103
99
|
|
104
100
|
PLATFORMS
|
105
101
|
arm64-darwin-21
|
data/README.md
CHANGED
@@ -7,9 +7,11 @@ Component-centric form object rendering for Ruby. Powered by [Phlex](https://www
|
|
7
7
|
Add Lifeform to your application's Gemfile by running:
|
8
8
|
|
9
9
|
```sh
|
10
|
-
|
10
|
+
bundle add lifeform
|
11
11
|
```
|
12
12
|
|
13
|
+
If you're in a Rails app, you'll want to `bundle add phlex-rails` as well for Action View rendering support.
|
14
|
+
|
13
15
|
## Usage
|
14
16
|
|
15
17
|
Full documentation coming as the library begins to mature. TL;DR:
|
@@ -7,7 +7,7 @@ module Lifeform
|
|
7
7
|
def render_in(view_context, &block)
|
8
8
|
if block
|
9
9
|
call(view_context: view_context) do |*args, **kwargs|
|
10
|
-
|
10
|
+
unsafe_raw(view_context.capture(*args, **kwargs, &block))
|
11
11
|
end.html_safe
|
12
12
|
else
|
13
13
|
call(view_context: view_context).html_safe
|
data/lib/lifeform/form.rb
CHANGED
@@ -6,7 +6,7 @@ module Lifeform
|
|
6
6
|
FieldDefinition = Struct.new(:type, :library, :parameters)
|
7
7
|
|
8
8
|
# A form object which stores field definitions and can be rendered as a component
|
9
|
-
class Form < Phlex::
|
9
|
+
class Form < Phlex::HTML # rubocop:todo Metrics/ClassLength
|
10
10
|
include CapturingRenderable
|
11
11
|
MODEL_PATH_HELPER = :polymorphic_path
|
12
12
|
|
@@ -132,7 +132,7 @@ module Lifeform
|
|
132
132
|
def verify_method
|
133
133
|
return if %w[get post].include?(parameters[:method].to_s.downcase)
|
134
134
|
|
135
|
-
@method_tag = Class.new(Phlex::
|
135
|
+
@method_tag = Class.new(Phlex::HTML) do # TODO: break this out into a real component
|
136
136
|
def initialize(method:)
|
137
137
|
@method = method
|
138
138
|
end
|
@@ -185,8 +185,8 @@ module Lifeform
|
|
185
185
|
parameters[:action] ||= url || (model ? helpers.send(self.class.const_get(:MODEL_PATH_HELPER), model) : nil)
|
186
186
|
|
187
187
|
send(form_tag, **attributes) do
|
188
|
-
|
189
|
-
|
188
|
+
unsafe_raw(add_authenticity_token) unless parameters[:method].to_s.downcase == "get"
|
189
|
+
unsafe_raw @method_tag&.() || ""
|
190
190
|
block ? yield_content(&block) : auto_render_fields
|
191
191
|
end
|
192
192
|
end
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module Lifeform
|
4
4
|
module Libraries
|
5
5
|
class Default
|
6
|
-
class Button < Phlex::
|
6
|
+
class Button < Phlex::HTML
|
7
|
+
using RefineProcToString
|
7
8
|
include CapturingRenderable
|
8
9
|
|
9
10
|
attr_reader :form, :field_definition, :attributes
|
@@ -30,7 +31,7 @@ module Lifeform
|
|
30
31
|
|
31
32
|
field_body = proc {
|
32
33
|
send(button_tag, **@attributes) do
|
33
|
-
|
34
|
+
unsafe_raw(@label.to_s) unless block
|
34
35
|
yield_content(&block)
|
35
36
|
end
|
36
37
|
}
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module Lifeform
|
4
4
|
module Libraries
|
5
5
|
class Default
|
6
|
-
class Input < Phlex::
|
6
|
+
class Input < Phlex::HTML
|
7
|
+
using RefineProcToString
|
7
8
|
include CapturingRenderable
|
8
9
|
|
9
10
|
attr_reader :form, :field_definition, :attributes
|
@@ -50,7 +51,7 @@ module Lifeform
|
|
50
51
|
@attributes = attributes.filter_map { |k, v| [k, v] unless k == :label }.to_h
|
51
52
|
|
52
53
|
proc {
|
53
|
-
label(for: label_name) {
|
54
|
+
label(for: label_name) { unsafe_raw label_text }
|
54
55
|
}
|
55
56
|
end
|
56
57
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Bridgetown-specific workaround that got copied over from the phlex-rails gem (for now)
|
4
|
+
module Lifeform
|
5
|
+
module PhlexRenderable
|
6
|
+
def helpers
|
7
|
+
@_view_context
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(renderable, *args, **kwargs, &block)
|
11
|
+
return super if renderable.is_a?(Phlex::HTML)
|
12
|
+
return super if renderable.is_a?(Class) && renderable < Phlex::HTML
|
13
|
+
|
14
|
+
@_target << @_view_context.render(renderable, *args, **kwargs, &block)
|
15
|
+
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def render_in(view_context, &block)
|
20
|
+
if block_given?
|
21
|
+
call(view_context: view_context) do |*args|
|
22
|
+
view_context.with_output_buffer(self) do
|
23
|
+
original_length = @_target.length
|
24
|
+
output = yield(*args)
|
25
|
+
unchanged = (original_length == @_target.length)
|
26
|
+
|
27
|
+
if unchanged
|
28
|
+
if output.is_a?(ActiveSupport::SafeBuffer)
|
29
|
+
unsafe_raw(output)
|
30
|
+
else
|
31
|
+
text(output)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end.html_safe
|
36
|
+
else
|
37
|
+
call(view_context: view_context).html_safe
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def safe_append=(value)
|
42
|
+
return unless value
|
43
|
+
|
44
|
+
@_target << case value
|
45
|
+
when String then value
|
46
|
+
when Symbol then value.name
|
47
|
+
else value.to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def append=(value)
|
52
|
+
return unless value
|
53
|
+
|
54
|
+
if value.html_safe?
|
55
|
+
self.safe_append = value
|
56
|
+
else
|
57
|
+
@_target << case value
|
58
|
+
when String then ERB::Util.html_escape(value)
|
59
|
+
when Symbol then ERB::Util.html_escape(value.name)
|
60
|
+
else ERB::Util.html_escape(value.to_s)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def capture
|
66
|
+
super.html_safe
|
67
|
+
end
|
68
|
+
|
69
|
+
# Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
|
70
|
+
def set_original_view_context(view_context)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Phlex::HTML.prepend(Lifeform::PhlexRenderable)
|
data/lib/lifeform/version.rb
CHANGED
data/lib/lifeform.rb
CHANGED
@@ -9,13 +9,21 @@ loader.setup
|
|
9
9
|
|
10
10
|
module Lifeform
|
11
11
|
class Error < StandardError; end
|
12
|
+
|
13
|
+
module RefineProcToString
|
14
|
+
refine Proc do
|
15
|
+
def to_s
|
16
|
+
call.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
12
20
|
end
|
13
21
|
|
14
22
|
if defined?(Bridgetown)
|
15
23
|
# Check compatibility
|
16
24
|
raise "The Lifeform support for Bridgetown requires v1.2 or newer" if Bridgetown::VERSION.to_f < 1.2
|
17
25
|
|
18
|
-
Bridgetown.initializer :lifeform do |config|
|
19
|
-
|
26
|
+
Bridgetown.initializer :lifeform do # |config|
|
27
|
+
require "lifeform/phlex_renderable" unless Phlex::HTML.instance_methods.include?(:render_in)
|
20
28
|
end
|
21
29
|
end
|
data/lifeform.gemspec
CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
# Uncomment to register a new dependency of your gem
|
27
27
|
spec.add_dependency "activesupport", ">= 6.0"
|
28
|
-
spec.add_dependency "phlex", "~> 0
|
28
|
+
spec.add_dependency "phlex", "~> 1.0"
|
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.
|
4
|
+
version: 0.10.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-
|
11
|
+
date: 2022-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
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: '0
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: zeitwerk
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/lifeform/libraries/shoelace/button.rb
|
83
83
|
- lib/lifeform/libraries/shoelace/input.rb
|
84
84
|
- lib/lifeform/libraries/shoelace/submit_button.rb
|
85
|
+
- lib/lifeform/phlex_renderable.rb
|
85
86
|
- lib/lifeform/version.rb
|
86
87
|
- lifeform.gemspec
|
87
88
|
homepage: https://github.com/bridgetownrb/lifeform
|