async_partial 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/async_partial.gemspec +1 -1
- data/lib/async_partial.rb +28 -5
- data/lib/async_partial/handlers/haml.rb +1 -1
- data/lib/async_partial/railtie.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e3f473cfc5fd5ff51c3e13639a9d9587bef937399411e09adce13afacbfbad6
|
4
|
+
data.tar.gz: '08b1bca32156f113ca9e25df0663cb394ca5d96f06a71a999acad7cdbe5e7a63'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86784ee671514b6979a933ff56ee187aecc388915f2f203b833842e71b43548c7b2fb94b7a2f3621fe88d624f7f57fe8d8b82f1cc6a99b6dea15e82c174107cc
|
7
|
+
data.tar.gz: adef41e53bb93ea0019c771cab94ed7ac66fe0f33638ae67d70e0b0ed117b80ec36b84a1fb77c290e78bb9399a743044f9df5fffc10dd3570b4968c3a895965f
|
data/async_partial.gemspec
CHANGED
data/lib/async_partial.rb
CHANGED
@@ -13,6 +13,27 @@ module AsyncPartial
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
module CaptureHelper
|
17
|
+
def capture(*args, &block)
|
18
|
+
buf = block.binding.local_variable_get :output_buffer
|
19
|
+
value = nil
|
20
|
+
buffer = with_output_buffer(buf) { value = block.call(*args) }
|
21
|
+
if (string = buffer.presence || value) && string.is_a?(String)
|
22
|
+
ERB::Util.html_escape string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Simply rewind what's written in the buffer
|
27
|
+
def with_output_buffer(buf = nil) #:nodoc:
|
28
|
+
buffer_values_was = buf.buffer_values.clone
|
29
|
+
yield
|
30
|
+
buffer_values_was.each {|e| buf.buffer_values.shift if buf.buffer_values[0] == e}
|
31
|
+
buf.to_s
|
32
|
+
ensure
|
33
|
+
buf.buffer_values = buffer_values_was
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
16
37
|
class AsyncResult
|
17
38
|
def initialize(thread)
|
18
39
|
@thread = thread
|
@@ -38,31 +59,33 @@ module AsyncPartial
|
|
38
59
|
end
|
39
60
|
|
40
61
|
module ArrayBuffer
|
62
|
+
attr_accessor :buffer_values
|
63
|
+
|
41
64
|
def initialize(*)
|
42
65
|
super
|
43
|
-
@
|
66
|
+
@buffer_values = []
|
44
67
|
end
|
45
68
|
|
46
69
|
def <<(value)
|
47
|
-
@
|
70
|
+
@buffer_values << [value, :<<] unless value.nil?
|
48
71
|
self
|
49
72
|
end
|
50
73
|
alias :append= :<<
|
51
74
|
|
52
75
|
def safe_concat(value)
|
53
76
|
raise ActiveSupport::SafeBuffer::SafeConcatError unless html_safe?
|
54
|
-
@
|
77
|
+
@buffer_values << [value, :safe_concat] unless value.nil?
|
55
78
|
self
|
56
79
|
end
|
57
80
|
alias :safe_append= :safe_concat
|
58
81
|
|
59
82
|
def safe_expr_append=(val)
|
60
|
-
@
|
83
|
+
@buffer_values << [val, :safe_expr_append] unless val.nil?
|
61
84
|
self
|
62
85
|
end
|
63
86
|
|
64
87
|
def to_s
|
65
|
-
result = @
|
88
|
+
result = @buffer_values.each_with_object(ActiveSupport::SafeBuffer.new) do |(v, meth), buf|
|
66
89
|
if meth == :<<
|
67
90
|
if AsyncPartial::AsyncResult === v
|
68
91
|
buf << v.value
|
@@ -6,6 +6,7 @@ module AsyncPartial
|
|
6
6
|
ActiveSupport.on_load :action_view do
|
7
7
|
ActionView::PartialRenderer.prepend AsyncPartial::Renderer
|
8
8
|
ActionView::OutputBuffer.prepend AsyncPartial::ArrayBuffer
|
9
|
+
ActionView::Base.prepend AsyncPartial::CaptureHelper
|
9
10
|
|
10
11
|
begin
|
11
12
|
require 'action_view/template/handlers/erb/erubi'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_partial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.7.6
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Asynchronous partial renderer for Rails
|