lifeform 0.8.0 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84cc7c165874ab122f164fe3edae5c7e7f68d7ba4936f115151f5fec3ecdd217
4
- data.tar.gz: 690ab60f63f813cfedf830416d1fe3761ad4dfd090344dc227e598e62c5bb497
3
+ metadata.gz: fef99043fb289f536c1a3b6986a48675dc741854ffef6e99c596c5d9abca303a
4
+ data.tar.gz: 61821150d087888c5b243e2c52916534f7fc8b4fb8a14ced79692d3bb1ed1f45
5
5
  SHA512:
6
- metadata.gz: aec711376fecf90651b305a8a8f3a7044dcbdb022a4c17713e0433f8e90590f9502668794143183bc0c71d8d3a0de1dbe85cc3e989b764552190367234a10bed
7
- data.tar.gz: f057b69cbf5d7f43f5cba4a30f79df5d0f3735af41fb363bf7147853d327b07315e730708c8feaae2063993a477ee39c9e9d22f0f1385f4c3c9991d9360a4a98
6
+ metadata.gz: 8b64f7550a79f0e7667ac422a9cecb364943c544e9583f724842326d4cb9b28b74ae0dee19427be1121fcfd4e9b1a9e5e7878ff1cc8a2e22ee65dd734a0c69e1
7
+ data.tar.gz: adec1d8e7d8a800f667953ef4e91f90935878a9e1dc6095a82536625bf675ee9f1be74ee3ed31f1857807c9ee75dcd3b36f95a42c32ba79aa10cca0395240dc8
data/.rubocop.yml CHANGED
@@ -5,6 +5,8 @@ require:
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.7
7
7
  NewCops: enable
8
+ Exclude:
9
+ - lib/lifeform/phlex_renderable.rb
8
10
 
9
11
  Lint/MissingSuper:
10
12
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.10.0] - 2022-12-23
6
+
7
+ - Support Phlex 1.0 and conditional `render_in` support for Bridgetown
8
+
9
+ ## [0.9.0] - 2022-11-06
10
+
11
+ - Add button & submit button support for Shoelace
12
+
13
+ ## [0.8.0] - 2022-10-09
14
+
15
+ - Add initializer for Bridgetown 1.2+
16
+ - Fix for Roda csrf
17
+
5
18
  ## [0.7.0] - 2022-09-30
6
19
 
7
20
  - Rearchitect library to be built on top of the Phlex view library
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifeform (0.8.0)
4
+ lifeform (0.10.0)
5
5
  activesupport (>= 6.0)
6
- phlex (~> 0.3)
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.0)
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.2)
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.8-arm64-darwin)
39
+ nokogiri (1.13.10-arm64-darwin)
40
40
  racc (~> 1.4)
41
- nokogiri (1.13.8-x86_64-linux)
41
+ nokogiri (1.13.10-x86_64-linux)
42
42
  racc (~> 1.4)
43
43
  parallel (1.22.1)
44
- parser (3.1.2.1)
44
+ parser (3.1.3.0)
45
45
  ast (~> 2.4.1)
46
- phlex (0.3.2)
47
- syntax_tree (~> 3.6)
46
+ phlex (1.0.0)
48
47
  zeitwerk (~> 2.6)
49
- prettier_print (0.1.0)
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.0)
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.36.0)
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.20.1, < 2.0)
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.21.0)
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.2)
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.1)
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
- $ bundle add lifeform
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
- raw(view_context.capture(*args, **kwargs, &block))
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::View # rubocop:todo Metrics/ClassLength
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::View) do # TODO: break this out into a real component
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
- raw(add_authenticity_token) unless parameters[:method].to_s.downcase == "get"
189
- raw @method_tag&.() || ""
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::View
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
- raw(@label.to_s) unless block
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::View
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) { raw label_text }
54
+ label(for: label_name) { unsafe_raw label_text }
54
55
  }
55
56
  end
56
57
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lifeform
4
+ module Libraries
5
+ class Shoelace
6
+ class Button < Default::Button
7
+ BUTTON_TAG = :sl_button
8
+
9
+ register_element BUTTON_TAG
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lifeform
4
+ module Libraries
5
+ class Shoelace
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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lifeform
4
- VERSION = "0.8.0"
4
+ VERSION = "0.10.0"
5
5
  end
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
- # no extra config at the moment
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.3"
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.8.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-10-09 00:00:00.000000000 Z
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.3'
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.3'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: zeitwerk
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +79,10 @@ files:
79
79
  - lib/lifeform/libraries/default/input.rb
80
80
  - lib/lifeform/libraries/default/submit_button.rb
81
81
  - lib/lifeform/libraries/shoelace.rb
82
+ - lib/lifeform/libraries/shoelace/button.rb
82
83
  - lib/lifeform/libraries/shoelace/input.rb
84
+ - lib/lifeform/libraries/shoelace/submit_button.rb
85
+ - lib/lifeform/phlex_renderable.rb
83
86
  - lib/lifeform/version.rb
84
87
  - lifeform.gemspec
85
88
  homepage: https://github.com/bridgetownrb/lifeform