async_partial 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b4cfe73def23ff520e039aad9da34c207484733a
4
- data.tar.gz: 6fd1b502c56739617144e5178eaf8238f752eddf
2
+ SHA256:
3
+ metadata.gz: 3e3f473cfc5fd5ff51c3e13639a9d9587bef937399411e09adce13afacbfbad6
4
+ data.tar.gz: '08b1bca32156f113ca9e25df0663cb394ca5d96f06a71a999acad7cdbe5e7a63'
5
5
  SHA512:
6
- metadata.gz: 75bf09f809d80b7d4c9635a6b9141106f1f04d87165ab80b243fe4125d4ff04692968b9f6affc29f32465140cd07fbcb0b123b6adff6f230718211f0e48add11
7
- data.tar.gz: 9b298e91f8b4574fc914c68e4d2c7a2ff7f41de29e54f90f6b6388147e8effc2e69aa799991990e1c0b8402889e05a23fcc2d3c971a37a9f7126c2a7a19f9d21
6
+ metadata.gz: 86784ee671514b6979a933ff56ee187aecc388915f2f203b833842e71b43548c7b2fb94b7a2f3621fe88d624f7f57fe8d8b82f1cc6a99b6dea15e82c174107cc
7
+ data.tar.gz: adef41e53bb93ea0019c771cab94ed7ac66fe0f33638ae67d70e0b0ed117b80ec36b84a1fb77c290e78bb9399a743044f9df5fffc10dd3570b4968c3a895965f
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "async_partial"
6
- spec.version = '0.3.0'.freeze
6
+ spec.version = '0.4.0'.freeze
7
7
  spec.authors = ["Akira Matsuda"]
8
8
  spec.email = ["ronnie@dio.jp"]
9
9
 
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
- @values = []
66
+ @buffer_values = []
44
67
  end
45
68
 
46
69
  def <<(value)
47
- @values << [value, :<<] unless value.nil?
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
- @values << [value, :safe_concat] unless value.nil?
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
- @values << [val, :safe_expr_append] unless val.nil?
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 = @values.each_with_object(ActiveSupport::SafeBuffer.new) do |(v, meth), buf|
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
@@ -9,7 +9,7 @@ module AsyncPartial
9
9
 
10
10
  module HamlArrayBufferizer
11
11
  def initialize(*)
12
- super;
12
+ super
13
13
  @buffer = AsyncPartial::HamlArrayBuffer.new
14
14
  end
15
15
  end
@@ -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.3.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-06 00:00:00.000000000 Z
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.5.2.2
110
+ rubygems_version: 2.7.6
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Asynchronous partial renderer for Rails