phlex-rails 0.2.1 → 0.3.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: 28ff15970d3e9f51641fcf4739a1ce10cf7d026a3e11bacf88892372a5aa8180
4
- data.tar.gz: dcd2019092caec7c33a8fb837396d072b2894e13819074423c679a6555809f47
3
+ metadata.gz: a3e59108c4a90e8c202407fd7a154b9548060da6f3f561360ea8ed6b43b3f66b
4
+ data.tar.gz: 18b8485b72c7a435045033d8fa630c29a5fb79bb668432e45ecccf44372e807a
5
5
  SHA512:
6
- metadata.gz: f60d2e3e17bafb9d40ac0e7287346cd97146954e2a3901e45c82d5d937bea4eb9468d7d573bceff4043a7244834426a0cf8c35065027582901534c68e9e8911d
7
- data.tar.gz: 6b4141a6ffc3a44c294370ba17cf15a8e9d683e6beeae00fd1b7045f842820155d1c8de8e396892f991af4eec5ca5759012ca606009213dc30bdf727669ed9ab
6
+ metadata.gz: 2a23afd4cc366ad642d2eb8c3aaefcb9cdc4913a886439aefbfb729ff3afc547096fbd455a34b9f7f569edbf7e7708c36880b8ca1bd0a6965161e424a4ab9adf
7
+ data.tar.gz: de2e90c2da14ca3aa70dc0e265b8a3449a2cb6f25eb58e6fcadc37c2b88420ebcc61269553482bf487b2ccc3c946cfc1409c78ad5ed82dd6f7f5f0cc8a69ca93
@@ -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.3.0"
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.3.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: 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
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: 1.0.0.rc1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0.5'
29
+ version: 1.0.0.rc1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rails
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -125,11 +131,11 @@ files:
125
131
  - lib/install/phlex.rb
126
132
  - lib/phlex-rails.rb
127
133
  - lib/phlex/rails.rb
128
- - lib/phlex/rails/buffer.rb
129
134
  - lib/phlex/rails/engine.rb
130
135
  - lib/phlex/rails/form.rb
131
136
  - lib/phlex/rails/helpers.rb
132
137
  - lib/phlex/rails/layout.rb
138
+ - lib/phlex/rails/output_buffer.rb
133
139
  - lib/phlex/rails/renderable.rb
134
140
  - lib/phlex/rails/version.rb
135
141
  - 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