async_partial 0.6.0 → 0.7.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
2
  SHA256:
3
- metadata.gz: a4c400883e8ff1cec0398606d334935122be82c6a36dd368830fcd74ec6e2deb
4
- data.tar.gz: 73556843fd3b3e53e90e98d50674b29b3efd94174511fc6b3081b32a7b93d203
3
+ metadata.gz: 166dac214e99eaf0c1740d70b233bdf4289ff06c2b53a7cf006ea5fa074d9833
4
+ data.tar.gz: a4dbfc18523e17f34c44d35fc974140f8d8dd21fc5ac340a7761db90f15c83e2
5
5
  SHA512:
6
- metadata.gz: d4f82a499e4066ada256ea3b65e3e03064b43b397ac9371798caa9c1832c945685aac19a95a90753307637a8d84eeee4d4ddb78e4bf4623a6ac983b0279c1562
7
- data.tar.gz: 120d2080bd0bbeb307bdf4e77fcbd0a495b0b5d20d50454c2c6efaeaaba6eb778333657bf9802c1fa272abae107b180b9e5d541f987a7202b99f2289bda7d04b
6
+ metadata.gz: 8bc6e8a27fd028a75cb9bdd25e9fcb0ed9c19ce8b4ff6c15e5482b3f672a91f8592fb5742c6de22c86a82c9bd93be09f6db0ad4cc7a90a3fae228c2171695e63
7
+ data.tar.gz: 531cee4e9c5426e8689e484de043cf57cd28bc1dc31c33afb20008ac242acf373a27ba08668e09ea0b6fea96f9b417bf9a64e54badcece812b8803b240143100
@@ -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.6.0'.freeze
6
+ spec.version = '0.7.0'.freeze
7
7
  spec.authors = ["Akira Matsuda"]
8
8
  spec.email = ["ronnie@dio.jp"]
9
9
 
@@ -3,9 +3,28 @@
3
3
  require_relative 'async_partial/railtie'
4
4
 
5
5
  module AsyncPartial
6
- module Renderer
7
- def render(context, options, block)
8
- if (options.delete(:async) || (options[:locals]&.delete(:async)))
6
+ module PartialRenderer
7
+ private
8
+
9
+ def render_partial
10
+ if @locals.delete :async
11
+ AsyncResult.new(Thread.new { super })
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ def collection_with_template
18
+ super.map do |v|
19
+ v.value if AsyncPartial::AsyncResult === v
20
+ end
21
+ end
22
+ end
23
+
24
+ module CollectionPartialTemplateRenderer
25
+ def render(view, locals, buffer = nil, &block)
26
+ locals = locals.dup
27
+ if locals.delete :async
9
28
  AsyncResult.new(Thread.new { super })
10
29
  else
11
30
  super
@@ -13,9 +32,19 @@ module AsyncPartial
13
32
  end
14
33
  end
15
34
 
35
+ module PerThreadBufferStack
36
+ def render(view, locals, buffer = nil, &block)
37
+ buffer ||= ActionView::OutputBuffer.new
38
+ (Thread.current[:output_buffers] ||= []).push buffer
39
+ result = super
40
+ Thread.current[:output_buffers].pop
41
+ result
42
+ end
43
+ end
44
+
16
45
  module CaptureHelper
17
46
  def capture(*args, &block)
18
- buf = block.binding.local_variable_get :output_buffer
47
+ buf = Thread.current[:output_buffers].last
19
48
  value = nil
20
49
  buffer = with_output_buffer(buf) { value = block.call(*args) }
21
50
  if (string = buffer.presence || value) && string.is_a?(String)
@@ -10,7 +10,7 @@ module ActionView
10
10
 
11
11
  # Dup properties so that we don't modify argument
12
12
  properties = Hash[properties]
13
- properties[:preamble] = "output_buffer = ActionView::OutputBuffer.new;"
13
+ properties[:preamble] = "output_buffer ||= ActionView::OutputBuffer.new;"
14
14
  properties[:postamble] = "output_buffer.to_s"
15
15
  properties[:bufvar] = "output_buffer"
16
16
  properties[:escapefunc] = ""
@@ -5,6 +5,21 @@ module AsyncPartial
5
5
  def html_safe
6
6
  map {|v| AsyncPartial::AsyncResult === v ? v.value : v}.join.html_safe
7
7
  end
8
+
9
+ def rstrip!
10
+ if last.frozen?
11
+ if (stripped = last.dup.rstrip!)
12
+ self[-1] = stripped
13
+ end
14
+ else
15
+ last.rstrip!
16
+ end
17
+ if last.blank?
18
+ last.pop
19
+ rstrip!
20
+ end
21
+ self
22
+ end
8
23
  end
9
24
 
10
25
  module HamlArrayBufferizer
@@ -4,9 +4,11 @@ module AsyncPartial
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer 'async_partial' do
6
6
  ActiveSupport.on_load :action_view do
7
- ActionView::PartialRenderer.prepend AsyncPartial::Renderer
7
+ ActionView::PartialRenderer.prepend AsyncPartial::PartialRenderer
8
8
  ActionView::OutputBuffer.prepend AsyncPartial::ArrayBuffer
9
9
  ActionView::Base.prepend AsyncPartial::CaptureHelper
10
+ ActionView::Template.prepend AsyncPartial::PerThreadBufferStack
11
+ ActionView::Template.prepend AsyncPartial::CollectionPartialTemplateRenderer
10
12
 
11
13
  begin
12
14
  require 'action_view/template/handlers/erb/erubi'
@@ -23,18 +25,35 @@ module AsyncPartial
23
25
  raise 'No Erubi nor Erubis found.'
24
26
  end
25
27
  end
28
+ end
29
+ end
26
30
 
27
- if Gem.loaded_specs.detect {|g| g[0] == 'haml'}
28
- require 'haml/buffer'
29
- require_relative 'handlers/haml'
30
- end
31
+ if Gem.loaded_specs.detect {|g| g[0] == 'haml'}
32
+ initializer 'async_partial_haml', after: :haml do
33
+ require 'haml/buffer'
34
+ require_relative 'handlers/haml'
35
+ end
36
+ end
31
37
 
32
- if Gem.loaded_specs.detect {|g| g[0] == 'slim'}
33
- require 'temple/generators/rails_output_buffer'
34
- require_relative 'handlers/slim'
38
+ if Gem.loaded_specs.detect {|g| g[0] == 'slim'}
39
+ initializer 'async_partial_slim', after: 'slim_rails.configure_template_digestor' do
40
+ require 'temple'
41
+ require 'slim'
42
+ require 'temple/generators/rails_output_buffer'
43
+ require_relative 'handlers/slim'
35
44
 
36
- Temple::Templates::Rails(Slim::Engine, register_as: :slim, generator: Temple::Generators::ThreadedRailsOutputBuffer, disable_capture: true, streaming: true)
37
- end
45
+ Temple::Templates::Rails(Slim::Engine, register_as: :slim, generator: Temple::Generators::ThreadedRailsOutputBuffer, disable_capture: true, streaming: true)
46
+ end
47
+ end
48
+
49
+ if Gem.loaded_specs.detect {|g| g[0] == 'faml'}
50
+ initializer 'async_partial_faml', after: :faml do
51
+ require 'temple'
52
+ require 'temple/generators/rails_output_buffer'
53
+ require_relative 'handlers/slim'
54
+
55
+ ActionView::Template.register_template_handler(:haml, ->(template) { Faml::Engine.new(use_html_safe: true, generator: Temple::Generators::ThreadedRailsOutputBuffer, filename: template.identifier).call(template.source) })
56
+ ActionView::Template.register_template_handler(:faml, ->(template) { Faml::Engine.new(use_html_safe: true, generator: Temple::Generators::ThreadedRailsOutputBuffer, filename: template.identifier).call(template.source) })
38
57
  end
39
58
  end
40
59
  end
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.6.0
4
+ version: 0.7.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-09 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.7.4
125
+ rubygems_version: 2.7.6
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Asynchronous partial renderer for Rails