Relative To Absolute Path Convertor


#1

Is there a built in function/plugin that converts
relative paths from a html page to absolute ones?

Example:
target url: http://mysite.com/folder/url.html

url content:

some link

converted content:

< a href=“http://mysite.com/folder/link.html”>some link</ a>

How can I accomplish this using ruby ?


#2

Dear Ciocan,

you could use something like

str=“http://mysite.com/folder/url.html
p File.dirname(str)
p File.basename(str)
p File.basename(str,".html")

Best regards,

Axel


#3

On 6/19/07, ciocan removed_email_address@domain.invalid wrote:

converted content:

< a href=“http://mysite.com/folder/link.html”>some link</ a>

How can I accomplish this using ruby ?

Use URI#merge:

require ‘uri’
=> true

base = URI.parse(“http://mysite.com/folder/url.html”)
=> #<URI::HTTP:0x4160a54 URL:http://mysite.com/folder/url.html>

base.merge("/script.js").to_s
=> “http://mysite.com/script.js

base.merge(“link.html”).to_s
=> “http://mysite.com/folder/link.html