Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Relative To Absolute Path Convertor
ciocan
6/19/2007 12:18:00 PM
Is there a built in function/plugin that converts
relative paths from a html page to absolute ones?
Example:
target url:
http://mysite.com/folde...
url content:
...
<script src="/script.js"></script>
<a href="link.html">some link</a>
...
converted content:
...
<script src="
http://mysite.com/script.js"></...
< a href="
http://mysite.com/folder/link.html&quo...
link</ a>
...
How can I accomplish this using ruby ?
--
Posted via
http://www.ruby-...
.
2 Answers
Axel Etzold
6/19/2007 1:00:00 PM
0
Dear Ciocan,
you could use something like
str="
http://mysite.com/folder/url....
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/g...
Bob Showalter
6/20/2007 1:03:00 PM
0
On 6/19/07, ciocan <ciocan@gmail.com> wrote:
> Is there a built in function/plugin that converts
> relative paths from a html page to absolute ones?
>
> Example:
> target url:
http://mysite.com/folde...
>
> url content:
> ...
> <script src="/script.js"></script>
> <a href="link.html">some link</a>
> ...
>
> converted content:
> ...
> <script src="
http://mysite.com/scrip...
></...
> < a href="
http://mysite.com/folder/link.html&quo...
link</ a>
> ...
>
> How can I accomplish this using ruby ?
Use URI#merge:
>> require 'uri'
=> true
>> base = URI.parse("
http://mysite.com/folde...
")
=> #<URI::HTTP:0x4160a54 URL:
http://mysite.com/folde...
>
>> base.merge("/script.js").to_s
=> "
http://mysite.com/scrip...
>> base.merge("link.html").to_s
=> "
http://mysite.com/folder/link....
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Relative To Absolute Path Convertor
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password