phlex-rails 0.7.1 → 0.9.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: 14e809453546abb9a9453eaaa4c11a60cccb9526ccf528b399ca56cdeb70b209
4
- data.tar.gz: 3b5902a341273eefb1bc49cdd4cd6bc8767ce68df3eb4d8011479b8e2f1adace
3
+ metadata.gz: 64bd1c0569d8a687689b1eec091acff484e3c3c7db388f80ddc1cb059881c680
4
+ data.tar.gz: 282af2d851aaef5e1266519b59ba5ade1360cd13666d629b4109441f16abb6f6
5
5
  SHA512:
6
- metadata.gz: a056aab2cf31bf38c1ed2eab7f52a8a7b63666219c1bacc2c8353f9a6f97a2ccb2cdf41d0bec8028bda4727b8a980cfe6c46c8a75a94b717bc3855cfa0916cf2
7
- data.tar.gz: 57f8936d469a6f821b4f66beb7f7449b1f8b7fca5b750683c1f048ae15d32c052ac3cd84dc9ca87f9b0b4fe92c390d7d45aac512fa71394b1cdaafa0a5f2eb55
6
+ metadata.gz: e9f65f079a1ec7372692767beb7f7f1f70dac50f4429f429aa0085bbfefcd40675e2933985d728ed2354fb90983d86a707d1f5432c3333f72f843032086c7924
7
+ data.tar.gz: 7e5f5fe2316c5db3ae8757a67517856ffdebf4f5b03467d17a712eb6c571486f402ceeb993cd1ceba31c3a7cfef37aa104ed297123be43fb30cb2af790775530
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
 
@@ -12,14 +12,18 @@ module Phlex
12
12
  end
13
13
  end
14
14
 
15
- def render(renderable = nil, *args, **kwargs, &block)
16
- return super if renderable.is_a?(Phlex::SGML)
17
- return super if renderable.is_a?(Class) && renderable < Phlex::SGML
18
-
19
- if renderable
20
- @_target << @_view_context.render(renderable, *args, **kwargs, &block)
15
+ def render(*args, **kwargs, &block)
16
+ renderable = args[0]
17
+
18
+ case renderable
19
+ when Phlex::SGML, Proc
20
+ return super
21
+ when Class
22
+ return super if renderable < Phlex::SGML
23
+ when Enumerable
24
+ return super unless renderable.is_a?(ActiveRecord::Relation)
21
25
  else
22
- @_target << @_view_context.render(*args, **kwargs, &block)
26
+ @_context.target << @_view_context.render(*args, **kwargs, &block)
23
27
  end
24
28
 
25
29
  nil
@@ -28,92 +32,46 @@ module Phlex
28
32
  def render_in(view_context, &block)
29
33
  if block_given?
30
34
  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
35
+ original_length = @_context.target.length
36
+
37
+ if args.length == 1 && Phlex::SGML === args[0]
38
+ output = view_context.capture(
39
+ args[0].unbuffered, &block
40
+ )
41
+ else
42
+ output = view_context.capture(*args, &block)
43
+ end
41
44
 
42
- unchanged = (original_length == @_target.length)
45
+ unchanged = (original_length == @_context.target.length)
43
46
 
44
- if unchanged
45
- if output.is_a?(ActiveSupport::SafeBuffer)
46
- unsafe_raw(output)
47
- else
48
- text(output)
49
- end
47
+ if unchanged
48
+ case output
49
+ when ActiveSupport::SafeBuffer
50
+ @_context.target << output
50
51
  end
51
52
  end
52
-
53
- nil
54
53
  end.html_safe
55
54
  else
56
55
  call(view_context: view_context).html_safe
57
56
  end
58
57
  end
59
58
 
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
59
+ def capture
60
+ super&.html_safe
69
61
  end
70
62
 
71
- # @api private
72
- alias_method :safe_concat, :safe_append=
73
-
74
- # @api private
75
- def append=(value)
76
- case value
63
+ def plain(content)
64
+ case content
77
65
  when ActiveSupport::SafeBuffer
78
- @_target << value
66
+ @_context.target << content
79
67
  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
68
+ super
85
69
  end
86
70
  end
87
71
 
88
- def capture
89
- super&.html_safe
90
- end
91
-
92
72
  # Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
93
73
  def set_original_view_context(view_context)
94
74
  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
75
  end
118
76
  end
119
77
  end
@@ -0,0 +1,25 @@
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
+ @object.helpers.capture(*aa, &b)
12
+ end
13
+ else
14
+ @object.public_send(name, *a, **k)
15
+ end
16
+ end
17
+ end
18
+
19
+ # Now we've defined this missing method, we can call it.
20
+ __public_send__(name, *args, **kwargs, &block)
21
+ else
22
+ super
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.7.1"
5
+ VERSION = "0.9.0"
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.9.0
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-08 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