aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/url_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-06 14:06:33 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-06 14:06:33 +0000
commitfd9967bca2aa32dd4173881c4d8c55f5ebabe97e (patch)
tree06d7e2a012800e33dbbfbf69ccee0d621f08d8df /actionpack/lib/action_view/helpers/url_helper.rb
parent9eb04967a4b7b7382cf5c562d379fdd65ceaaf1b (diff)
downloadrails-fd9967bca2aa32dd4173881c4d8c55f5ebabe97e.tar.gz
rails-fd9967bca2aa32dd4173881c4d8c55f5ebabe97e.tar.bz2
rails-fd9967bca2aa32dd4173881c4d8c55f5ebabe97e.zip
Added UrlHelper#link_to_if/link_to_unless to enable other conditions that just link_to_unless_current #757 [mindel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@852 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 7acfb6407a..3f014d4822 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -86,14 +86,28 @@ module ActionView
# request uri is the same as the link's, in which case only the name is returned (or the
# given block is yielded, if one exists). This is useful for creating link bars where you don't want to link
# to the page currently being viewed.
- def link_to_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference)
- if current_page?(options)
- block_given? ?
- yield(name, options, html_options, *parameters_for_method_reference) :
+ def link_to_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
+ link_to_unless current_page?(options), name, options, html_options, *parameters_for_method_reference, &block
+ end
+
+ # Create a link tag of the given +name+ using an URL created by the set of +options+, unless +condition+
+ # is true, in which case only the name is returned (or the given block is yielded, if one exists).
+ def link_to_unless(condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
+ if condition
+ if block_given?
+ block.arity <= 1 ? yield(name) : yield(name, options, html_options, *parameters_for_method_reference)
+ else
html_escape(name)
+ end
else
link_to(name, options, html_options, *parameters_for_method_reference)
- end
+ end
+ end
+
+ # Create a link tag of the given +name+ using an URL created by the set of +options+, if +condition+
+ # is true, in which case only the name is returned (or the given block is yielded, if one exists).
+ def link_to_if(condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
+ link_to_unless !condition, name, options, html_options, *parameters_for_method_reference, &block
end
# Creates a link tag for starting an email to the specified <tt>email_address</tt>, which is also used as the name of the