phlex-rails 0.5.1 → 0.6.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: 407ff3d219b8d6ec6bbe429422b18125dde3f9cfb73ec756bad2ab4f08953083
4
- data.tar.gz: b0e4f337a9626bf67a5e4dfd4172648cf69c264008fde9a5e3c1b456b98d7e72
3
+ metadata.gz: 5ea6f194e6a1f7b09577d125fb155dca62b50f8d807ca31c259666fa31f623e6
4
+ data.tar.gz: 8f05825ecc0a21249c5824b953f6facf1c421b804163519d1d97d1fdd22eebfe
5
5
  SHA512:
6
- metadata.gz: b4e29f9f569bc0259d037d7b8a6e3ee8fb267d8210b2faf1e0a952d25275419e27c9621b615aad8be7d3f5531872848a63e46fdeb1a3ec8506e9babc5b27b1af
7
- data.tar.gz: 4440057f8e253c7f0f78dbd41e4f92c6a8e4faeeac4cb339fbc26d09bc7bafa72302d2f2bc066b8879579b4dc3c053ba07f301622a8801d9a635a216f0ef2ac3
6
+ metadata.gz: 4b37858b1aff182875a4f11b616e5a1ba6fbb72323f77810ee815ee22858893a56fe5aa5dd318fbf60c2988239f9857d50190c6ccf8ca0fd4108eeb32894a7fd
7
+ data.tar.gz: e908c96cbeb82e5396118d14b644fba152a2e08645d32fe505e5058e3776d8cd3f4294d6a34a72ae3fa1bd7c8402aa1f686d22ee9600f959cca0c1652e78e5d5
data/.rubocop.yml CHANGED
@@ -16,6 +16,8 @@ Layout/CaseIndentation:
16
16
  Style/StringConcatenation:
17
17
  Enabled: false
18
18
 
19
+ Layout/MultilineMethodCallBraceLayout:
20
+ Enabled: false
19
21
 
20
22
 
21
23
  Security/Eval:
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.1
data/Gemfile CHANGED
@@ -5,7 +5,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
6
  gemspec
7
7
 
8
- gem "phlex", github: "joeldrapper/phlex", branch: "main"
8
+ gem "phlex", github: "joeldrapper/phlex"
9
+ gem "phlex-testing-capybara", github: "joeldrapper/phlex-testing-capybara"
9
10
  gem "rspec-rails"
10
11
  gem "combustion"
