Saji Njarackalazhikam H. ha scritto:
Francesco,
Thanks very much. I am using Radiant 0.6.1. Do I still have to modify the site_controller.rb?
That is something I would like to avoid if possible.
saji
…
I made this on a Radiant 0.6.1 if I am not worng you have to modify the
controller, but I am sure someone else on this list can confirm this
bettere than me.
I post a little more recent version of my tag.
It is still far from to be complete.
It is a snapshot of code I was working on, I was doing some speed tests
page loading in two ways, using curl and using pure ruby method.
But the bottleneck wasn’t there but in the url rewriting.
The url rewriting in this method
res.body.each_line {|line|
risposta+= line=~/http/ ? line :
line.gsub(/href="(.*)"/,“href=”#{server}?pag="+’\1"’)
}
works but with unpredictable speed. In my tests sometimes it is quick
enought, sometimes it require too much time to complete.
Another problem to solve is in this line of code: res.body.each_line
{|line|… the method each.line dosnt’ wotk correctly with different
endline charachters (unix windows machintosh) so before it you should
execute a test to find which endline charachter is the right one.
So I started to do some tests using apricot, but they still wasn’t
functioning.
I will go on developing this tag as soon as I will have time enought to
complete it.
tag ‘inner_site’ do |tag|
site = tag.attr[‘site’]
pag = tag.attr[‘pagina’]
risposta=""
server=request.env[‘PATH_INFO’]
tag.globals.page.request.params.each do | param |
@pagina = param[1].to_s.dup
end
if site
=begin
#----------- curl method --------------
url = @pagina ? URI.parse(site+@pagina) : URI.parse(site+pag)
c = Curl::Easy.perform(url.to_s)
c.body_str.each_line {|line|
risposta+= line=~/http/ ? line :
line.gsub(/href="(.*)"/,“href=”#{server}?pag="+’\1"’)
}
#----------- fine --------------------
=end
------- pure ruby method-------
url = URI.parse(site)
res = Net::HTTP.start(url.host, url.port) {|http|
@pagina ? http.get(@pagina) : http.get(pag)
}
risposta=res.body
#.gsub(/href="(?!http)(.*?)"/,“href=”#{server}?pag="+’\1"’)
res.body.each_line {|line|
risposta+= line=~/http/ ? line :
line.gsub(/href="(.*)"/,“href=”#{server}?pag="+’\1"’)
}
#---------- fine -------------
end
#c.body_str
risposta
end
I hope this could be useful for you.
ciao
–
Francesco L.
Ymir s.r.l.
Viale Verona 190/11
38100 Trento