async_partial 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/async_partial.gemspec +1 -1
- data/lib/async_partial.rb +33 -4
- data/lib/async_partial/handlers/erubi.rb +1 -1
- data/lib/async_partial/handlers/haml.rb +15 -0
- data/lib/async_partial/railtie.rb +29 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 166dac214e99eaf0c1740d70b233bdf4289ff06c2b53a7cf006ea5fa074d9833
|
4
|
+
data.tar.gz: a4dbfc18523e17f34c44d35fc974140f8d8dd21fc5ac340a7761db90f15c83e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bc6e8a27fd028a75cb9bdd25e9fcb0ed9c19ce8b4ff6c15e5482b3f672a91f8592fb5742c6de22c86a82c9bd93be09f6db0ad4cc7a90a3fae228c2171695e63
|
7
|
+
data.tar.gz: 531cee4e9c5426e8689e484de043cf57cd28bc1dc31c33afb20008ac242acf373a27ba08668e09ea0b6fea96f9b417bf9a64e54badcece812b8803b240143100
|
data/async_partial.gemspec
CHANGED
data/lib/async_partial.rb
CHANGED
@@ -3,9 +3,28 @@
|
|
3
3
|
require_relative 'async_partial/railtie'
|
4
4
|
|
5
5
|
module AsyncPartial
|
6
|
-
module
|
7
|
-
|
8
|
-
|
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 =
|
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
|
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::
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
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.
|
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-
|
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.
|
125
|
+
rubygems_version: 2.7.6
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Asynchronous partial renderer for Rails
|