From d76ef6fa6cd34f4c7023706e8b8b4eb8a6a03b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 6 Oct 2012 22:00:06 -0300 Subject: Update some code styles. * Uses the Ruby 1.9 hash syntax * Avoid escaping " inside string using the %{} syntax --- actionpack/lib/action_view/helpers/url_helper.rb | 98 ++++++++++++------------ 1 file changed, 48 insertions(+), 50 deletions(-) (limited to 'actionpack/lib/action_view/helpers/url_helper.rb') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index e8b3b14265..5105d0e585 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -46,7 +46,6 @@ module ActionView end protected :_back_url - # Creates a link tag of the given +name+ using a URL created by the set of +options+. # See the valid options in the documentation for +url_for+. It's also possible to # pass a String instead of an options hash, which generates a link tag that uses the @@ -115,7 +114,7 @@ module ActionView # # in place of the older more verbose, non-resource-oriented # - # link_to "Profile", :controller => "profiles", :action => "show", :id => @profile + # link_to "Profile", controller: "profiles", action: "show", id: @profile # # => Profile # # Similarly, @@ -125,7 +124,7 @@ module ActionView # # is better than # - # link_to "Profiles", :controller => "profiles" + # link_to "Profiles", controller: "profiles" # # => Profiles # # You can use a block as well if your link target is hard to fit into the name parameter. ERB example: @@ -139,38 +138,38 @@ module ActionView # # Classes and ids for CSS are easy to produce: # - # link_to "Articles", articles_path, :id => "news", :class => "article" + # link_to "Articles", articles_path, id: "news", class: "article" # # => Articles # # Be careful when using the older argument style, as an extra literal hash is needed: # - # link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article" + # link_to "Articles", { controller: "articles" }, id: "news", class: "article" # # => Articles # # Leaving the hash off gives the wrong link: # - # link_to "WRONG!", :controller => "articles", :id => "news", :class => "article" + # link_to "WRONG!", controller: "articles", id: "news", class: "article" # # => WRONG! # # +link_to+ can also produce links with anchors or query strings: # - # link_to "Comment wall", profile_path(@profile, :anchor => "wall") + # link_to "Comment wall", profile_path(@profile, anchor: "wall") # # => Comment wall # - # link_to "Ruby on Rails search", :controller => "searches", :query => "ruby on rails" + # link_to "Ruby on Rails search", controller: "searches", query: "ruby on rails" # # => Ruby on Rails search # - # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux") + # link_to "Nonsense search", searches_path(foo: "bar", baz: "quux") # # => Nonsense search # # The only option specific to +link_to+ (:method) is used as follows: # - # link_to("Destroy", "http://www.example.com", :method => :delete) + # link_to("Destroy", "http://www.example.com", method: :delete) # # => Destroy # # You can also use custom data attributes using the :data option: # - # link_to "Visit Other Site", "http://www.rubyonrails.org/", :data => { :confirm => "Are you sure?" } + # link_to "Visit Other Site", "http://www.rubyonrails.org/", data: { confirm: "Are you sure?" } # # => Visit Other Site def link_to(name = nil, options = nil, html_options = nil, &block) html_options, options = options, name if block_given? @@ -197,7 +196,7 @@ module ActionView # the form submission and input element behavior using +html_options+. # This method accepts the :method modifier described in the +link_to+ documentation. # If no :method modifier is given, it will default to performing a POST operation. - # You can also disable the button by passing :disabled => true in +html_options+. + # You can also disable the button by passing disabled: true in +html_options+. # If you are using RESTful routes, you can pass the :method # to change the HTTP verb used to submit the form. # @@ -226,7 +225,7 @@ module ActionView # by the unobtrusive JavaScript driver. # # ==== Examples - # <%= button_to "New", :action => "new" %> + # <%= button_to "New", action: "new" %> # # => "
# #
# #
" @@ -242,13 +241,13 @@ module ActionView # # # # " # - # <%= button_to "New", :action => "new", :form_class => "new-thing" %> + # <%= button_to "New", action: "new", form_class: "new-thing" %> # # => "
# #
# #
" # # - # <%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %> + # <%= button_to "Create", action: "create", remote: true, form: { "data-type" => "json" } %> # # => "
# #
# # @@ -257,8 +256,8 @@ module ActionView # # " # # - # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, - # :method => :delete, :data => { :confirm => "Are you sure?" } %> + # <%= button_to "Delete Image", { action: "delete", id: @image.id }, + # method: :delete, data: { confirm: "Are you sure?" } %> # # => "
# #
# # @@ -269,7 +268,7 @@ module ActionView # # # <%= button_to('Destroy', 'http://www.example.com', - # :method => "delete", :remote => true, :data => { :confirm' => 'Are you sure?', :disable_with => 'loading...' }) %> + # method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %> # # => " # #
# # @@ -295,7 +294,7 @@ module ActionView form_method = method == 'get' ? 'get' : 'post' form_options = html_options.delete('form') || {} form_options[:class] ||= html_options.delete('form_class') || 'button_to' - form_options.merge!(:method => form_method, :action => url) + form_options.merge!(method: form_method, action: url) form_options.merge!("data-remote" => "true") if remote request_token_tag = form_method == 'post' ? token_tag : '' @@ -314,7 +313,6 @@ module ActionView content_tag('form', content_tag('div', inner_tags), form_options) end - # Creates a link tag of the given +name+ using a URL created by the set of # +options+ unless the current request URI is the same as the links, in # which case only the name is returned (or the given block is yielded, if @@ -326,8 +324,8 @@ module ActionView # Let's say you have a navigation menu... # # # # If in the "about" action, it will render... @@ -349,8 +347,8 @@ module ActionView # "Go Back" link instead of a link to the comments page, we could do something like this... # # <%= - # link_to_unless_current("Comment", { :controller => "comments", :action => "new" }) do - # link_to("Go back", { :controller => "posts", :action => "index" }) + # link_to_unless_current("Comment", { controller: "comments", action: "new" }) do + # link_to("Go back", { controller: "posts", action: "index" }) # end # %> def link_to_unless_current(name, options = {}, html_options = {}, &block) @@ -364,13 +362,13 @@ module ActionView # accepts the name or the full argument list for +link_to_unless+. # # ==== Examples - # <%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %> + # <%= link_to_unless(@current_user.nil?, "Reply", { action: "reply" }) %> # # If the user is logged in... # # => Reply # # <%= - # link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name| - # link_to(name, { :controller => "accounts", :action => "signup" }) + # link_to_unless(@current_user.nil?, "Reply", { action: "reply" }) do |name| + # link_to(name, { controller: "accounts", action: "signup" }) # end # %> # # If the user is logged in... @@ -396,13 +394,13 @@ module ActionView # in +link_to_unless+). # # ==== Examples - # <%= link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) %> + # <%= link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) %> # # If the user isn't logged in... # # => Login # # <%= - # link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) do - # link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user }) + # link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) do + # link_to(@current_user.login, { controller: "accounts", action: "show", id: @current_user }) # end # %> # # If the user isn't logged in... @@ -443,17 +441,17 @@ module ActionView # mail_to "me@domain.com" # # => me@domain.com # - # mail_to "me@domain.com", "My email", :encode => "javascript" + # mail_to "me@domain.com", "My email", encode: "javascript" # # => # - # mail_to "me@domain.com", "My email", :encode => "hex" + # mail_to "me@domain.com", "My email", encode: "hex" # # => My email # - # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email" + # mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email" # # => # - # mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com", - # :subject => "This is an example email" + # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com", + # subject: "This is an example email" # # => My email def mail_to(email_address, name = nil, html_options = {}) email_address = ERB::Util.html_escape(email_address) @@ -502,47 +500,47 @@ module ActionView # ==== Examples # Let's say we're in the /shop/checkout?order=desc action. # - # current_page?(:action => 'process') + # current_page?(action: 'process') # # => false # - # current_page?(:controller => 'shop', :action => 'checkout') + # current_page?(controller: 'shop', action: 'checkout') # # => true # - # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc') + # current_page?(controller: 'shop', action: 'checkout', order: 'asc') # # => false # - # current_page?(:action => 'checkout') + # current_page?(action: 'checkout') # # => true # - # current_page?(:controller => 'library', :action => 'checkout') + # current_page?(controller: 'library', action: 'checkout') # # => false # # Let's say we're in the /shop/checkout?order=desc&page=1 action. # - # current_page?(:action => 'process') + # current_page?(action: 'process') # # => false # - # current_page?(:controller => 'shop', :action => 'checkout') + # current_page?(controller: 'shop', action: 'checkout') # # => true # - # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page => '1') + # current_page?(controller: 'shop', action: 'checkout', order: 'desc', page: '1') # # => true # - # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page => '2') + # current_page?(controller: 'shop', action: 'checkout', order: 'desc', page: '2') # # => false # - # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc') + # current_page?(controller: 'shop', action: 'checkout', order: 'desc') # # => false # - # current_page?(:action => 'checkout') + # current_page?(action: 'checkout') # # => true # - # current_page?(:controller => 'library', :action => 'checkout') + # current_page?(controller: 'library', action: 'checkout') # # => false # # Let's say we're in the /products action with method POST in case of invalid product. # - # current_page?(:controller => 'product', :action => 'index') + # current_page?(controller: 'product', action: 'index') # # => false # def current_page?(options) @@ -642,14 +640,14 @@ module ActionView def token_tag(token=nil) if token != false && protect_against_forgery? token ||= form_authenticity_token - tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => token) + tag(:input, type: "hidden", name: request_forgery_protection_token.to_s, value: token) else '' end end def method_tag(method) - tag('input', :type => 'hidden', :name => '_method', :value => method.to_s) + tag('input', type: 'hidden', name: '_method', value: method.to_s) end end end -- cgit v1.2.3