Sean Cribbs wrote:
>
>> 1. Automatically create links for URL.
>> I'd like to be able to type in http://example.org or [EMAIL PROTECTED] 
>> and have a link created to it.  If I use Textile, I need to do this 
>> as "http://example.org":http://example.org - just wondering if 
>> there's a tag I can use (else, I think I should just write it up).  I 
>> think Rails has a function called auto_link that can do this for text 
>> content - just need to think about any vulnerabilities that this may 
>> have.  I imagine that this would only be a tag, no database backend 
>> needed.
>>
>>   
> This sounds like a good candidate for a filter.  You could probably 
> harness the helper modules in ActionView to use auto_link or 
> simple_format in a filter.
>

Hi Everyone,

About a month back, I had asked if there was a way to automatically 
create links/ mail.  I thought of it mostly cos I was using textile and 
would often do something like: 
"http://www.onghu.com":http://www.onghu.com to get it to work.

I am now in the midst of updating the site that needs this, so I wrote 
up a couple of tags for it and I'm enclosing it here in case someone 
needs it.  I'm sure the code can be made prettier and there's a lot more 
that can be done with this, but these meet my needs for now.  If you add 
something, it would be good if you could let me know so that I can watch 
and learn.

Cheers
Mohit.

==== The Tags ====
  desc %{
    Renders a URL as a link.  'url' is the full URL (including http:// 
or ftp://) and 'descr' is the text that should be
    rendered as the title (for mouse over) and the link text.  If 
'descr' is not specified, 'link' is used.
   
    *Usage*:
   
    <pre><code><r:teao:autolink url="http://onghu.com";  descr="My Site" 
/></code></pre>
  }
  tag 'teao:autolink' do |tag|
    link  = tag.attr['url']
    descr = tag.attr['descr'] || link
    "<a href=\"#{url}\" title=\"#{descr}\">#{descr}</a>"
  end
 
  desc %{
    Converts an email address into a link.  'url' is the email address 
(without mailto) and 'name' is the name that should be
    rendered as the title (for mouse over) and the link text.  If 'name' 
is not specified, 'url' is used.
   
    *Usage*:
   
    <pre><code><r:teao:automail url="[EMAIL PROTECTED]" descr="Don't email" 
/></code></pre>
  }
  tag 'teao:automail' do |tag|
    link  = tag.attr['url']
    name = tag.attr['name'] || link
    "<a href=\"mailto:#{url}\"; title=\"#{name}\">#{name}</a>"
  end



_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to