Create links automatically

Hi! I’ve been looking around in the plugins that are there for Radiant
and I can’t seem to find anything directly that does this, so I’m asking
here to see if anyone has implemented these/ knows of something that
implements these (or if I just haven’t found it).

  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.

  2. Create links for known entities
    It would be good to have a mechanism that automatically creates links to
    known entities. For example, I’d like to set up SampleSite as being
    http://example.org and then every time, I include SampleSite, it
    automatically creates a link to http://example.org. I don’t want it to
    be automatic (so we don’t need to parse all the text) - it’s good enough
    if I have to pass the name to a tag. I imagine that this would be 2
    parts - 1 part would be a tab in the admin section allowing the user to
    set up any of the pre-defined entities (I think the link_roll extension
    points in the correct direction) and then a tag that allows the user to
    get back the link.

Any ideas?

Cheers,
Mohit.
8/13/2007 | 10:53 AM.

  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.

get back the link.

This sounds like an extension… take a look at the wiki on How to
Create an Extension. It explains how to create a LinkRoll, but the
concepts are very similar.

Sean

Sean C. wrote:

good enough if I have to pass the name to a tag. I imagine that this
Sean

Thanks for the reply, Sean. I’m sure that the second one can be modeled
directly on your (excelent) LinkRoll extension tutorial. The concept is
quite similar. As for the first one, umm, I need to look up on filters
again - since I’ve spent some time with extensions, admittedly an
extension seems easier! But, I shall take a look on using a filter
instead…

Cheers,
Mohit.
8/14/2007 | 12:08 AM.

Thanks for the reply, Sean. I’m sure that the second one can be
modeled directly on your (excelent) LinkRoll extension tutorial. The
concept is quite similar. As for the first one, umm, I need to look
up on filters again - since I’ve spent some time with extensions,
admittedly an extension seems easier! But, I shall take a look on
using a filter instead…

John wrote the tutorial ;). Actually you can package the first one in
an extension too! There are two primary components to a filter:

  1. The filter class itself
  2. The filter reference

The first you can model after the markdown or textile filters that are
included in the normal distribution. If you want to see another
example, check out the Sass filter extension.

The filter reference is a fragment of HTML that will be displayed in the
admin interface. You can either use the “description” (for shorter,
inline descriptions) or “description_file” (for text stored in a file)
class methods to specify the reference. Check out the included .html
files in the filter extensions for examples.

Sean

Sean C. wrote:

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"

/>
}
tag ‘teao:autolink’ do |tag|
link = tag.attr[‘url’]
descr = tag.attr[‘descr’] || link
“<a href="#{url}" title="#{descr}">#{descr}”
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"

/>
}
tag ‘teao:automail’ do |tag|
link = tag.attr[‘url’]
name = tag.attr[‘name’] || link
“<a href="mailto:#{url}" title="#{name}">#{name}”
end

Mohit S. wrote:

needed.

and learn.

Cheers
Mohit.

As luck would have it, I posted you the wrong version! I’m embarrassed
but here are the new ones.

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" /></code></pre>

}
tag ‘teao:autolink’ do |tag|
url = tag.attr[‘url’]
descr = tag.attr[‘descr’] || url
“<a href=”#{url}" title="#{descr}">#{descr}"
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]" /></code></pre>

}
tag ‘teao:automail’ do |tag|
url = tag.attr[‘url’]
name = tag.attr[‘name’] || url
“<a href=“mailto:#{url}” title=”#{name}">#{name}"
end

Mohit.

Sean C. wrote:

Thanks for the reply, Sean. I’m sure that the second one can be
modeled directly on your (excelent) LinkRoll extension tutorial. The
concept is quite similar. As for the first one, umm, I need to look
up on filters again - since I’ve spent some time with extensions,
admittedly an extension seems easier! But, I shall take a look on
using a filter instead…

John wrote the tutorial ;).

Ooopss… my apologies!

Actually you can package the first one in
an extension too! There are two primary components to a filter:

  1. The filter class itself
  2. The filter reference

The first you can model after the markdown or textile filters that are
included in the normal distribution. If you want to see another
example, check out the Sass filter extension.

I certainly don’t know enough about filters but at least for Textile and
Markdown, it appears that you can only pick one or the other. I love
Textile and certainly don’t want to repeat the work for rendering
everything else. I only need something that DRYs up the typing of URLs
when writing up the text. (At first, I thought you meant something like
an after or before filter and that made some sense in my head). I think
it may be easiest for me to start by looking at the Sass filter and/ or
just sticking with an extension for now (now = after I write it).

The filter reference is a fragment of HTML that will be displayed in the
admin interface. You can either use the “description” (for shorter,
inline descriptions) or “description_file” (for text stored in a file)
class methods to specify the reference. Check out the included .html
files in the filter extensions for examples.

Sean

Thanks again, Sean!

Cheers,
Mohit.
8/14/2007 | 2:00 AM.