render_async 2.1.3 → 2.1.8

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.
@@ -1,10 +1,12 @@
1
1
  module RenderAsync
2
2
  class Configuration
3
- attr_accessor :jquery, :turbolinks
3
+ attr_accessor :jquery, :turbolinks, :replace_container, :nonces
4
4
 
5
5
  def initialize
6
6
  @jquery = false
7
7
  @turbolinks = false
8
+ @replace_container = true
9
+ @nonces = false
8
10
  end
9
11
  end
10
12
  end
@@ -1,3 +1,3 @@
1
1
  module RenderAsync
2
- VERSION = "2.1.3".freeze
2
+ VERSION = "2.1.8".freeze
3
3
  end
@@ -2,7 +2,6 @@ require 'securerandom'
2
2
 
3
3
  module RenderAsync
4
4
  module ViewHelper
5
-
6
5
  def render_async_cache_key(path)
7
6
  "render_async_#{path}"
8
7
  end
@@ -20,18 +19,17 @@ module RenderAsync
20
19
  def render_async(path, options = {}, &placeholder)
21
20
  event_name = options.delete(:event_name)
22
21
  placeholder = capture(&placeholder) if block_given?
23
- retry_count = options.delete(:retry_count) || 0
24
- html_options = options.delete(:html_options) || {}
25
22
 
26
23
  render 'render_async/render_async', **container_element_options(options),
27
24
  path: path,
28
- html_options: html_options,
25
+ html_options: html_options(options),
29
26
  event_name: event_name,
30
27
  placeholder: placeholder,
31
28
  **request_options(options),
32
29
  **error_handling_options(options),
33
- retry_count: retry_count,
34
- **polling_options(options)
30
+ **retry_options(options),
31
+ **polling_options(options),
32
+ **content_for_options(options)
35
33
  end
36
34
 
37
35
  private
@@ -39,7 +37,16 @@ module RenderAsync
39
37
  def container_element_options(options)
40
38
  { html_element_name: options[:html_element_name] || 'div',
41
39
  container_id: options[:container_id] || generate_container_id,
42
- container_class: options[:container_class] }
40
+ container_class: options[:container_class],
41
+ replace_container: replace_container(options) }
42
+ end
43
+
44
+ def html_options(options)
45
+ set_options = options.delete(:html_options) || {}
46
+
47
+ set_options[:nonce] = config.nonces if set_options[:nonce].nil?
48
+
49
+ set_options
43
50
  end
44
51
 
45
52
  def request_options(options)
@@ -53,15 +60,36 @@ module RenderAsync
53
60
  error_event_name: options[:error_event_name] }
54
61
  end
55
62
 
63
+ def retry_options(options)
64
+ {
65
+ retry_count: options.delete(:retry_count) || 0,
66
+ retry_delay: options.delete(:retry_delay)
67
+ }
68
+ end
69
+
56
70
  def polling_options(options)
57
71
  { interval: options[:interval],
58
72
  toggle: options[:toggle] }
59
73
  end
60
74
 
61
- private
75
+ def content_for_options(options)
76
+ {
77
+ content_for_name: options[:content_for_name] || :render_async
78
+ }
79
+ end
62
80
 
63
81
  def generate_container_id
64
82
  "render_async_#{SecureRandom.hex(5)}#{Time.now.to_i}"
65
83
  end
84
+
85
+ def replace_container(options)
86
+ return options[:replace_container] unless options[:replace_container].nil?
87
+
88
+ config.replace_container
89
+ end
90
+
91
+ def config
92
+ RenderAsync.configuration
93
+ end
66
94
  end
67
95
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_async
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Grubbe
8
8
  - nikolalsvk
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-10-19 00:00:00.000000000 Z
12
+ date: 2020-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".all-contributorsrc"
64
+ - ".github/FUNDING.yml"
64
65
  - ".gitignore"
65
66
  - ".gitmodules"
66
67
  - ".rspec"
@@ -85,7 +86,7 @@ homepage: https://github.com/renderedtext/render_async
85
86
  licenses:
86
87
  - MIT
87
88
  metadata: {}
88
- post_install_message:
89
+ post_install_message:
89
90
  rdoc_options: []
90
91
  require_paths:
91
92
  - lib
@@ -100,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.7.6
105
- signing_key:
104
+ rubygems_version: 3.0.3
105
+ signing_key:
106
106
  specification_version: 4
107
107
  summary: Render parts of the page asynchronously with AJAX
108
108
  test_files: []