async_partial 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 882b52321e8ff16c31b7d2bf2d1da62cefe0cdb110d991adb9ce2568ba376c4d
4
+ data.tar.gz: 606224d8511358400a66f00de2f5ffa0f2e475bf71b6421ae8f8c0877dace95a
5
+ SHA512:
6
+ metadata.gz: 0e04df603347440d1eef9e684288185b70f58f3e6fd5b44822398b007034be425d639cc68071a6a17ad777622f2ed02f9f58af3f4501ed3102830ce36ca3af6b
7
+ data.tar.gz: 4c752826a21b0bfa4c89de52d02479a8d68b9af2ce5ae2aa6882fbdc2997e567ff1850c9bae99652180a85985afcff404ded97171f58586dec14128db7a0747f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.6.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in async_partial.gemspec
6
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Akira Matsuda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # AsyncPartial
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/async_partial`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'async_partial'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install async_partial
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/amatsuda/async_partial.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "async_partial"
6
+ spec.version = '0.1.0'.freeze
7
+ spec.authors = ["Akira Matsuda"]
8
+ spec.email = ["ronnie@dio.jp"]
9
+
10
+ spec.summary = 'Asynchronous partial renderer for Rails'
11
+ spec.description = 'render asynchronously for the speed!'
12
+ spec.homepage = 'https://github.com/amatsuda/async_partial'
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency 'rails'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'minitest'
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "async_partial"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ class Template
5
+ module Handlers
6
+ class ERB
7
+ class ThreadSafeErubi < Erubi
8
+ def initialize(input, properties = {})
9
+ @newline_pending = 0
10
+
11
+ # Dup properties so that we don't modify argument
12
+ properties = Hash[properties]
13
+ properties[:preamble] = "output_buffer = ActionView::OutputBuffer.new;"
14
+ properties[:postamble] = "output_buffer.to_s"
15
+ properties[:bufvar] = "output_buffer"
16
+ properties[:escapefunc] = ""
17
+
18
+ # Call ::Erubi::Engine#initializer
19
+ method(__method__).super_method.super_method.call input, properties
20
+ end
21
+
22
+ private
23
+
24
+ eval Erubi.instance_method(:add_text).source.gsub('@output_buffer', '#{@bufvar}')
25
+ eval Erubi.instance_method(:add_expression).source.gsub('@output_buffer', '#{@bufvar}')
26
+ eval Erubi.instance_method(:flush_newline_if_pending).source.gsub('@output_buffer', '#{@bufvar}')
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AsyncPartial
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'async_partial' do
6
+ ActiveSupport.on_load :action_view do
7
+ ActionView::PartialRenderer.prepend AsyncPartial::Renderer
8
+ ActionView::OutputBuffer.prepend AsyncPartial::ArrayBuffer
9
+
10
+ begin
11
+ require 'action_view/template/handlers/erb/erubi'
12
+ require_relative 'handlers/erubi'
13
+
14
+ ActionView::Template::Handlers::ERB.erb_implementation = ActionView::Template::Handlers::ERB::ThreadSafeErubi
15
+ rescue LoadError
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'async_partial/railtie'
4
+
5
+ module AsyncPartial
6
+ module Renderer
7
+ def render(context, options, block)
8
+ if (options.delete(:async) || (options[:locals]&.delete(:async)))
9
+ AsyncResult.new(Thread.new { super })
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
15
+
16
+ class AsyncResult
17
+ def initialize(thread)
18
+ @thread = thread
19
+ end
20
+
21
+ def nil?
22
+ false
23
+ end
24
+
25
+ def to_s
26
+ val = @thread.value
27
+ @thread.kill
28
+ val
29
+ end
30
+ end
31
+
32
+ module ArrayBuffer
33
+ def initialize(*)
34
+ super
35
+ @values = []
36
+ @caller = caller[0]
37
+ end
38
+
39
+ def <<(value)
40
+ @values << [value, :<<] unless value.nil?
41
+ self
42
+ end
43
+ alias :append= :<<
44
+
45
+ def safe_concat(value)
46
+ raise ActiveSupport::SafeBuffer::SafeConcatError unless html_safe?
47
+ @values << [value, :safe_concat] unless value.nil?
48
+ self
49
+ end
50
+ alias :safe_append= :safe_concat
51
+
52
+ def safe_expr_append=(val)
53
+ @values << [val, :safe_expr_append] unless val.nil?
54
+ self
55
+ end
56
+
57
+ def to_s
58
+ result = @values.each_with_object(ActiveSupport::SafeBuffer.new) do |(v, meth), buf|
59
+ if meth == :<<
60
+ buf << v.to_s
61
+ else
62
+ buf.safe_concat(v.to_s)
63
+ end
64
+ end
65
+ result.to_s
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async_partial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akira Matsuda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: render asynchronously for the speed!
70
+ email:
71
+ - ronnie@dio.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - MIT-LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - async_partial.gemspec
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/async_partial.rb
86
+ - lib/async_partial/handlers/erubi.rb
87
+ - lib/async_partial/railtie.rb
88
+ homepage: https://github.com/amatsuda/async_partial
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.4
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Asynchronous partial renderer for Rails
112
+ test_files: []