Relative To Absolute Path Convertor

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:
...
<script src="/script.js"></script>
<a href="link.html">some link</a>
...

converted content:
...
<script src="http://mysite.com/script.js"></script>
< a href="http://mysite.com/folder/link.html">some link</ a>
...

How can I accomplish this using ruby ?

···

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

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

···

--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

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:
...
<script src="/script.js"></script>
<a href="link.html">some link</a>
...

converted content:
...
<script src="http://mysite.com/script.js&quot;&gt;&lt;/script&gt;
< a href="http://mysite.com/folder/link.html&quot;&gt;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&quot;\)
  => #<URI::HTTP:0x4160a54 URL:http://mysite.com/folder/url.html&gt;
  >> base.merge("/script.js").to_s
  => "http://mysite.com/script.js&quot;
  >> base.merge("link.html").to_s
  => "http://mysite.com/folder/link.html&quot;

···

On 6/19/07, ciocan <ciocan@gmail.com> wrote: