phlex-rails 0.7.1 → 0.8.1

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: 14e809453546abb9a9453eaaa4c11a60cccb9526ccf528b399ca56cdeb70b209
4
- data.tar.gz: 3b5902a341273eefb1bc49cdd4cd6bc8767ce68df3eb4d8011479b8e2f1adace
3
+ metadata.gz: 1d500a3ff8d27e51acd27c6901159a5878ee3bf86548d621e4d3deae2d04ad18
4
+ data.tar.gz: 076fce2ab65191941c6f5f7e72e861e9f0c8768909051977c840661b76811d90
5
5
  SHA512:
6
- metadata.gz: a056aab2cf31bf38c1ed2eab7f52a8a7b63666219c1bacc2c8353f9a6f97a2ccb2cdf41d0bec8028bda4727b8a980cfe6c46c8a75a94b717bc3855cfa0916cf2
7
- data.tar.gz: 57f8936d469a6f821b4f66beb7f7449b1f8b7fca5b750683c1f048ae15d32c052ac3cd84dc9ca87f9b0b4fe92c390d7d45aac512fa71394b1cdaafa0a5f2eb55
6
+ metadata.gz: a48694a35ddc236320b5467548cf5a509a8cd6cb069277aa39109be4e49f6d299459b14a2c8d8afa3debc559deecdec90743536fbad42b2e2ba4250aadcb7d92
7
+ data.tar.gz: 3dbd6856b20b5c27471cded9cb6600da3d71de126134564b9367eafa88bdbf3c9e18463c442892d63d58ac118a3c39d91959dd52be6b8aba373071cc4b7d75fb
data/.rubocop.yml CHANGED
@@ -6,31 +6,7 @@ AllCops:
6
6
  TargetRubyVersion: 2.7
7
7
  Exclude:
8
8
  - "lib/phlex-rails.rb"
9
+ SuggestExtensions: false
9
10
 
10
- Style/PercentLiteralDelimiters:
11
- Enabled: false
12
-
13
- Layout/CaseIndentation:
14
- Enabled: false
15
-
16
- Style/StringConcatenation:
17
- Enabled: false
18
-
19
- Layout/MultilineMethodCallBraceLayout:
20
- Enabled: false
21
-
22
-
23
- Security/Eval:
24
- Enabled: false
25
-
26
- Style/MethodCallWithoutArgsParentheses:
27
- Enabled: false
28
-
29
- Style/MixinUsage:
30
- Enabled: false
31
-
32
- Style/ConditionalAssignment:
33
- Enabled: false
34
-
35
- Lint/UnderscorePrefixedVariableName:
11
+ Style/MissingRespondToMissing:
36
12
  Enabled: false
data/Appraisals CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  appraise "rails-6" do
4
- gem "rails", "~> 6.1"
4
+ gem "rails", "~> 6"
5
5
  end
6
6
 
7
7
  appraise "rails-7" do
8
- gem "rails"
8
+ gem "rails", "~> 7"
9
9
  end
10
10
 
11
11
  appraise "rails-edge" do
data/README.md CHANGED
@@ -8,7 +8,7 @@ Documentation can be found at [www.phlex.fun](https://www.phlex.fun).
8
8
 
9
9
  ### Support ✋
10
10
 
11
- If you run into any trouble, please [start a discussion](https://github.com/joeldrapper/phlex/discussions/new), or [open an issue](https://github.com/joeldrapper/phlex/issues/new) if you think you’ve found a bug.
11
+ If you run into any trouble, please [start a discussion](https://github.com/joeldrapper/phlex/discussions/new), or [open an issue](https://github.com/joeldrapper/phlex-rails/issues/new) if you think you’ve found a bug.
12
12
 
13
13
  ### Community 🙌
14
14
 
@@ -29,7 +29,7 @@ module Phlex::Rails
29
29
 
30
30
  case output
31
31
  when ::ActiveSupport::SafeBuffer
32
- @view.instance_variable_get(:@_target) << output
32
+ @view.instance_variable_get(:@_context).target << output
33
33
  end
34
34
 
35
35
  nil
@@ -56,7 +56,7 @@ module Phlex::Rails
56
56
 
57
57
  case output
58
58
  when ::ActiveSupport::SafeBuffer
59
- @view.instance_variable_get(:@_target) << output
59
+ @view.instance_variable_get(:@_context).target << output
60
60
  end
61
61
 
62
62
  nil
@@ -11,7 +11,7 @@ module Phlex::Rails::HelperMacros
11
11
 
12
12
  case output
13
13
  when ActiveSupport::SafeBuffer
14
- @_target << output
14
+ @_context.target << output
15
15
  end
16
16
 
17
17
  nil
@@ -32,7 +32,7 @@ module Phlex::Rails::HelperMacros
32
32
 
33
33
  case output
34
34
  when ActiveSupport::SafeBuffer
35
- @_target << output
35
+ @_context.target << output
36
36
  end
37
37
 
38
38
  nil
@@ -85,7 +85,7 @@ module Phlex::Rails::HelperMacros
85
85
 
86
86
  case output
87
87
  when ActiveSupport::SafeBuffer
88
- @_target << output
88
+ @_context.target << output
89
89
  end
90
90
 
91
91
  nil
@@ -10,7 +10,7 @@ module Phlex::Rails::Helpers::Tag
10
10
 
11
11
  case result
12
12
  when ActiveSupport::SafeBuffer
13
- @_target << result
13
+ @_context.target << result
14
14
  when ActionView::Helpers::TagHelper::TagBuilder
15
15
  Phlex::Rails::Buffered.new(
16
16
  result,
@@ -1306,6 +1306,13 @@ module Phlex::Rails::Helpers
1306
1306
  define_output_helper :url_field_tag
1307
1307
  end
1308
1308
 
1309
+ module URLFor
1310
+ extend Phlex::Rails::HelperMacros
1311
+
1312
+ # @!method url_for(...)
1313
+ define_value_helper :url_for
1314
+ end
1315
+
1309
1316
  module URLOptions
1310
1317
  extend Phlex::Rails::HelperMacros
1311
1318
 
@@ -17,9 +17,9 @@ module Phlex
17
17
  return super if renderable.is_a?(Class) && renderable < Phlex::SGML
18
18
 
19
19
  if renderable
20
- @_target << @_view_context.render(renderable, *args, **kwargs, &block)
20
+ @_context.target << @_view_context.render(renderable, *args, **kwargs, &block)
21
21
  else
22
- @_target << @_view_context.render(*args, **kwargs, &block)
22
+ @_context.target << @_view_context.render(*args, **kwargs, &block)
23
23
  end
24
24
 
25
25
  nil
@@ -28,92 +28,46 @@ module Phlex
28
28
  def render_in(view_context, &block)
29
29
  if block_given?
30
30
  call(view_context: view_context) do |*args|
31
- view_context.with_output_buffer(self) do
32
- original_length = @_target.length
33
-
34
- if args.length == 1 && Phlex::SGML === args[0]
35
- output = yield(
36
- args[0].unbuffered
37
- )
38
- else
39
- output = yield(*args)
40
- end
31
+ original_length = @_context.target.length
32
+
33
+ if args.length == 1 && Phlex::SGML === args[0]
34
+ output = view_context.capture(
35
+ args[0].unbuffered, &block
36
+ )
37
+ else
38
+ output = view_context.capture(*args, &block)
39
+ end
41
40
 
42
- unchanged = (original_length == @_target.length)
41
+ unchanged = (original_length == @_context.target.length)
43
42
 
44
- if unchanged
45
- if output.is_a?(ActiveSupport::SafeBuffer)
46
- unsafe_raw(output)
47
- else
48
- text(output)
49
- end
43
+ if unchanged
44
+ case output
45
+ when ActiveSupport::SafeBuffer
46
+ @_context.target << output
50
47
  end
51
48
  end
52
-
53
- nil
54
49
  end.html_safe
55
50
  else
56
51
  call(view_context: view_context).html_safe
57
52
  end
58
53
  end
59
54
 
60
- # @api private
61
- def safe_append=(value)
62
- return unless value
63
-
64
- @_target << case value
65
- when String then value
66
- when Symbol then value.name
67
- else value.to_s
68
- end
55
+ def capture
56
+ super&.html_safe
69
57
  end
70
58
 
71
- # @api private
72
- alias_method :safe_concat, :safe_append=
73
-
74
- # @api private
75
- def append=(value)
76
- case value
59
+ def plain(content)
60
+ case content
77
61
  when ActiveSupport::SafeBuffer
78
- @_target << value
62
+ @_context.target << content
79
63
  else
80
- @_target << case value
81
- when String then ERB::Util.html_escape(value)
82
- when Symbol then ERB::Util.html_escape(value.name)
83
- else ERB::Util.html_escape(value.to_s)
84
- end
64
+ super
85
65
  end
86
66
  end
87
67
 
88
- def capture
89
- super&.html_safe
90
- end
91
-
92
68
  # Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
93
69
  def set_original_view_context(view_context)
94
70
  end
95
-
96
- private def yield_content(&block)
97
- return unless block
98
-
99
- case block.binding.receiver
100
- when Phlex::SGML
101
- super
102
- else
103
- @_view_context.with_output_buffer(self) { super }
104
- end
105
- end
106
-
107
- private def yield_content_with_args(*args, &block)
108
- return unless block
109
-
110
- case block.binding.receiver
111
- when Phlex::SGML
112
- super
113
- else
114
- @_view_context.with_output_buffer(self) { super }
115
- end
116
- end
117
71
  end
118
72
  end
119
73
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Rails::UnbufferedOverrides
4
+ def method_missing(name, *args, **kwargs, &block)
5
+ if @object.respond_to?(name)
6
+
7
+ __class__.define_method(name) do |*a, **k, &b|
8
+ @object.capture do
9
+ if b
10
+ @object.public_send(name, *a, **k) do |*aa|
11
+ if aa.length == 1 && aa[0].is_a?(Phlex::SGML)
12
+ @object.helpers.capture(aa[0].unbuffered, &b)
13
+ else
14
+ @object.helpers.capture(*aa, &b)
15
+ end
16
+ end
17
+ else
18
+ @object.public_send(name, *a, **k)
19
+ end
20
+ end
21
+ end
22
+
23
+ # Now we've defined this missing method, we can call it.
24
+ __public_send__(name, *args, **kwargs, &block)
25
+ else
26
+ super
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.7.1"
5
+ VERSION = "0.8.1"
6
6
  end
7
7
  end
data/lib/phlex/rails.rb CHANGED
@@ -18,7 +18,6 @@ module Phlex
18
18
 
19
19
  class SGML
20
20
  extend Phlex::Rails::SGML::ClassMethods
21
- extend Phlex::Rails::SGML::AppendMethodAddedWarning
22
21
 
23
22
  prepend Phlex::Rails::SGML::Overrides
24
23
  end
@@ -27,4 +26,8 @@ module Phlex
27
26
  extend Phlex::Rails::HTML::Format
28
27
  include Phlex::Rails::HTML::Format
29
28
  end
29
+
30
+ class Unbuffered
31
+ prepend ::Phlex::Rails::UnbufferedOverrides
32
+ end
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '1.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -111,9 +111,9 @@ files:
111
111
  - lib/phlex/rails/helpers/turbo_stream.rb
112
112
  - lib/phlex/rails/html/format.rb
113
113
  - lib/phlex/rails/layout.rb
114
- - lib/phlex/rails/sgml/append_method_added_warning.rb
115
114
  - lib/phlex/rails/sgml/class_methods.rb
116
115
  - lib/phlex/rails/sgml/overrides.rb
116
+ - lib/phlex/rails/unbuffered_overrides.rb
117
117
  - lib/phlex/rails/version.rb
118
118
  - lib/phlex/testing/rails/view_helper.rb
119
119
  - phlex_logo.png
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Rails
5
- module SGML
6
- module AppendMethodAddedWarning
7
- def method_added(name)
8
- if name == :append || name == :safe_append= || name == :safe_concat
9
- raise Phlex::NameError, "You shouldn't redefine the #{name} method as it's required for safe HTML output."
10
- end
11
-
12
- super
13
- end
14
- end
15
- end
16
- end
17
- end