Eu avisei no último artigo desta série que muitos métodos do Rails seriam alterados para deixarem de receber seus parâmetros da forma convencional e passariam a recebe-los via um Hash de opções.
Pois bem, agora chegou a vez dos métodos truncate, highlight, excerpt, word_wrap e auto_link serem atualizados. Veja como eles devem ser usados a partir da próxima versão do Rails:
truncate
truncate("Once upon a time in a world far far away")
# => Once upon a time in a world f...
truncate("Once upon a time in a world far far away", :length => 14)
# => Once upon a...
truncate("And they found that many people were sleeping better.", :omission => "... (continued)", :length => 15)
# => And they found... (continued)
highlight
highlight('You searched for: rails', ['for', 'rails'], :highlighter => '<em>\1</em>')
# => You searched <em>for</em>: <em>rails</em>
highlight('You searched for: rails', 'rails', :highlighter => '<a href="search?q=\1">\1</a>')
# => You searched for: <a href="search?q=rails">rails</a>
excerpt
excerpt('This is an example', 'an', :radius => 5)
# => ...s is an exam...
excerpt('This is an example', 'is', :radius => 5)
# => This is a...
excerpt('This next thing is an example', 'ex', :radius => 2)
# => ...next...
excerpt('This is also an example', 'an', :radius => 8, :omission => '<chop> ')
# => <chop> is also an example
word_wrap
word_wrap('Once upon a time', :line_width => 8)
# => Once upon\na time
word_wrap('Once upon a time', :line_width => 1)
# => Once\nupon\na\ntime
auto_link
post_body = "Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com."
auto_link(post_body, :urls)
# => "Welcome to my new blog at <a href=\"http://www.myblog.com/\">http://www.myblog.com</a>. Please e-mail me at me@email.com."
auto_link(post_body, :all, :target => "_blank")
# => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.myblog.com</a>. Please e-mail me at <a href=\"mailto:me@email.com\">me@email.com</a>."
Todos os métodos continuam funcionando da forma antiga por enquanto, mas alertas serão emitidos no terminal para lembra-lo de atualizar seu código o mais rápido possível.