[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Auto-recognize links?

Josh Pigford

10/8/2008 9:54:00 PM

In PHP I've got a few functions that will turn data into links based on
if it recognizes "http://", "www." etc etc.

How can I do this with Ruby?

For instance, in a forums setting if a user posted a link to something
like http://e...

It'd basically turn it into a clickable link:
<a
href="http://e...">http://e...</a>
--
Posted via http://www.ruby-....

3 Answers

Ted Han

10/8/2008 10:20:00 PM

0

I think everything you'd need to do to validate and produce links should
be in the core URI class: http://www.ruby-doc.org/core/classe...

Josh Pigford wrote:
> In PHP I've got a few functions that will turn data into links based on
> if it recognizes "http://", "www." etc etc.
>
> How can I do this with Ruby?
>
> For instance, in a forums setting if a user posted a link to something
> like http://e...
>
> It'd basically turn it into a clickable link:
> <a
> href="http://e...">http://e...</a>

--
Posted via http://www.ruby-....

Henrik Nyh

10/8/2008 11:10:00 PM

0

On Thu, Oct 9, 2008 at 12:20 AM, Ted Han <notheory@gmail.com> wrote:
> I think everything you'd need to do to validate and produce links should
> be in the core URI class: http://www.ruby-doc.org/core/classe...

Interesting, did not know that. Seems bad though:
URI.extract("Visit http://google.c...) # => ["http://google.c...]

You could borrow code from Rails' auto_link() which handles that kind
of stuff better:
http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.ht...

> Josh Pigford wrote:
>> In PHP I've got a few functions that will turn data into links based on
>> if it recognizes "http://", "www." etc etc.
>>
>> How can I do this with Ruby?
>>
>> For instance, in a forums setting if a user posted a link to something
>> like http://e...
>>
>> It'd basically turn it into a clickable link:
>> &lt;a
>> href=&quot;http://e...&quot;&gt;http://e...&lt;/a&gt;
>
> --
> Posted via http://www.ruby-....
>
>

lrlebron@gmail.com

10/10/2008 8:59:00 PM

0

On Oct 8, 6:09 pm, Henrik Nyh <hen...@nyh.se> wrote:
> On Thu, Oct 9, 2008 at 12:20 AM, Ted Han <nothe...@gmail.com> wrote:
> > I think everything you'd need to do to validate and produce links should
> > be in the core URI class:http://www.ruby-doc.org/core/classe...
>
> Interesting, did not know that. Seems bad though:
> URI.extract("Visithttp://google.c...)  # => ["http://google.c...]
>
> You could borrow code from Rails' auto_link() which handles that kind
> of stuff better:http://api.rubyonrails.com/classes/ActionView/Helpers/TextH......
>
>
>
> > Josh Pigford wrote:
> >> In PHP I've got a few functions that will turn data into links based on
> >> if it recognizes "http://", "www." etc etc.
>
> >> How can I do this with Ruby?
>
> >> For instance, in a forums setting if a user posted a link to something
> >> likehttp://e...
>
> >> It'd basically turn it into a clickable link:
> >> &lt;a
> >> href=&quot;http://e...">http://e...</a>
>
> > --
> > Posted viahttp://www.ruby-fo... Hide quoted text -
>
> - Show quoted text -

Have you looked at hpricot