Permalink
Browse files

Restructuring the gem paths to be cleaner before pushing it to gemcut…

…ter.
  • Loading branch information...
markcatley committed Oct 13, 2009
1 parent 0d5c77d commit 840ada34d79b7bb0c1aaae894ac3901fdccba95c
View
@@ -1,2 +1 @@
-ActionController::Base.send :include, RespondsToParent
-require 'parent_selector_assertion'
+require 'responds_to_parent'
@@ -1,144 +0,0 @@
-module ActionController
- module Assertions
- module SelectorAssertions
- # :call-seq:
- # assert_select_parent()
- # assert_select_parent() { |script| ... }
- #
- # Selects JavaScript that is generated for the `parent' window.
- #
- # Without a block, #assert_select_parent asserts that the response
- # is generated by responds_to_parent.
- #
- # With a block, #assert_select_parent selects script that is supposed
- # to be evaluated in the parent window and passes it to the block.
- # Typically #assert_select_rjs is used in the block.
- def assert_select_parent(*args, &block)
- wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
- "(.*)" +
- Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
- match = @response.body.match(Regexp.new(wrapper_re_str))
-
- if match
- escaped_js = match[1]
- unescaped_js = escaped_js.
- gsub(%r!</scr"\+"ipt>!, '</script>').
- gsub(/\\(\'|\")/, '\1').
- gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
- gsub(/\\\\/, '\\')
- @response.body = unescaped_js # assert_select_rjs refers @response.body.
-
- if block_given?
- begin
- in_scope, @selected = @selected, unescaped_js
- yield unescaped_js
- ensure
- @selected = in_scope
- end
- end
- unescaped_js
- else
- # doesn't seem a responds_to_parent content.
- flunk args.shift || "No content for the parent window."
- end
- end
- end
- end
-end
-
-module ActionController
- module Assertions
- module SelectorAssertions
- # :call-seq:
- # assert_select_parent()
- # assert_select_parent() { |script| ... }
- #
- # Selects JavaScript that is generated for the `parent' window.
- #
- # Without a block, #assert_select_parent asserts that the response
- # is generated by responds_to_parent.
- #
- # With a block, #assert_select_parent selects script that is supposed
- # to be evaluated in the parent window and passes it to the block.
- # Typically #assert_select_rjs is used in the block.
- def assert_select_parent(*args, &block)
- wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
- "(.*)" +
- Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
- match = @response.body.match(Regexp.new(wrapper_re_str))
-
- if match
- escaped_js = match[1]
- unescaped_js = escaped_js.
- gsub(%r!</scr"\+"ipt>!, '</script>').
- gsub(/\\(\'|\")/, '\1').
- gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
- gsub(/\\\\/, '\\')
- @response.body = unescaped_js # assert_select_rjs refers @response.body.
-
- if block_given?
- begin
- in_scope, @selected = @selected, unescaped_js
- yield unescaped_js
- ensure
- @selected = in_scope
- end
- end
- unescaped_js
- else
- # doesn't seem a responds_to_parent content.
- flunk args.shift || "No content for the parent window."
- end
- end
- end
- end
-end
-
-module ActionController
- module Assertions
- module SelectorAssertions
- # :call-seq:
- # assert_select_parent()
- # assert_select_parent() { |script| ... }
- #
- # Selects JavaScript that is generated for the `parent' window.
- #
- # Without a block, #assert_select_parent asserts that the response
- # is generated by responds_to_parent.
- #
- # With a block, #assert_select_parent selects script that is supposed
- # to be evaluated in the parent window and passes it to the block.
- # Typically #assert_select_rjs is used in the block.
- def assert_select_parent(*args, &block)
- wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
- "(.*)" +
- Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
- match = @response.body.match(Regexp.new(wrapper_re_str))
-
- if match
- escaped_js = match[1]
- unescaped_js = escaped_js.
- gsub(%r!</scr"\+"ipt>!, '</script>').
- gsub(/\\(\'|\")/, '\1').
- gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
- gsub(/\\\\/, '\\')
- @response.body = unescaped_js # assert_select_rjs refers @response.body.
-
- if block_given?
- begin
- in_scope, @selected = @selected, unescaped_js
- yield unescaped_js
- ensure
- @selected = in_scope
- end
- end
- unescaped_js
- else
- # doesn't seem a responds_to_parent content.
- flunk args.shift || "No content for the parent window."
- end
- end
- end
- end
-end
-
View
@@ -1,37 +1,16 @@
-# Module containing the methods useful for child IFRAME to parent window communication
-module RespondsToParent
- # Executes the response body as JavaScript in the context of the parent window.
- # Use this method of you are posting a form to a hidden IFRAME or if you would like
- # to use IFRAME base RPC.
- def responds_to_parent(&block)
- yield
-
- if performed?
- # Either pull out a redirect or the request body
- script = if location = erase_redirect_results
- "document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
- else
- response.body || ''
- end
+require 'responds_to_parent/action_controller'
+require 'responds_to_parent/selector_assertion'
- # Clear out the previous render to prevent double render
- erase_results
-
- # We're returning HTML instead of JS or XML now
- response.headers['Content-Type'] = 'text/html; charset=UTF-8'
-
- # Eval in parent scope and replace document location of this frame
- # so back button doesn't replay action on targeted forms
- # loc = document.location to be set after parent is updated for IE
- # with(window.parent) - pull in variables from parent window
- # setTimeout - scope the execution in the windows parent for safari
- # window.eval - legal eval for Opera
- render :text => "<html><body><script type='text/javascript' charset='utf-8'>
- var loc = document.location;
- with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
- </script></body></html>"
- end
+module ActionController
+ class Base
+ include RespondsToParent::ActionController
end
- alias respond_to_parent responds_to_parent
end
+module ActionController
+ module Assertions
+ module SelectorAssertions
+ include RespondsToParent::SelectorAssertion
+ end
+ end
+end
@@ -0,0 +1,38 @@
+module RespondsToParent
+ # Module containing the methods useful for child IFRAME to parent window communication
+ module ActionController
+ # Executes the response body as JavaScript in the context of the parent window.
+ # Use this method of you are posting a form to a hidden IFRAME or if you would like
+ # to use IFRAME base RPC.
+ def responds_to_parent(&block)
+ yield
+
+ if performed?
+ # Either pull out a redirect or the request body
+ script = if location = erase_redirect_results
+ "document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
+ else
+ response.body || ''
+ end
+
+ # Clear out the previous render to prevent double render
+ erase_results
+
+ # We're returning HTML instead of JS or XML now
+ response.headers['Content-Type'] = 'text/html; charset=UTF-8'
+
+ # Eval in parent scope and replace document location of this frame
+ # so back button doesn't replay action on targeted forms
+ # loc = document.location to be set after parent is updated for IE
+ # with(window.parent) - pull in variables from parent window
+ # setTimeout - scope the execution in the windows parent for safari
+ # window.eval - legal eval for Opera
+ render :text => "<html><body><script type='text/javascript' charset='utf-8'>
+ var loc = document.location;
+ with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
+ </script></body></html>"
+ end
+ end
+ alias respond_to_parent responds_to_parent
+ end
+end
@@ -0,0 +1,45 @@
+module RespondsToParent
+ module SelectorAssertion
+ # :call-seq:
+ # assert_select_parent()
+ # assert_select_parent() { |script| ... }
+ #
+ # Selects JavaScript that is generated for the `parent' window.
+ #
+ # Without a block, #assert_select_parent asserts that the response
+ # is generated by responds_to_parent.
+ #
+ # With a block, #assert_select_parent selects script that is supposed
+ # to be evaluated in the parent window and passes it to the block.
+ # Typically #assert_select_rjs is used in the block.
+ def assert_select_parent(*args, &block)
+ wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
+ "(.*)" +
+ Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
+ match = @response.body.match(Regexp.new(wrapper_re_str))
+
+ if match
+ escaped_js = match[1]
+ unescaped_js = escaped_js.
+ gsub(%r!</scr"\+"ipt>!, '</script>').
+ gsub(/\\(\'|\")/, '\1').
+ gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
+ gsub(/\\\\/, '\\')
+ @response.body = unescaped_js # assert_select_rjs refers @response.body.
+
+ if block_given?
+ begin
+ in_scope, @selected = @selected, unescaped_js
+ yield unescaped_js
+ ensure
+ @selected = in_scope
+ end
+ end
+ unescaped_js
+ else
+ # doesn't seem a responds_to_parent content.
+ flunk args.shift || "No content for the parent window."
+ end
+ end
+ end
+end
View
@@ -1,2 +0,0 @@
-ActionController::Base.send :include, RespondsToParent
-require 'parent_selector_assertion'
@@ -1,15 +1,16 @@
spec = Gem::Specification.new do |s|
- s.name = 'responds-to-parent'
- s.version = '1.0.20090923'
- s.homepage = 'http://constancy.rubyforge.org/'
+ s.name = 'responds_to_parent'
+ s.version = '1.0.20091013'
+ s.homepage = 'http://github.com/markcatley/responds_to_parent'
s.summary = "[Rails] Adds 'responds_to_parent' to your controller to" +
- 'respond to the parent document of your page.'
+ 'respond to the parent document of your page.' +
'Make Ajaxy file uploads by posting the form to a hidden' +
'iframe, and respond with RJS to the parent window.'
- s.files = %w( README Rakefile MIT-LICENSE rails/init.rb
+ s.files = %w( README Rakefile MIT-LICENSE
lib/responds_to_parent.rb
- lib/parent_selector_assertion.rb
+ lib/responds_to_parent/action_controller.rb
+ lib/responds_to_parent/selector_assertion.rb
test/responds_to_parent_test.rb
test/assert_select_parent_test.rb)
end

1 comment on commit 840ada3

@oivoodoo

This comment has been minimized.

Show comment Hide comment
@oivoodoo

oivoodoo May 15, 2012

Hi.

Could you push the current version of the 'responds_to_parent' to the rubygems? Because now in the rubygems the latest version of the gem doesn't contain 'erase_results' method for missing double render exception.

I can use :git in the Gemfile but it's much better only gem name :)

Thanks in advance.

Alex.

Hi.

Could you push the current version of the 'responds_to_parent' to the rubygems? Because now in the rubygems the latest version of the gem doesn't contain 'erase_results' method for missing double render exception.

I can use :git in the Gemfile but it's much better only gem name :)

Thanks in advance.

Alex.

Please sign in to comment.