phlex-rails 0.7.1 → 0.8.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: 00fc3d53f19d10aee8a5a0c3aac7c77d5a753caa641dd92524acf1327a3e6a4f
4
+ data.tar.gz: b5574038403fbdf9aba3de312446c3fd027f6f2a98c7bffe50f36ee8ab44f09c
5
5
  SHA512:
6
- metadata.gz: a056aab2cf31bf38c1ed2eab7f52a8a7b63666219c1bacc2c8353f9a6f97a2ccb2cdf41d0bec8028bda4727b8a980cfe6c46c8a75a94b717bc3855cfa0916cf2
7
- data.tar.gz: 57f8936d469a6f821b4f66beb7f7449b1f8b7fca5b750683c1f048ae15d32c052ac3cd84dc9ca87f9b0b4fe92c390d7d45aac512fa71394b1cdaafa0a5f2eb55
6
+ metadata.gz: 68e1dd45327362c06b9cc7b07efcbba51916c34cf3de4e8b42891dee24f20f98a12dec011fe35d7cc6067f5b610339020de43ed6c4ffbc817671a5f1ff8305b1
7
+ data.tar.gz: f671b7275caf0bb733d385cd7310388ab5a82475131bb08d937692f3ed57aeba7bd8788d2bd23856a5e08435cc21924c733238d5c391b82bf2bee9d281453ce1
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
 
@@ -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
 
@@ -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 = @_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 == @_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
+ @_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
+ @_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,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.8.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.8.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-06 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.5'
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.5'
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