11
12
  gem "rubocop"
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module Phlex::Rails
6
+ # A decorator that buffers all missing method calls and captures the blocks passed to them.
7
+ class Buffered < BasicObject
8
+ extend ::Forwardable
9
+
10
+ # @api private
11
+ def self.define_builder_yielding_method(method_name, builder)
12
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
13
+ # frozen_string_literal: true
14
+
15
+ def #{method_name}(*args, **kwargs, &block)
16
+ output = if block
17
+ @object.#{method_name}(*args, **kwargs) { |builder|
18
+ @view.capture do
19
+ yield(
20
+ ::#{builder.name}.new(builder,
21
+ view: @view
22
+ )
23
+ )
24
+ end
25
+ }
26
+ else
27
+ @object.#{method_name}(*args, **kwargs)
28
+ end
29
+
30
+ case output
31
+ when ::ActiveSupport::SafeBuffer
32
+ @view.instance_variable_get(:@_target) << output
33
+ end
34
+
35
+ nil
36
+ end
37
+ RUBY
38
+ end
39
+
40
+ # @api private
41
+ def initialize(object, view:)
42
+ @object = object
43
+ @view = view
44
+ end
45
+
46
+ def respond_to_missing?(...)
47
+ @object.respond_to?(...)
48
+ end
49
+
50
+ def method_missing(*args, **kwargs, &block)
51
+ output = if block
52
+ @object.public_send(*args, **kwargs) { @view.capture(&block) }
53
+ else
54
+ @object.public_send(*args, **kwargs)
55
+ end
56
+
57
+ case output
58
+ when ::ActiveSupport::SafeBuffer
59
+ @view.instance_variable_get(:@_target) << output
60
+ end
61
+
62
+ nil
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails
4
+ class BufferedCheckboxBuilder < Buffered
5
+ # @!method object(...)
6
+ # @!method text(...)
7
+ # @!method value(...)
8
+ def_delegators :@object,
9
+ :object,
10
+ :text,
11
+ :value
12
+ end
13
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails
4
+ class BufferedFormBuilder < Buffered
5
+ # @!method field_id(...)
6
+ # @!method field_name(...)
7
+ # @!method id(...)
8
+ # @!method multipart=(value)
9
+ # @!method to_model(...)
10
+ # @!method to_partial_path(...)
11
+ def_delegators :@object,
12
+ :to_model,
13
+ :to_partial_path,
14
+ :options,
15
+ :id,
16
+ :field_helpers,
17
+ :multipart=,
18
+ :field_name,
19
+ :index,
20
+ :multipart,
21
+ :multipart?,
22
+ :emitted_hidden_id?,
23
+ :field_id,
24
+ :options=,
25
+ :object=,
26
+ :object_name,
27
+ :field_helpers=,
28
+ :field_helpers?,
29
+ :object_name=,
30
+ :object,
31
+ :convert_to_model,
32
+ :model_name_from_record_or_class
33
+
34
+ # @!method button(...)
35
+ # @!method check_box(...)
36
+ # @!method collection_select(...)
37
+ # @!method color_field(...)
38
+ # @!method date_field(...)
39
+ # @!method date_select(...)
40
+ # @!method datetime_field(...)
41
+ # @!method datetime_local_field(...)
42
+ # @!method datetime_select(...)
43
+ # @!method email_field(...)
44
+ # @!method file_field(...)
45
+ # @!method grouped_collection_select(...)
46
+ # @!method hidden_field(...)
47
+ # @!method month_field(...)
48
+ # @!method number_field(...)
49
+ # @!method password_field(...)
50
+ # @!method phone_field(...)
51
+ # @!method radio_button(...)
52
+ # @!method range_field(...)
53
+ # @!method rich_text_area(...)
54
+ # @!method search_field(...)
55
+ # @!method select(...)
56
+ # @!method submit(...)
57
+ # @!method telephone_field(name, value = nil, **attributes)
58
+ # Outputs an input field of type <code>tel</code>.
59
+ # @param name [Symbol] the name of the field.
60
+ # @param value [String] the default value.
61
+ # @param attributes HTML attributes.
62
+ # @return [nil]
63
+ # @!method text_area(...)
64
+ # @!method text_field(...)
65
+ # @!method time_field(...)
66
+ # @!method time_select(...)
67
+ # @!method time_zone_select(...)
68
+ # @!method url_field(...)
69
+ # @!method week_field(...)
70
+ # @!method weekday_select(...)
71
+
72
+ # @!method label(...)
73
+ # @yield [builder]
74
+ # @yieldparam builder [Phlex::Rails::BufferedLabelBuilder]
75
+ define_builder_yielding_method :label, ::Phlex::Rails::BufferedLabelBuilder
76
+
77
+ # @!method fields(...)
78
+ # @yield [builder]
79
+ # @yieldparam builder [Phlex::Rails::BufferedFormBuilder]
80
+ define_builder_yielding_method :fields, ::Phlex::Rails::BufferedFormBuilder
81
+
82
+ # @!method fields_for(...)
83
+ # @yield [builder]
84
+ # @yieldparam builder [Phlex::Rails::BufferedFormBuilder]
85
+ define_builder_yielding_method :fields_for, ::Phlex::Rails::BufferedFormBuilder
86
+
87
+ # @!method collection_check_boxes(...)
88
+ # @yield [builder]
89
+ # @yieldparam builder [Phlex::Rails::BufferedCheckboxBuilder]
90
+ define_builder_yielding_method :collection_check_boxes, ::Phlex::Rails::BufferedCheckboxBuilder
91
+
92
+ # @!method collection_radio_buttons(...)
93
+ # @yield [builder]
94
+ # @yieldparam builder [Phlex::Rails::BufferedRadioButtonBuilder]
95
+ define_builder_yielding_method :collection_radio_buttons, ::Phlex::Rails::BufferedRadioButtonBuilder
96
+ end
97
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails
4
+ class BufferedLabelBuilder < Buffered
5
+ # @!method object(...)
6
+ # @!method translation(...)
7
+ def_delegators :@object,
8
+ :object,
9
+ :translation
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails
4
+ class BufferedRadioButtonBuilder < Buffered
5
+ # @!method object(...)
6
+ # @!method text(...)
7
+ # @!method value(...)
8
+ def_delegators :@object,
9
+ :object,
10
+ :text,
11
+ :value
12
+ end
13
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ module Phlex::Rails::HelperMacros
5
+ def define_output_helper(method_name)
6
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
7
+ # frozen_string_literal: true
8
+
9
+ def #{method_name}(...)
10
+ output = helpers.#{method_name}(...)
11
+
12
+ case output
13
+ when ActiveSupport::SafeBuffer
14
+ @_target << output
15
+ end
16
+
17
+ nil
18
+ end
19
+ RUBY
20
+ end
21
+
22
+ def define_output_helper_with_capture_block(method_name)
23
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
24
+ # frozen_string_literal: true
25
+
26
+ def #{method_name}(*args, **kwargs, &block)
27
+ output = if block
28
+ helpers.#{method_name}(*args, **kwargs) { capture(&block) }
29
+ else
30
+ helpers.#{method_name}(*args, **kwargs)
31
+ end
32
+
33
+ case output
34
+ when ActiveSupport::SafeBuffer
35
+ @_target << output
36
+ end
37
+
38
+ nil
39
+ end
40
+ RUBY
41
+ end
42
+
43
+ def define_value_helper(method_name)
44
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
45
+ # frozen_string_literal: true
46
+
47
+ def #{method_name}(...)
48
+ helpers.#{method_name}(...)
49
+ end
50
+ RUBY
51
+ end
52
+
53
+ def define_value_helper_with_capture_block(method_name)
54
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
55
+ # frozen_string_literal: true
56
+
57
+ def #{method_name}(*args, **kwargs, &block)
58
+ if block
59
+ helpers.#{method_name}(*args, **kwargs) { capture(&block) }
60
+ else
61
+ helpers.#{method_name}(*args, **kwargs)
62
+ end
63
+ end
64
+ RUBY
65
+ end
66
+
67
+ def define_builder_yielding_helper(method_name, builder)
68
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
69
+ # frozen_string_literal: true
70
+
71
+ def #{method_name}(*args, **kwargs)
72
+ output = if block_given?
73
+ helpers.#{method_name}(*args, **kwargs) { |form|
74
+ capture do
75
+ yield(
76
+ #{builder.name}.new(form,
77
+ view: self
78
+ )
79
+ )
80
+ end
81
+ }
82
+ else
83
+ helpers.#{method_name}(*args, **kwargs)
84
+ end
85
+
86
+ case output
87
+ when ActiveSupport::SafeBuffer
88
+ @_target << output
89
+ end
90
+
91
+ nil
92
+ end
93
+ RUBY
94
+ end
95
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails::Helpers
4
+ module Routes
5
+ include DefaultURLOptions
6
+ include Rails.application.routes.url_helpers
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails::Helpers::Tag
4
+ def tag(...)
5
+ result = helpers.tag(...)
6
+
7
+ case result
8
+ when ActiveSupport::SafeBuffer
9
+ @_target << result
10
+ when ActionView::Helpers::TagHelper::TagBuilder
11
+ Phlex::Rails::Buffered.new(
12
+ result,
13
+ view: self
14
+ )
15
+ end
16
+ end
17
+ end