Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate JavaScriptHelper#update_element_function, which is supersee…
…ded by RJS [Thomas Fuchs] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5438 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
- Loading branch information
Showing
5 changed files
with
72 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module ActionView | ||
module Helpers | ||
module PrototypeHelper | ||
|
||
def update_element_function(element_id, options = {}, &block) | ||
content = escape_javascript(options[:content] || '') | ||
content = escape_javascript(capture(&block)) if block | ||
|
||
javascript_function = case (options[:action] || :update) | ||
when :update | ||
if options[:position] | ||
"new Insertion.#{options[:position].to_s.camelize}('#{element_id}','#{content}')" | ||
else | ||
"$('#{element_id}').innerHTML = '#{content}'" | ||
end | ||
|
||
when :empty | ||
"$('#{element_id}').innerHTML = ''" | ||
|
||
when :remove | ||
"Element.remove('#{element_id}')" | ||
|
||
else | ||
raise ArgumentError, "Invalid action, choose one of :update, :remove, :empty" | ||
end | ||
|
||
javascript_function << ";\n" | ||
options[:binding] ? concat(javascript_function, options[:binding]) : javascript_function | ||
end | ||
deprecate :update_element_function => "use RJS instead" | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require File.dirname(__FILE__) + '/../abstract_unit' | ||
|
||
class DeprecatedHelperTest < Test::Unit::TestCase | ||
include ActionView::Helpers::JavaScriptHelper | ||
include ActionView::Helpers::CaptureHelper | ||
|
||
def test_update_element_function | ||
assert_deprecated 'update_element_function' do | ||
|
||
assert_equal %($('myelement').innerHTML = 'blub';\n), | ||
update_element_function('myelement', :content => 'blub') | ||
assert_equal %($('myelement').innerHTML = 'blub';\n), | ||
update_element_function('myelement', :action => :update, :content => 'blub') | ||
assert_equal %($('myelement').innerHTML = '';\n), | ||
update_element_function('myelement', :action => :empty) | ||
assert_equal %(Element.remove('myelement');\n), | ||
update_element_function('myelement', :action => :remove) | ||
|
||
assert_equal %(new Insertion.Bottom('myelement','blub');\n), | ||
update_element_function('myelement', :position => 'bottom', :content => 'blub') | ||
assert_equal %(new Insertion.Bottom('myelement','blub');\n), | ||
update_element_function('myelement', :action => :update, :position => :bottom, :content => 'blub') | ||
|
||
_erbout = "" | ||
assert_equal %($('myelement').innerHTML = 'test';\n), | ||
update_element_function('myelement') { _erbout << "test" } | ||
|
||
_erbout = "" | ||
assert_equal %($('myelement').innerHTML = 'blockstuff';\n), | ||
update_element_function('myelement', :content => 'paramstuff') { _erbout << "blockstuff" } | ||
|
||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters