responds_to_parent2 2.1.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
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59ca39231c17e7cbae29f6fa81066418b222f3286531554f6e47cab3e6807a80
|
4
|
+
data.tar.gz: e46cafe5c5d79bb1aa607bfd28d60ae0882c25fc3b07cd4ad9a1b9682a276758
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a04d5d41372ad1ec6c135030785fe6bdab1bdab32180f6877e7dda8982748018e2e64e13c8a84ab0fd93130a8b9e61dd577432f44de29eb3b40466184064393
|
7
|
+
data.tar.gz: 83cb9692536b08e38666d3aae4de700eb6807dddb5990f4b42154c9ae3082d02d94587e6d71c70da30c85fed01bfbfd8aab92e80f2bcb727cf01330b651c3fb8
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RespondsToParent
|
2
|
+
# Module containing the methods useful for child IFRAME to parent window communication
|
3
|
+
module ActionController
|
4
|
+
# Executes the response body as JavaScript in the context of the parent window.
|
5
|
+
# Use this method of you are posting a form to a hidden IFRAME or if you would like
|
6
|
+
# to use IFRAME base RPC.
|
7
|
+
def responds_to_parent(&block)
|
8
|
+
yield
|
9
|
+
|
10
|
+
if performed?
|
11
|
+
# Either pull out a redirect or the request body
|
12
|
+
script = if response.headers['Location']
|
13
|
+
#TODO: erase_redirect_results is missing in rails 3.0
|
14
|
+
"document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
|
15
|
+
else
|
16
|
+
response.body || ''
|
17
|
+
end
|
18
|
+
|
19
|
+
# Eval in parent scope and replace document location of this frame
|
20
|
+
# so back button doesn't replay action on targeted forms
|
21
|
+
# loc = document.location to be set after parent is updated for IE
|
22
|
+
# with(window.parent) - pull in variables from parent window
|
23
|
+
# setTimeout - scope the execution in the windows parent for safari
|
24
|
+
# window.eval - legal eval for Opera
|
25
|
+
script = "<html><body><script type='text/javascript' charset='utf-8'>
|
26
|
+
var loc = document.location;
|
27
|
+
with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
|
28
|
+
</script></body></html>"
|
29
|
+
|
30
|
+
# We're returning HTML instead of JS or XML now
|
31
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
32
|
+
|
33
|
+
# Clear out the previous render to prevent double render and then render
|
34
|
+
if respond_to?(:erase_results, true)
|
35
|
+
erase_results
|
36
|
+
else
|
37
|
+
instance_variable_set(:@_response_body, nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
render :text => script
|
41
|
+
end
|
42
|
+
end
|
43
|
+
alias respond_to_parent responds_to_parent
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RespondsToParent
|
2
|
+
module SelectorAssertion
|
3
|
+
# :call-seq:
|
4
|
+
# assert_select_parent()
|
5
|
+
# assert_select_parent() { |script| ... }
|
6
|
+
#
|
7
|
+
# Selects JavaScript that is generated for the `parent' window.
|
8
|
+
#
|
9
|
+
# Without a block, #assert_select_parent asserts that the response
|
10
|
+
# is generated by responds_to_parent.
|
11
|
+
#
|
12
|
+
# With a block, #assert_select_parent selects script that is supposed
|
13
|
+
# to be evaluated in the parent window and passes it to the block.
|
14
|
+
# Typically #assert_select_rjs is used in the block.
|
15
|
+
def assert_select_parent(*args, &block)
|
16
|
+
wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
|
17
|
+
"(.*)" +
|
18
|
+
Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
|
19
|
+
match = @response.body.match(Regexp.new(wrapper_re_str))
|
20
|
+
|
21
|
+
if match
|
22
|
+
escaped_js = match[1]
|
23
|
+
unescaped_js = escaped_js.
|
24
|
+
gsub(%r!</scr"\+"ipt>!, '</script>').
|
25
|
+
gsub(/\\(\'|\")/, '\1').
|
26
|
+
gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
|
27
|
+
gsub(/\\\\/, '\\')
|
28
|
+
@response.body = unescaped_js # assert_select_rjs refers @response.body.
|
29
|
+
|
30
|
+
if block_given?
|
31
|
+
begin
|
32
|
+
in_scope, @selected = @selected, unescaped_js
|
33
|
+
yield unescaped_js
|
34
|
+
ensure
|
35
|
+
@selected = in_scope
|
36
|
+
end
|
37
|
+
end
|
38
|
+
unescaped_js
|
39
|
+
else
|
40
|
+
# doesn't seem a responds_to_parent content.
|
41
|
+
flunk args.shift || "No content for the parent window."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'responds_to_parent/action_controller'
|
2
|
+
require 'responds_to_parent/selector_assertion'
|
3
|
+
|
4
|
+
ActionController::Base.include RespondsToParent::ActionController
|
5
|
+
|
6
|
+
where_to_include = [ActionController::TestCase]
|
7
|
+
if defined?(ActionDispatch::Assertions::SelectorAssertions)
|
8
|
+
where_to_include << ActionDispatch::Assertions::SelectorAssertions
|
9
|
+
else
|
10
|
+
where_to_include << Rails::Dom::Testing::Assertions::SelectorAssertions
|
11
|
+
end
|
12
|
+
where_to_include.each do |to_include|
|
13
|
+
to_include.include RespondsToParent::SelectorAssertion
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: responds_to_parent2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Grosser
|
8
|
+
- Pierre Schambacher
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.22
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.22
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8.0'
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/responds_to_parent.rb
|
38
|
+
- lib/responds_to_parent/action_controller.rb
|
39
|
+
- lib/responds_to_parent/selector_assertion.rb
|
40
|
+
- lib/responds_to_parent/version.rb
|
41
|
+
homepage: https://github.com/zendesk/responds_to_parent
|
42
|
+
licenses: []
|
43
|
+
metadata: {}
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.6.2
|
59
|
+
specification_version: 4
|
60
|
+
summary: "[Rails] Adds 'responds_to_parent' to your controller to respond to the parent
|
61
|
+
document of your page.Make Ajaxy file uploads by posting the form to a hidden iframe,
|
62
|
+
and respond with RJS to the parent window."
|
63
|
+
test_files: []
|