phlex-rails 0.2.1 → 0.2.2

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: 28ff15970d3e9f51641fcf4739a1ce10cf7d026a3e11bacf88892372a5aa8180
4
- data.tar.gz: dcd2019092caec7c33a8fb837396d072b2894e13819074423c679a6555809f47
3
+ metadata.gz: d270dd49cf94953641c2f7987f05c3a4904b3e6c39983884b6c6dca60bd89a78
4
+ data.tar.gz: ee571c67532384b55c641777c42d295820f3ec00b5a48fb8bb3b331f3539009d
5
5
  SHA512:
6
- metadata.gz: f60d2e3e17bafb9d40ac0e7287346cd97146954e2a3901e45c82d5d937bea4eb9468d7d573bceff4043a7244834426a0cf8c35065027582901534c68e9e8911d
7
- data.tar.gz: 6b4141a6ffc3a44c294370ba17cf15a8e9d683e6beeae00fd1b7045f842820155d1c8de8e396892f991af4eec5ca5759012ca606009213dc30bdf727669ed9ab
6
+ metadata.gz: b8bdc497af4542412f8addfda2b7cdb3602448df6867010a2352d7ed66e862073eb3cce54167ddf1cda8d8f7ad5a7f528f6a90987ad51107987fe7dcced8074b
7
+ data.tar.gz: 597a9cd87505991851beeaa69a3c41453b476a0e4d7b5709d8a3b6c9ab7ddd5df5b50bfe2a673c6c9ec62ba5c0bc2aa822315f8be5dec62cbf1e96fc9bcd8b8c
@@ -17,7 +17,7 @@ module Phlex
17
17
  ::Rails.root.join("app/views/layout.rb").exist?
18
18
  end
19
19
 
20
- hook_for :test_framework
20
+ # hook_for :test_framework
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+
5
+ module Phlex
6
+ module Rails
7
+ class OutputBuffer < SimpleDelegator
8
+ def safe_append=(value)
9
+ return unless value
10
+
11
+ self << case value
12
+ when String then value
13
+ when Symbol then value.name
14
+ else value.to_s
15
+ end
16
+ end
17
+
18
+ def append=(value)
19
+ return unless value
20
+
21
+ if value.html_safe?
22
+ self.safe_append = value
23
+ else
24
+ self << case value
25
+ when String then CGI.escape_html(value)
26
+ when Symbol then CGI.escape_html(value.name)
27
+ else CGI.escape_html(value.to_s)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -17,18 +17,25 @@ module Phlex
17
17
  end
18
18
 
19
19
  def render_in(view_context, &block)
20
- output_buffer = view_context.output_buffer
21
-
22
- # Since https://github.com/rails/rails/pull/45731
23
- if output_buffer.respond_to?(:raw_buffer)
24
- buffer = output_buffer.raw_buffer
20
+ if block_given?
21
+ call(view_context: view_context) do |*args|
22
+ view_context.with_output_buffer(OutputBuffer.new(@_target)) 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
25
36
  else
26
- buffer = Buffer.new(output_buffer)
37
+ call(view_context: view_context).html_safe
27
38
  end
28
-
29
- call(buffer, view_context: view_context, &block)
30
-
31
- nil
32
39
  end
33
40
  end
34
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-24 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -125,11 +125,11 @@ files:
125
125
  - lib/install/phlex.rb
126
126
  - lib/phlex-rails.rb
127
127
  - lib/phlex/rails.rb
128
- - lib/phlex/rails/buffer.rb
129
128
  - lib/phlex/rails/engine.rb
130
129
  - lib/phlex/rails/form.rb
131
130
  - lib/phlex/rails/helpers.rb
132
131
  - lib/phlex/rails/layout.rb
132
+ - lib/phlex/rails/output_buffer.rb
133
133
  - lib/phlex/rails/renderable.rb
134
134
  - lib/phlex/rails/version.rb
135
135
  - lib/phlex/testing/rails.rb
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Rails
5
- # A wrapper for Rails’ OutputBuffer that acts like a Phlex buffer.
6
-
7
- class Buffer < SimpleDelegator
8
- def <<(value)
9
- __getobj__.safe_append = (value)
10
- self
11
- end
12
-
13
- def length
14
- __getobj__.length
15
- end
16
- end
17
- end
18
- end