tastebook-respond_to_parent 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/respond_to_parent.rb +13 -0
- data/lib/respond_to_parent/action_controller_methods.rb +49 -0
- data/lib/respond_to_parent/version.rb +3 -0
- data/respond_to_parent.gemspec +21 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Max Gonzih
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# RespondToParent
|
2
|
+
|
3
|
+
respond_to_parent for rails ~> 3.2
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'respond_to_parent'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install respond_to_parent
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add `gem 'respond_to_parent', github: 'Gonzih/respond_to_parent'` to your `Gemfile`.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'respond_to_parent/version'
|
3
|
+
require 'respond_to_parent/action_controller_methods'
|
4
|
+
|
5
|
+
module RespondToParent
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer 'respond_to_parent.initializer' do
|
8
|
+
ActiveSupport.on_load(:action_controller) do
|
9
|
+
include RespondToParent::ActionControllerMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RespondToParent
|
2
|
+
# Module containing the methods useful for child IFRAME to parent window communication
|
3
|
+
module ActionControllerMethods
|
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
|
8
|
+
yield
|
9
|
+
|
10
|
+
if performed?
|
11
|
+
# We're returning HTML instead of JS or XML now
|
12
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
13
|
+
|
14
|
+
# Either pull out a redirect or the request body
|
15
|
+
script = if response.headers['Location']
|
16
|
+
#TODO: erase_redirect_results is missing in rails 3.0 has to be implemented
|
17
|
+
# erase redirect
|
18
|
+
"document.location.href = #{location.to_s.inspect}"
|
19
|
+
else
|
20
|
+
response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
# Escape quotes, linebreaks and slashes, maintaining previously escaped slashes
|
24
|
+
# Suggestions for improvement?
|
25
|
+
script = (script || '').
|
26
|
+
gsub('\\', '\\\\\\').
|
27
|
+
gsub(/\r\n|\r|\n/, '\\n').
|
28
|
+
gsub(/['"]/, '\\\\\&').
|
29
|
+
gsub('</script>','</scr"+"ipt>')
|
30
|
+
|
31
|
+
# Clear out the previous render to prevent double render
|
32
|
+
@_response_body = nil
|
33
|
+
|
34
|
+
# Eval in parent scope and replace document location of this frame
|
35
|
+
# so back button doesn't replay action on targeted forms
|
36
|
+
# loc = document.location to be set after parent is updated for IE
|
37
|
+
# with(window.parent) - pull in variables from parent window
|
38
|
+
# setTimeout - scope the execution in the windows parent for safari
|
39
|
+
# window.eval - legal eval for Opera
|
40
|
+
render :text => "<html><body><script type='text/javascript' charset='utf-8'>
|
41
|
+
var loc = document.location;
|
42
|
+
with(window.parent) { setTimeout(function() { window.eval('#{script}'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };
|
43
|
+
</script></body></html>".html_safe
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
alias respond_to_parent responds_to_parent
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'respond_to_parent/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "tastebook-respond_to_parent"
|
8
|
+
gem.version = RespondToParent::VERSION
|
9
|
+
gem.authors = ["Max Gonzih"]
|
10
|
+
gem.email = ["gonzih@gmail.com"]
|
11
|
+
gem.description = %q{respond_to_parent for Rails 3}
|
12
|
+
gem.summary = %q{respond_to_parent gem ported for Rails >3}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.add_dependency 'rails', '~> 3.2'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tastebook-respond_to_parent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Max Gonzih
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2013-04-22 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "3.2"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: respond_to_parent for Rails 3
|
27
|
+
email:
|
28
|
+
- gonzih@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/respond_to_parent.rb
|
42
|
+
- lib/respond_to_parent/action_controller_methods.rb
|
43
|
+
- lib/respond_to_parent/version.rb
|
44
|
+
- respond_to_parent.gemspec
|
45
|
+
homepage: ""
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.21
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: respond_to_parent gem ported for Rails >3
|
72
|
+
test_files: []
|
73
|
+
|