wysihat-engine 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/generators/wysihat/templates/javascripts/wysihat_engine.js +73 -0
- data/generators/wysihat/wysihat_generator.rb +1 -0
- data/lib/wysihat-engine.rb +7 -76
- data/wysihat-engine.gemspec +2 -11
- metadata +2 -11
- data/vendor/plugins/responds_to_parent/MIT-LICENSE +0 -20
- data/vendor/plugins/responds_to_parent/README +0 -42
- data/vendor/plugins/responds_to_parent/Rakefile +0 -22
- data/vendor/plugins/responds_to_parent/init.rb +0 -2
- data/vendor/plugins/responds_to_parent/lib/parent_selector_assertion.rb +0 -144
- data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +0 -37
- data/vendor/plugins/responds_to_parent/rails/init.rb +0 -2
- data/vendor/plugins/responds_to_parent/responds-to-parent.gemspec +0 -15
- data/vendor/plugins/responds_to_parent/test/assert_select_parent_test.rb +0 -319
- data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +0 -116
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,73 @@
|
|
1
|
+
var toolbars = [];
|
2
|
+
|
3
|
+
var WysihatHelper = {
|
4
|
+
faceBoxFile: function()
|
5
|
+
{
|
6
|
+
facebox.loading();
|
7
|
+
new Effect.Appear($('facebox'), {duration: .3});
|
8
|
+
|
9
|
+
var fb = facebox;
|
10
|
+
var url = '/wysihat_files/?editor=' + this.id
|
11
|
+
|
12
|
+
new Ajax.Request(url, {
|
13
|
+
method : 'get',
|
14
|
+
onFailure : function(transport){
|
15
|
+
fb.reveal(transport.responseText, null);
|
16
|
+
},
|
17
|
+
onSuccess : function(transport){
|
18
|
+
fb.reveal(transport.responseText, null);
|
19
|
+
}
|
20
|
+
});
|
21
|
+
},
|
22
|
+
|
23
|
+
faceboxLink: function()
|
24
|
+
{
|
25
|
+
if (this.linkSelected()) {
|
26
|
+
this.unlinkSelection();
|
27
|
+
} else {
|
28
|
+
facebox.loading();
|
29
|
+
new Effect.Appear($('facebox'), {duration: .3});
|
30
|
+
iframe = this
|
31
|
+
facebox.reveal('<input type=\"text\" id=\"link_field\" style=\"width:100%;\"/>', null);
|
32
|
+
Event.observe('link_field', 'change', function(event) {
|
33
|
+
iframe.linkSelection($('link_field').value);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
},
|
37
|
+
|
38
|
+
faceboxHTML: function()
|
39
|
+
{
|
40
|
+
facebox.loading();
|
41
|
+
new Effect.Appear($('facebox'), {duration: .3});
|
42
|
+
iframe = this
|
43
|
+
facebox.reveal('<textarea id=\"html_editor\" style=\"width:100%; height:400px;\">' + iframe.contentWindow.document.body.innerHTML + '</textarea>', null);
|
44
|
+
Event.observe('html_editor', 'change', function(event) {
|
45
|
+
iframe.contentWindow.document.body.innerHTML = $('html_editor').value;
|
46
|
+
});
|
47
|
+
},
|
48
|
+
|
49
|
+
faceboxPaste: function()
|
50
|
+
{
|
51
|
+
facebox.loading();
|
52
|
+
new Effect.Appear($('facebox'), {duration: .3});
|
53
|
+
iframe = this
|
54
|
+
facebox.reveal('<textarea id=\"paste_editor\" style=\"width:100%; height:400px;\"></textarea>', null);
|
55
|
+
Event.observe('paste_editor', 'change', function(event) {
|
56
|
+
iframe.contentWindow.document.body.innerHTML = iframe.contentWindow.document.body.innerHTML + $('paste_editor').value.escapeHTML();
|
57
|
+
});
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
WysiHat.Editor.include(WysihatHelper);
|
62
|
+
|
63
|
+
Event.observe(window, 'load', function() {
|
64
|
+
$$('textarea').each(function(i){
|
65
|
+
var editor = WysiHat.Editor.attach(i.id);
|
66
|
+
var toolbar = new WysiHat.Toolbar(editor);
|
67
|
+
toolbars[i.id] = toolbar;
|
68
|
+
});
|
69
|
+
|
70
|
+
$$('form').each().onsubmit = function(){
|
71
|
+
editor.save();
|
72
|
+
};
|
73
|
+
});
|
@@ -3,6 +3,7 @@ class WysihatGenerator < Rails::Generator::Base
|
|
3
3
|
record do |m|
|
4
4
|
|
5
5
|
m.file 'javascripts/wysihat.js', 'public/javascripts/wysihat.js'
|
6
|
+
m.file 'javascripts/wysihat_engine.js', 'public/javascripts/wysihat_engine.js'
|
6
7
|
m.file 'javascripts/facebox.js', 'public/javascripts/facebox.js'
|
7
8
|
|
8
9
|
m.file 'stylesheets/wysihat.css', 'public/stylesheets/wysihat.css'
|
data/lib/wysihat-engine.rb
CHANGED
@@ -29,15 +29,15 @@ module ActionView
|
|
29
29
|
options['buttons'].each do |b|
|
30
30
|
case b.to_s.downcase
|
31
31
|
when "image"
|
32
|
-
buttons << "
|
32
|
+
buttons << "toolbars['#{tag_id}'].addButton({label : \'Image\', handler: function(editor) { return editor.faceBoxFile(editor); } })\n"
|
33
33
|
when "link"
|
34
|
-
buttons << "
|
34
|
+
buttons << "toolbars['#{tag_id}'].addButton({label : \'Link\', handler: function(editor) { return editor.faceboxLink(editor); } })\n"
|
35
35
|
when "html"
|
36
|
-
buttons << "
|
36
|
+
buttons << "toolbars['#{tag_id}'].addButton({label : \'HTML\', handler: function(editor) { return editor.faceboxHTML(editor); } })\n"
|
37
37
|
when "paste"
|
38
|
-
buttons << "
|
38
|
+
buttons << "toolbars['#{tag_id}'].addButton({label : \'Paste\', handler: function(editor) { return editor.faceboxPaste(editor); } })\n"
|
39
39
|
else
|
40
|
-
buttons << "
|
40
|
+
buttons << "toolbars['#{tag_id}'].addButton({label : \'#{b.to_s.split('_').map {|w| w.capitalize}.join}\'});\n"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -45,78 +45,9 @@ module ActionView
|
|
45
45
|
|
46
46
|
content_tag(
|
47
47
|
:script,
|
48
|
-
"
|
49
|
-
var WysihatHelper = {
|
50
|
-
faceBoxFile: function()
|
51
|
-
{
|
52
|
-
facebox.loading();
|
53
|
-
new Effect.Appear($('facebox'), {duration: .3});
|
54
|
-
|
55
|
-
var fb = facebox;
|
56
|
-
var url = '/wysihat_files/?editor=' + this.id
|
57
|
-
|
58
|
-
new Ajax.Request(url, {
|
59
|
-
method : 'get',
|
60
|
-
onFailure : function(transport){
|
61
|
-
fb.reveal(transport.responseText, null);
|
62
|
-
},
|
63
|
-
onSuccess : function(transport){
|
64
|
-
fb.reveal(transport.responseText, null);
|
65
|
-
}
|
66
|
-
});
|
67
|
-
},
|
68
|
-
|
69
|
-
faceboxLink: function()
|
70
|
-
{
|
71
|
-
if (this.linkSelected()) {
|
72
|
-
this.unlinkSelection();
|
73
|
-
} else {
|
74
|
-
facebox.loading();
|
75
|
-
new Effect.Appear($('facebox'), {duration: .3});
|
76
|
-
iframe = this
|
77
|
-
facebox.reveal('<input type=\"text\" id=\"link_field\" style=\"width:100%;\"/>', null);
|
78
|
-
Event.observe('link_field', 'change', function(event) {
|
79
|
-
iframe.linkSelection($('link_field').value);
|
80
|
-
});
|
81
|
-
}
|
82
|
-
},
|
83
|
-
|
84
|
-
faceboxHTML: function()
|
85
|
-
{
|
86
|
-
facebox.loading();
|
87
|
-
new Effect.Appear($('facebox'), {duration: .3});
|
88
|
-
iframe = this
|
89
|
-
facebox.reveal('<textarea id=\"html_editor\" style=\"width:100%; height:400px;\">' + iframe.contentWindow.document.body.innerHTML + '</textarea>', null);
|
90
|
-
Event.observe('html_editor', 'change', function(event) {
|
91
|
-
iframe.contentWindow.document.body.innerHTML = $('html_editor').value;
|
92
|
-
});
|
93
|
-
},
|
94
|
-
|
95
|
-
faceboxPaste: function()
|
96
|
-
{
|
97
|
-
facebox.loading();
|
98
|
-
new Effect.Appear($('facebox'), {duration: .3});
|
99
|
-
iframe = this
|
100
|
-
facebox.reveal('<textarea id=\"paste_editor\" style=\"width:100%; height:400px;\"></textarea>', null);
|
101
|
-
Event.observe('paste_editor', 'change', function(event) {
|
102
|
-
iframe.contentWindow.document.body.innerHTML = iframe.contentWindow.document.body.innerHTML + $('paste_editor').value.escapeHTML();
|
103
|
-
});
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
WysiHat.Editor.include(WysihatHelper);
|
108
|
-
|
109
|
-
Event.observe(window, 'load', function() {
|
110
|
-
var editor = WysiHat.Editor.attach('#{tag_id}');
|
111
|
-
var toolbar = new WysiHat.Toolbar(editor);
|
48
|
+
"Event.observe(window, 'load', function() {
|
112
49
|
#{buttons}
|
113
|
-
|
114
|
-
$$('form').first().onsubmit = function(){
|
115
|
-
editor.save();
|
116
|
-
};
|
117
|
-
|
118
|
-
});
|
119
|
-
",
|
50
|
+
})",
|
120
51
|
:type => 'text/javascript'
|
121
52
|
) <<
|
122
53
|
content_tag("textarea", html_escape(options.delete('value') || value_before_type_cast(object)), options.merge(:class => 'wysihat_editor'))
|
data/wysihat-engine.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wysihat-engine}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Kreeftmeijer"]
|
@@ -60,21 +60,12 @@ Gem::Specification.new do |s|
|
|
60
60
|
"generators/wysihat/templates/images/tr.png",
|
61
61
|
"generators/wysihat/templates/javascripts/facebox.js",
|
62
62
|
"generators/wysihat/templates/javascripts/wysihat.js",
|
63
|
+
"generators/wysihat/templates/javascripts/wysihat_engine.js",
|
63
64
|
"generators/wysihat/templates/migrations/create_wysihat_files.rb",
|
64
65
|
"generators/wysihat/templates/stylesheets/facebox.css",
|
65
66
|
"generators/wysihat/templates/stylesheets/wysihat.css",
|
66
67
|
"generators/wysihat/wysihat_generator.rb",
|
67
68
|
"lib/wysihat-engine.rb",
|
68
|
-
"vendor/plugins/responds_to_parent/MIT-LICENSE",
|
69
|
-
"vendor/plugins/responds_to_parent/README",
|
70
|
-
"vendor/plugins/responds_to_parent/Rakefile",
|
71
|
-
"vendor/plugins/responds_to_parent/init.rb",
|
72
|
-
"vendor/plugins/responds_to_parent/lib/parent_selector_assertion.rb",
|
73
|
-
"vendor/plugins/responds_to_parent/lib/responds_to_parent.rb",
|
74
|
-
"vendor/plugins/responds_to_parent/rails/init.rb",
|
75
|
-
"vendor/plugins/responds_to_parent/responds-to-parent.gemspec",
|
76
|
-
"vendor/plugins/responds_to_parent/test/assert_select_parent_test.rb",
|
77
|
-
"vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb",
|
78
69
|
"wysihat-engine.gemspec"
|
79
70
|
]
|
80
71
|
s.homepage = %q{http://www.80beans.com/2009/10/01/wysihat-engine/}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wysihat-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Kreeftmeijer
|
@@ -85,21 +85,12 @@ files:
|
|
85
85
|
- generators/wysihat/templates/images/tr.png
|
86
86
|
- generators/wysihat/templates/javascripts/facebox.js
|
87
87
|
- generators/wysihat/templates/javascripts/wysihat.js
|
88
|
+
- generators/wysihat/templates/javascripts/wysihat_engine.js
|
88
89
|
- generators/wysihat/templates/migrations/create_wysihat_files.rb
|
89
90
|
- generators/wysihat/templates/stylesheets/facebox.css
|
90
91
|
- generators/wysihat/templates/stylesheets/wysihat.css
|
91
92
|
- generators/wysihat/wysihat_generator.rb
|
92
93
|
- lib/wysihat-engine.rb
|
93
|
-
- vendor/plugins/responds_to_parent/MIT-LICENSE
|
94
|
-
- vendor/plugins/responds_to_parent/README
|
95
|
-
- vendor/plugins/responds_to_parent/Rakefile
|
96
|
-
- vendor/plugins/responds_to_parent/init.rb
|
97
|
-
- vendor/plugins/responds_to_parent/lib/parent_selector_assertion.rb
|
98
|
-
- vendor/plugins/responds_to_parent/lib/responds_to_parent.rb
|
99
|
-
- vendor/plugins/responds_to_parent/rails/init.rb
|
100
|
-
- vendor/plugins/responds_to_parent/responds-to-parent.gemspec
|
101
|
-
- vendor/plugins/responds_to_parent/test/assert_select_parent_test.rb
|
102
|
-
- vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb
|
103
94
|
- wysihat-engine.gemspec
|
104
95
|
has_rdoc: true
|
105
96
|
homepage: http://www.80beans.com/2009/10/01/wysihat-engine/
|
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2006 Sean Treadway
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,42 +0,0 @@
|
|
1
|
-
RespondsToParent
|
2
|
-
================
|
3
|
-
|
4
|
-
Adds responds_to_parent to your controller to respond to the parent document of your page.
|
5
|
-
Make Ajaxy file uploads by posting the form to a hidden iframe, and respond with
|
6
|
-
RJS to the parent window.
|
7
|
-
|
8
|
-
Example
|
9
|
-
=======
|
10
|
-
|
11
|
-
Controller:
|
12
|
-
|
13
|
-
class Test < ActionController::Base
|
14
|
-
def main
|
15
|
-
end
|
16
|
-
|
17
|
-
def form_action
|
18
|
-
# Do stuff with params[:uploaded_file]
|
19
|
-
|
20
|
-
responds_to_parent do
|
21
|
-
render :update do |page|
|
22
|
-
page << "alert($('stuff').innerHTML)"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
main.rhtml:
|
29
|
-
|
30
|
-
<html>
|
31
|
-
<body>
|
32
|
-
<div id="stuff">Here is some stuff</div>
|
33
|
-
|
34
|
-
<form target="frame" action="form_action">
|
35
|
-
<input type="file" name="uploaded_file"/>
|
36
|
-
<input type="submit"/>
|
37
|
-
</form>
|
38
|
-
|
39
|
-
<iframe id='frame' name="frame"></iframe>
|
40
|
-
</body>
|
41
|
-
</html>
|
42
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the responds_to_parent plugin.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Generate documentation for the responds_to_parent plugin.'
|
16
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
-
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = 'RespondsToParent'
|
19
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README')
|
21
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
module ActionController
|
2
|
-
module Assertions
|
3
|
-
module SelectorAssertions
|
4
|
-
# :call-seq:
|
5
|
-
# assert_select_parent()
|
6
|
-
# assert_select_parent() { |script| ... }
|
7
|
-
#
|
8
|
-
# Selects JavaScript that is generated for the `parent' window.
|
9
|
-
#
|
10
|
-
# Without a block, #assert_select_parent asserts that the response
|
11
|
-
# is generated by responds_to_parent.
|
12
|
-
#
|
13
|
-
# With a block, #assert_select_parent selects script that is supposed
|
14
|
-
# to be evaluated in the parent window and passes it to the block.
|
15
|
-
# Typically #assert_select_rjs is used in the block.
|
16
|
-
def assert_select_parent(*args, &block)
|
17
|
-
wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
|
18
|
-
"(.*)" +
|
19
|
-
Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
|
20
|
-
match = @response.body.match(Regexp.new(wrapper_re_str))
|
21
|
-
|
22
|
-
if match
|
23
|
-
escaped_js = match[1]
|
24
|
-
unescaped_js = escaped_js.
|
25
|
-
gsub(%r!</scr"\+"ipt>!, '</script>').
|
26
|
-
gsub(/\\(\'|\")/, '\1').
|
27
|
-
gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
|
28
|
-
gsub(/\\\\/, '\\')
|
29
|
-
@response.body = unescaped_js # assert_select_rjs refers @response.body.
|
30
|
-
|
31
|
-
if block_given?
|
32
|
-
begin
|
33
|
-
in_scope, @selected = @selected, unescaped_js
|
34
|
-
yield unescaped_js
|
35
|
-
ensure
|
36
|
-
@selected = in_scope
|
37
|
-
end
|
38
|
-
end
|
39
|
-
unescaped_js
|
40
|
-
else
|
41
|
-
# doesn't seem a responds_to_parent content.
|
42
|
-
flunk args.shift || "No content for the parent window."
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module ActionController
|
50
|
-
module Assertions
|
51
|
-
module SelectorAssertions
|
52
|
-
# :call-seq:
|
53
|
-
# assert_select_parent()
|
54
|
-
# assert_select_parent() { |script| ... }
|
55
|
-
#
|
56
|
-
# Selects JavaScript that is generated for the `parent' window.
|
57
|
-
#
|
58
|
-
# Without a block, #assert_select_parent asserts that the response
|
59
|
-
# is generated by responds_to_parent.
|
60
|
-
#
|
61
|
-
# With a block, #assert_select_parent selects script that is supposed
|
62
|
-
# to be evaluated in the parent window and passes it to the block.
|
63
|
-
# Typically #assert_select_rjs is used in the block.
|
64
|
-
def assert_select_parent(*args, &block)
|
65
|
-
wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
|
66
|
-
"(.*)" +
|
67
|
-
Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
|
68
|
-
match = @response.body.match(Regexp.new(wrapper_re_str))
|
69
|
-
|
70
|
-
if match
|
71
|
-
escaped_js = match[1]
|
72
|
-
unescaped_js = escaped_js.
|
73
|
-
gsub(%r!</scr"\+"ipt>!, '</script>').
|
74
|
-
gsub(/\\(\'|\")/, '\1').
|
75
|
-
gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
|
76
|
-
gsub(/\\\\/, '\\')
|
77
|
-
@response.body = unescaped_js # assert_select_rjs refers @response.body.
|
78
|
-
|
79
|
-
if block_given?
|
80
|
-
begin
|
81
|
-
in_scope, @selected = @selected, unescaped_js
|
82
|
-
yield unescaped_js
|
83
|
-
ensure
|
84
|
-
@selected = in_scope
|
85
|
-
end
|
86
|
-
end
|
87
|
-
unescaped_js
|
88
|
-
else
|
89
|
-
# doesn't seem a responds_to_parent content.
|
90
|
-
flunk args.shift || "No content for the parent window."
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
module ActionController
|
98
|
-
module Assertions
|
99
|
-
module SelectorAssertions
|
100
|
-
# :call-seq:
|
101
|
-
# assert_select_parent()
|
102
|
-
# assert_select_parent() { |script| ... }
|
103
|
-
#
|
104
|
-
# Selects JavaScript that is generated for the `parent' window.
|
105
|
-
#
|
106
|
-
# Without a block, #assert_select_parent asserts that the response
|
107
|
-
# is generated by responds_to_parent.
|
108
|
-
#
|
109
|
-
# With a block, #assert_select_parent selects script that is supposed
|
110
|
-
# to be evaluated in the parent window and passes it to the block.
|
111
|
-
# Typically #assert_select_rjs is used in the block.
|
112
|
-
def assert_select_parent(*args, &block)
|
113
|
-
wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") +
|
114
|
-
"(.*)" +
|
115
|
-
Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }")
|
116
|
-
match = @response.body.match(Regexp.new(wrapper_re_str))
|
117
|
-
|
118
|
-
if match
|
119
|
-
escaped_js = match[1]
|
120
|
-
unescaped_js = escaped_js.
|
121
|
-
gsub(%r!</scr"\+"ipt>!, '</script>').
|
122
|
-
gsub(/\\(\'|\")/, '\1').
|
123
|
-
gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash.
|
124
|
-
gsub(/\\\\/, '\\')
|
125
|
-
@response.body = unescaped_js # assert_select_rjs refers @response.body.
|
126
|
-
|
127
|
-
if block_given?
|
128
|
-
begin
|
129
|
-
in_scope, @selected = @selected, unescaped_js
|
130
|
-
yield unescaped_js
|
131
|
-
ensure
|
132
|
-
@selected = in_scope
|
133
|
-
end
|
134
|
-
end
|
135
|
-
unescaped_js
|
136
|
-
else
|
137
|
-
# doesn't seem a responds_to_parent content.
|
138
|
-
flunk args.shift || "No content for the parent window."
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# Module containing the methods useful for child IFRAME to parent window communication
|
2
|
-
module RespondsToParent
|
3
|
-
# Executes the response body as JavaScript in the context of the parent window.
|
4
|
-
# Use this method of you are posting a form to a hidden IFRAME or if you would like
|
5
|
-
# to use IFRAME base RPC.
|
6
|
-
def responds_to_parent(&block)
|
7
|
-
yield
|
8
|
-
|
9
|
-
if performed?
|
10
|
-
# Either pull out a redirect or the request body
|
11
|
-
script = if location = erase_redirect_results
|
12
|
-
"document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
|
13
|
-
else
|
14
|
-
response.body || ''
|
15
|
-
end
|
16
|
-
|
17
|
-
# Clear out the previous render to prevent double render
|
18
|
-
erase_results
|
19
|
-
|
20
|
-
# We're returning HTML instead of JS or XML now
|
21
|
-
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
22
|
-
|
23
|
-
# Eval in parent scope and replace document location of this frame
|
24
|
-
# so back button doesn't replay action on targeted forms
|
25
|
-
# loc = document.location to be set after parent is updated for IE
|
26
|
-
# with(window.parent) - pull in variables from parent window
|
27
|
-
# setTimeout - scope the execution in the windows parent for safari
|
28
|
-
# window.eval - legal eval for Opera
|
29
|
-
render :text => "<html><body><script type='text/javascript' charset='utf-8'>
|
30
|
-
var loc = document.location;
|
31
|
-
with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
|
32
|
-
</script></body></html>"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
alias respond_to_parent responds_to_parent
|
36
|
-
end
|
37
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
spec = Gem::Specification.new do |s|
|
2
|
-
s.name = 'responds-to-parent'
|
3
|
-
s.version = '1.0.20090923'
|
4
|
-
s.homepage = 'http://constancy.rubyforge.org/'
|
5
|
-
s.summary = "[Rails] Adds 'responds_to_parent' to your controller to" +
|
6
|
-
'respond to the parent document of your page.'
|
7
|
-
'Make Ajaxy file uploads by posting the form to a hidden' +
|
8
|
-
'iframe, and respond with RJS to the parent window.'
|
9
|
-
|
10
|
-
s.files = %w( README Rakefile MIT-LICENSE rails/init.rb
|
11
|
-
lib/responds_to_parent.rb
|
12
|
-
lib/parent_selector_assertion.rb
|
13
|
-
test/responds_to_parent_test.rb
|
14
|
-
test/assert_select_parent_test.rb)
|
15
|
-
end
|
@@ -1,319 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.dirname(__FILE__) + '/../../../../config/environment'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'test_help'
|
5
|
-
|
6
|
-
class AssertSelectParentTest < ActionController::TestCase
|
7
|
-
class AssertSelectParentController < ActionController::Base
|
8
|
-
def response_with=(content)
|
9
|
-
@content = content
|
10
|
-
end
|
11
|
-
|
12
|
-
def response_with(&block)
|
13
|
-
@update = block
|
14
|
-
end
|
15
|
-
|
16
|
-
def rjs
|
17
|
-
responds_to_parent do
|
18
|
-
render :update do |page|
|
19
|
-
@update.call page
|
20
|
-
end
|
21
|
-
end
|
22
|
-
@update = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def text
|
26
|
-
responds_to_parent do
|
27
|
-
render :text => @content, :layout => false
|
28
|
-
end
|
29
|
-
@content = nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def not_respond_to_parent
|
33
|
-
render :nothing => true
|
34
|
-
end
|
35
|
-
|
36
|
-
def rescue_action(e)
|
37
|
-
raise e
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def setup
|
42
|
-
@controller = AssertSelectParentController.new
|
43
|
-
@request = ActionController::TestRequest.new
|
44
|
-
@response = ActionController::TestResponse.new
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_basic
|
48
|
-
render_rjs do |page|
|
49
|
-
page.replace "test", "<div id=\"1\">foo</div>"
|
50
|
-
end
|
51
|
-
|
52
|
-
found = false
|
53
|
-
assert_select_parent do
|
54
|
-
assert_select_rjs do
|
55
|
-
assert_select "#1"
|
56
|
-
found = true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
assert found
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_bubble_up_failure
|
63
|
-
render_rjs do |page|
|
64
|
-
page.replace "test", "<div id=\"1\">foo</div>"
|
65
|
-
end
|
66
|
-
|
67
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
68
|
-
assert_select_parent do
|
69
|
-
assert_select_rjs do
|
70
|
-
assert_select "#nonexistent"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_fail_if_no_content_for_parent
|
77
|
-
get :not_respond_to_parent
|
78
|
-
assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_quotes
|
82
|
-
do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_new_line
|
86
|
-
do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
|
87
|
-
end
|
88
|
-
|
89
|
-
protected
|
90
|
-
def render_rjs(&block)
|
91
|
-
@controller.response_with &block
|
92
|
-
get :rjs
|
93
|
-
end
|
94
|
-
|
95
|
-
def render_text(text)
|
96
|
-
@controller.response_with = text
|
97
|
-
get :text
|
98
|
-
end
|
99
|
-
|
100
|
-
def do_test_with_text(text)
|
101
|
-
render_text text
|
102
|
-
|
103
|
-
assert_select_parent do |text_for_parent|
|
104
|
-
assert_equal text, text_for_parent
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
require File.dirname(__FILE__) + '/../../../../config/environment'
|
109
|
-
require 'test/unit'
|
110
|
-
require 'test_help'
|
111
|
-
|
112
|
-
class AssertSelectParentTest < ActionController::TestCase
|
113
|
-
class AssertSelectParentController < ActionController::Base
|
114
|
-
def response_with=(content)
|
115
|
-
@content = content
|
116
|
-
end
|
117
|
-
|
118
|
-
def response_with(&block)
|
119
|
-
@update = block
|
120
|
-
end
|
121
|
-
|
122
|
-
def rjs
|
123
|
-
responds_to_parent do
|
124
|
-
render :update do |page|
|
125
|
-
@update.call page
|
126
|
-
end
|
127
|
-
end
|
128
|
-
@update = nil
|
129
|
-
end
|
130
|
-
|
131
|
-
def text
|
132
|
-
responds_to_parent do
|
133
|
-
render :text => @content, :layout => false
|
134
|
-
end
|
135
|
-
@content = nil
|
136
|
-
end
|
137
|
-
|
138
|
-
def not_respond_to_parent
|
139
|
-
render :nothing => true
|
140
|
-
end
|
141
|
-
|
142
|
-
def rescue_action(e)
|
143
|
-
raise e
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def setup
|
148
|
-
@controller = AssertSelectParentController.new
|
149
|
-
@request = ActionController::TestRequest.new
|
150
|
-
@response = ActionController::TestResponse.new
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_basic
|
154
|
-
render_rjs do |page|
|
155
|
-
page.replace "test", "<div id=\"1\">foo</div>"
|
156
|
-
end
|
157
|
-
|
158
|
-
found = false
|
159
|
-
assert_select_parent do
|
160
|
-
assert_select_rjs do
|
161
|
-
assert_select "#1"
|
162
|
-
found = true
|
163
|
-
end
|
164
|
-
end
|
165
|
-
assert found
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_bubble_up_failure
|
169
|
-
render_rjs do |page|
|
170
|
-
page.replace "test", "<div id=\"1\">foo</div>"
|
171
|
-
end
|
172
|
-
|
173
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
174
|
-
assert_select_parent do
|
175
|
-
assert_select_rjs do
|
176
|
-
assert_select "#nonexistent"
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_fail_if_no_content_for_parent
|
183
|
-
get :not_respond_to_parent
|
184
|
-
assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_quotes
|
188
|
-
do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_new_line
|
192
|
-
do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
|
193
|
-
end
|
194
|
-
|
195
|
-
protected
|
196
|
-
def render_rjs(&block)
|
197
|
-
@controller.response_with &block
|
198
|
-
get :rjs
|
199
|
-
end
|
200
|
-
|
201
|
-
def render_text(text)
|
202
|
-
@controller.response_with = text
|
203
|
-
get :text
|
204
|
-
end
|
205
|
-
|
206
|
-
def do_test_with_text(text)
|
207
|
-
render_text text
|
208
|
-
|
209
|
-
assert_select_parent do |text_for_parent|
|
210
|
-
assert_equal text, text_for_parent
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
require File.dirname(__FILE__) + '/../../../../config/environment'
|
215
|
-
require 'test/unit'
|
216
|
-
require 'test_help'
|
217
|
-
|
218
|
-
class AssertSelectParentTest < ActionController::TestCase
|
219
|
-
class AssertSelectParentController < ActionController::Base
|
220
|
-
def response_with=(content)
|
221
|
-
@content = content
|
222
|
-
end
|
223
|
-
|
224
|
-
def response_with(&block)
|
225
|
-
@update = block
|
226
|
-
end
|
227
|
-
|
228
|
-
def rjs
|
229
|
-
responds_to_parent do
|
230
|
-
render :update do |page|
|
231
|
-
@update.call page
|
232
|
-
end
|
233
|
-
end
|
234
|
-
@update = nil
|
235
|
-
end
|
236
|
-
|
237
|
-
def text
|
238
|
-
responds_to_parent do
|
239
|
-
render :text => @content, :layout => false
|
240
|
-
end
|
241
|
-
@content = nil
|
242
|
-
end
|
243
|
-
|
244
|
-
def not_respond_to_parent
|
245
|
-
render :nothing => true
|
246
|
-
end
|
247
|
-
|
248
|
-
def rescue_action(e)
|
249
|
-
raise e
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def setup
|
254
|
-
@controller = AssertSelectParentController.new
|
255
|
-
@request = ActionController::TestRequest.new
|
256
|
-
@response = ActionController::TestResponse.new
|
257
|
-
end
|
258
|
-
|
259
|
-
def test_basic
|
260
|
-
render_rjs do |page|
|
261
|
-
page.replace "test", "<div id=\"1\">foo</div>"
|
262
|
-
end
|
263
|
-
|
264
|
-
found = false
|
265
|
-
assert_select_parent do
|
266
|
-
assert_select_rjs do
|
267
|
-
assert_select "#1"
|
268
|
-
found = true
|
269
|
-
end
|
270
|
-
end
|
271
|
-
assert found
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_bubble_up_failure
|
275
|
-
render_rjs do |page|
|
276
|
-
page.replace "test", "<div id=\"1\">foo</div>"
|
277
|
-
end
|
278
|
-
|
279
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
280
|
-
assert_select_parent do
|
281
|
-
assert_select_rjs do
|
282
|
-
assert_select "#nonexistent"
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_fail_if_no_content_for_parent
|
289
|
-
get :not_respond_to_parent
|
290
|
-
assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_quotes
|
294
|
-
do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_new_line
|
298
|
-
do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
|
299
|
-
end
|
300
|
-
|
301
|
-
protected
|
302
|
-
def render_rjs(&block)
|
303
|
-
@controller.response_with &block
|
304
|
-
get :rjs
|
305
|
-
end
|
306
|
-
|
307
|
-
def render_text(text)
|
308
|
-
@controller.response_with = text
|
309
|
-
get :text
|
310
|
-
end
|
311
|
-
|
312
|
-
def do_test_with_text(text)
|
313
|
-
render_text text
|
314
|
-
|
315
|
-
assert_select_parent do |text_for_parent|
|
316
|
-
assert_equal text, text_for_parent
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.dirname(__FILE__) + '/../../../../config/environment'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'test_help'
|
5
|
-
|
6
|
-
class IFrameController < ActionController::Base
|
7
|
-
def normal
|
8
|
-
render :update do |page|
|
9
|
-
page.alert "foo"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def aliased
|
14
|
-
respond_to_parent do
|
15
|
-
render :text => 'woot'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def redirect
|
20
|
-
responds_to_parent do
|
21
|
-
redirect_to '/another/place'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def no_block
|
26
|
-
responds_to_parent
|
27
|
-
end
|
28
|
-
|
29
|
-
def empty_render
|
30
|
-
responds_to_parent do
|
31
|
-
end
|
32
|
-
|
33
|
-
render :text => ''
|
34
|
-
end
|
35
|
-
|
36
|
-
def quotes
|
37
|
-
responds_to_parent do
|
38
|
-
render :text => %(single' double" qs\\' qd\\" escaped\\\' doubleescaped\\\\')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def newlines
|
43
|
-
responds_to_parent do
|
44
|
-
render :text => "line1\nline2\\nline2"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def update
|
49
|
-
responds_to_parent do
|
50
|
-
render :update do |page|
|
51
|
-
page.alert 'foo'
|
52
|
-
page.alert 'bar'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def rescue_action(e)
|
58
|
-
raise e
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class RespondsToParentTest < ActionController::TestCase
|
63
|
-
def setup
|
64
|
-
@controller = IFrameController.new
|
65
|
-
@request = ActionController::TestRequest.new
|
66
|
-
@response = ActionController::TestResponse.new
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_normal
|
70
|
-
get :normal
|
71
|
-
assert_match /alert\("foo"\)/, @response.body
|
72
|
-
assert_no_match /window\.parent/, @response.body
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_quotes_should_be_escaped
|
76
|
-
render :quotes
|
77
|
-
assert_match %r{eval\('single\\' double\\" qs\\\\\\' qd\\\\\\" escaped\\\\\\' doubleescaped\\\\\\\\\\'}, @response.body
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_newlines_should_be_escaped
|
81
|
-
render :newlines
|
82
|
-
assert_match %r{eval\('line1\\nline2\\\\nline2'\)}, @response.body
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_no_block_should_raise
|
86
|
-
assert_raises LocalJumpError do
|
87
|
-
get :no_block
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_empty_render_should_not_expand_javascript
|
92
|
-
get :empty_render
|
93
|
-
assert_equal '', @response.body
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_update_should_perform_combined_rjs
|
97
|
-
render :update
|
98
|
-
assert_match /alert\(\\"foo\\"\);\\nalert\(\\"bar\\"\)/, @response.body
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_aliased_method_should_not_raise
|
102
|
-
assert_nothing_raised do
|
103
|
-
render :aliased
|
104
|
-
assert_match /eval\('woot'\)/, @response.body
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
protected
|
109
|
-
|
110
|
-
def render(action)
|
111
|
-
get action
|
112
|
-
assert_match /<script type='text\/javascript'/, @response.body
|
113
|
-
assert_match /with\(window\.parent\)/, @response.body
|
114
|
-
assert_match /loc\.replace\('about:blank'\)/, @response.body
|
115
|
-
end
|
116
|
-
end
|