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 +4 -4
- data/lib/generators/phlex/view/view_generator.rb +1 -1
- data/lib/phlex/rails/output_buffer.rb +33 -0
- data/lib/phlex/rails/renderable.rb +17 -10
- data/lib/phlex/rails/version.rb +1 -1
- metadata +3 -3
- data/lib/phlex/rails/buffer.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d270dd49cf94953641c2f7987f05c3a4904b3e6c39983884b6c6dca60bd89a78
|
4
|
+
data.tar.gz: ee571c67532384b55c641777c42d295820f3ec00b5a48fb8bb3b331f3539009d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8bdc497af4542412f8addfda2b7cdb3602448df6867010a2352d7ed66e862073eb3cce54167ddf1cda8d8f7ad5a7f528f6a90987ad51107987fe7dcced8074b
|
7
|
+
data.tar.gz: 597a9cd87505991851beeaa69a3c41453b476a0e4d7b5709d8a3b6c9ab7ddd5df5b50bfe2a673c6c9ec62ba5c0bc2aa822315f8be5dec62cbf1e96fc9bcd8b8c
|
@@ -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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
data/lib/phlex/rails/version.rb
CHANGED
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.
|
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-
|
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
|
data/lib/phlex/rails/buffer.rb
DELETED
@@ -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
|