mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added simple alert() notifications for RJS exceptions when config.action_view.debug_rjs = true. Set debug_rjs = true for the default development environment.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3856 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
955583aed4
commit
3589871de8
6 changed files with 48 additions and 28 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Added simple alert() notifications for RJS exceptions when config.action_view.debug_rjs = true. [Sam Stephenson]
|
||||||
|
|
||||||
* Added :content_type option to render, so you can change the content type on the fly [DHH]. Example: render :action => "atom.rxml", :content_type => "application/atom+xml"
|
* Added :content_type option to render, so you can change the content type on the fly [DHH]. Example: render :action => "atom.rxml", :content_type => "application/atom+xml"
|
||||||
|
|
||||||
* CHANGED DEFAULT: The default content type for .rxml is now application/xml instead of type/xml, see http://www.xml.com/pub/a/2004/07/21/dive.html for reason [DHH]
|
* CHANGED DEFAULT: The default content type for .rxml is now application/xml instead of type/xml, see http://www.xml.com/pub/a/2004/07/21/dive.html for reason [DHH]
|
||||||
|
|
|
@ -162,6 +162,11 @@ module ActionView #:nodoc:
|
||||||
# shortly.
|
# shortly.
|
||||||
@@local_assigns_support_string_keys = true
|
@@local_assigns_support_string_keys = true
|
||||||
cattr_accessor :local_assigns_support_string_keys
|
cattr_accessor :local_assigns_support_string_keys
|
||||||
|
|
||||||
|
# Specify whether RJS responses should be wrapped in a try/catch block
|
||||||
|
# that alert()s the caught exception (and then re-raises it).
|
||||||
|
@@debug_rjs = false
|
||||||
|
cattr_accessor :debug_rjs
|
||||||
|
|
||||||
@@template_handlers = {}
|
@@template_handlers = {}
|
||||||
|
|
||||||
|
|
|
@ -370,12 +370,12 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def include_helpers_from_context
|
def include_helpers_from_context
|
||||||
@context.extended_by.each do |mod|
|
@context.extended_by.each do |mod|
|
||||||
extend mod unless mod.name =~ /^ActionView::Helpers/
|
extend mod unless mod.name =~ /^ActionView::Helpers/
|
||||||
|
end
|
||||||
|
extend GeneratorMethods
|
||||||
end
|
end
|
||||||
extend GeneratorMethods
|
|
||||||
end
|
|
||||||
|
|
||||||
# JavaScriptGenerator generates blocks of JavaScript code that allow you
|
# JavaScriptGenerator generates blocks of JavaScript code that allow you
|
||||||
# to change the content and presentation of multiple DOM elements. Use
|
# to change the content and presentation of multiple DOM elements. Use
|
||||||
|
@ -425,7 +425,12 @@ module ActionView
|
||||||
# <script> tag.
|
# <script> tag.
|
||||||
module GeneratorMethods
|
module GeneratorMethods
|
||||||
def to_s #:nodoc:
|
def to_s #:nodoc:
|
||||||
@lines * $/
|
returning javascript = @lines * $/ do
|
||||||
|
if ActionView::Base.debug_rjs
|
||||||
|
javascript.replace "try {\n#{javascript}\n} catch (e) "
|
||||||
|
javascript << "{ alert('RJS error:\\n\\n' + e.toString()); throw e }"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a element reference by finding it through +id+ in the DOM. This element can then be
|
# Returns a element reference by finding it through +id+ in the DOM. This element can then be
|
||||||
|
@ -748,7 +753,7 @@ module ActionView
|
||||||
class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
|
class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
|
||||||
def initialize(generator, id)
|
def initialize(generator, id)
|
||||||
@id = id
|
@id = id
|
||||||
super(generator, "$('#{id}')")
|
super(generator, "$(#{id.to_json})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_html(*options_for_render)
|
def replace_html(*options_for_render)
|
||||||
|
@ -874,7 +879,7 @@ module ActionView
|
||||||
|
|
||||||
class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
|
class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
|
||||||
def initialize(generator, pattern)
|
def initialize(generator, pattern)
|
||||||
super(generator, "$$('#{pattern}')")
|
super(generator, "$$(#{pattern.to_json})")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -141,7 +141,7 @@ class MimeControllerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
||||||
get :using_defaults
|
get :using_defaults
|
||||||
assert_equal "$('body').visualEffect(\"highlight\");", @response.body
|
assert_equal '$("body").visualEffect("highlight");', @response.body
|
||||||
|
|
||||||
@request.env["HTTP_ACCEPT"] = "application/xml"
|
@request.env["HTTP_ACCEPT"] = "application/xml"
|
||||||
get :using_defaults
|
get :using_defaults
|
||||||
|
|
|
@ -393,7 +393,7 @@ class NewRenderTest < Test::Unit::TestCase
|
||||||
def test_enum_rjs_test
|
def test_enum_rjs_test
|
||||||
get :enum_rjs_test
|
get :enum_rjs_test
|
||||||
assert_equal <<-EOS.strip, @response.body
|
assert_equal <<-EOS.strip, @response.body
|
||||||
$$('.product').each(function(value, index) {
|
$$(".product").each(function(value, index) {
|
||||||
new Effect.Highlight(element,{});
|
new Effect.Highlight(element,{});
|
||||||
new Effect.Highlight(value,{});
|
new Effect.Highlight(value,{});
|
||||||
Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value)})}});
|
Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value)})}});
|
||||||
|
|
|
@ -230,31 +230,31 @@ Element.update("baz", "<p>This is a test</p>");
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_element_access
|
def test_element_access
|
||||||
assert_equal %($('hello');), @generator['hello']
|
assert_equal %($("hello");), @generator['hello']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_element_proxy_one_deep
|
def test_element_proxy_one_deep
|
||||||
@generator['hello'].hide
|
@generator['hello'].hide
|
||||||
assert_equal %($('hello').hide();), @generator.to_s
|
assert_equal %($("hello").hide();), @generator.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_element_proxy_assignment
|
def test_element_proxy_assignment
|
||||||
@generator['hello'].width = 400
|
@generator['hello'].width = 400
|
||||||
assert_equal %($('hello').width = 400;), @generator.to_s
|
assert_equal %($("hello").width = 400;), @generator.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_element_proxy_two_deep
|
def test_element_proxy_two_deep
|
||||||
@generator['hello'].hide("first").clean_whitespace
|
@generator['hello'].hide("first").clean_whitespace
|
||||||
assert_equal %($('hello').hide("first").cleanWhitespace();), @generator.to_s
|
assert_equal %($("hello").hide("first").cleanWhitespace();), @generator.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_select_access
|
def test_select_access
|
||||||
assert_equal %($$('div.hello');), @generator.select('div.hello')
|
assert_equal %($$("div.hello");), @generator.select('div.hello')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_select_proxy_one_deep
|
def test_select_proxy_one_deep
|
||||||
@generator.select('p.welcome b').first.hide
|
@generator.select('p.welcome b').first.hide
|
||||||
assert_equal %($$('p.welcome b').first().hide();), @generator.to_s
|
assert_equal %($$("p.welcome b").first().hide();), @generator.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_visual_effect
|
def test_visual_effect
|
||||||
|
@ -286,8 +286,8 @@ Element.update("baz", "<p>This is a test</p>");
|
||||||
@generator.select('p.welcome b').first.hide()
|
@generator.select('p.welcome b').first.hide()
|
||||||
@generator.select('p.welcome b').last.show()
|
@generator.select('p.welcome b').last.show()
|
||||||
assert_equal <<-EOS.strip, @generator.to_s
|
assert_equal <<-EOS.strip, @generator.to_s
|
||||||
$$('p.welcome b').first().hide();
|
$$("p.welcome b").first().hide();
|
||||||
$$('p.welcome b').last().show();
|
$$("p.welcome b").last().show();
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -299,10 +299,10 @@ $$('p.welcome b').last().show();
|
||||||
@generator.visual_effect :highlight, value
|
@generator.visual_effect :highlight, value
|
||||||
end
|
end
|
||||||
assert_equal <<-EOS.strip, @generator.to_s
|
assert_equal <<-EOS.strip, @generator.to_s
|
||||||
$$('p.welcome b').each(function(value, index) {
|
$$("p.welcome b").each(function(value, index) {
|
||||||
value.removeClassName("selected");
|
value.removeClassName("selected");
|
||||||
});
|
});
|
||||||
$$('p.welcome b').each(function(value, index) {
|
$$("p.welcome b").each(function(value, index) {
|
||||||
new Effect.Highlight(value,{});
|
new Effect.Highlight(value,{});
|
||||||
});
|
});
|
||||||
EOS
|
EOS
|
||||||
|
@ -312,10 +312,10 @@ new Effect.Highlight(value,{});
|
||||||
@generator.select('p').collect('a') { |para| para.show }
|
@generator.select('p').collect('a') { |para| para.show }
|
||||||
@generator.select('p').collect { |para| para.hide }
|
@generator.select('p').collect { |para| para.hide }
|
||||||
assert_equal <<-EOS.strip, @generator.to_s
|
assert_equal <<-EOS.strip, @generator.to_s
|
||||||
var a = $$('p').collect(function(value, index) {
|
var a = $$("p").collect(function(value, index) {
|
||||||
return value.show();
|
return value.show();
|
||||||
});
|
});
|
||||||
$$('p').collect(function(value, index) {
|
$$("p").collect(function(value, index) {
|
||||||
return value.hide();
|
return value.hide();
|
||||||
});
|
});
|
||||||
EOS
|
EOS
|
||||||
|
@ -332,10 +332,10 @@ return value.hide();
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal <<-EOS.strip, @generator.to_s
|
assert_equal <<-EOS.strip, @generator.to_s
|
||||||
var a = $$('p').grep(/^a/, function(value, index) {
|
var a = $$("p").grep(/^a/, function(value, index) {
|
||||||
return (value.className == "welcome");
|
return (value.className == "welcome");
|
||||||
});
|
});
|
||||||
var b = $$('p').grep(/b$/, function(value, index) {
|
var b = $$("p").grep(/b$/, function(value, index) {
|
||||||
alert(value);
|
alert(value);
|
||||||
return (value.className == "welcome");
|
return (value.className == "welcome");
|
||||||
});
|
});
|
||||||
|
@ -352,10 +352,10 @@ return (value.className == "welcome");
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal <<-EOS.strip, @generator.to_s
|
assert_equal <<-EOS.strip, @generator.to_s
|
||||||
var a = $$('p').inject([], function(memo, value, index) {
|
var a = $$("p").inject([], function(memo, value, index) {
|
||||||
return (value.className == "welcome");
|
return (value.className == "welcome");
|
||||||
});
|
});
|
||||||
var b = $$('p').inject(null, function(memo, value, index) {
|
var b = $$("p").inject(null, function(memo, value, index) {
|
||||||
alert(memo);
|
alert(memo);
|
||||||
return (value.className == "welcome");
|
return (value.className == "welcome");
|
||||||
});
|
});
|
||||||
|
@ -364,7 +364,7 @@ return (value.className == "welcome");
|
||||||
|
|
||||||
def test_collection_proxy_with_pluck
|
def test_collection_proxy_with_pluck
|
||||||
@generator.select('p').pluck('a', 'className')
|
@generator.select('p').pluck('a', 'className')
|
||||||
assert_equal %(var a = $$('p').pluck("className");), @generator.to_s
|
assert_equal %(var a = $$("p").pluck("className");), @generator.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_collection_proxy_with_zip
|
def test_collection_proxy_with_zip
|
||||||
|
@ -380,9 +380,17 @@ return array.reverse();
|
||||||
});
|
});
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_debug_rjs
|
||||||
|
ActionView::Base.debug_rjs = true
|
||||||
|
@generator['welcome'].replace_html 'Welcome'
|
||||||
|
assert_equal "try {\n$(\"welcome\").update(\"Welcome\");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); throw e }", @generator.to_s
|
||||||
|
ensure
|
||||||
|
ActionView::Base.debug_rjs = false
|
||||||
|
end
|
||||||
|
|
||||||
def test_class_proxy
|
def test_class_proxy
|
||||||
@generator.form.focus('my_field')
|
@generator.form.focus('my_field')
|
||||||
assert_equal "Form.focus(\"my_field\");", @generator.to_s
|
assert_equal "Form.focus(\"my_field\");", @generator.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue