# Inserting a local HTML page

**URL:** <https://www.ruby-forum.com/t/inserting-a-local-html-page/108509>\
**Category:** Radiant CMS\
**Created:** [July 4, 2007, 7:53am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509 "2007-07-04T07:53:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 7:53am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/1 "2007-07-04T07:53:17Z")

</div>

Would it be possible to insert a local html page into a  
radiant page? The situation is that I have scrapped some  
info from a webpage and now want to include it into  
a Radiant page that will serve as the ‘Newsroom’.

any hints would be appreciated.

thanks  
saji

–  
Saji N. Hameed

APEC Climate Center +82 51 668 7470  
National Pension Corporation Busan Building 12F  
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 removed\_email\_address@domain.invalid  
KOREA

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 8:37am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/2 "2007-07-04T08:37:21Z")

</div>

Quick and dirty method would be to load the page into an iFrame in  
one of the Radiant pages.

More elegantly, you could probably use an Ajax method to put the  
contents of the page into a DIV on the Radiant page.

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 8:42am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/3 "2007-07-04T08:42:22Z")

</div>

hm… why not just copy HTML into Radiant page?

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 8:45am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/4 "2007-07-04T08:45:22Z")

</div>

Thanks a lot. I will go for the iFrame method for the time being.

saji

- d n [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [2007-07-03 23:35:33 -0700]:

> > radiant page? The situation is that I have scrapped some
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Saji N. Hameed

APEC Climate Center +82 51 668 7470  
National Pension Corporation Busan Building 12F  
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 removed\_email\_address@domain.invalid  
KOREA

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 8:47am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/5 "2007-07-04T08:47:24Z")

</div>

> hm… why not just copy HTML into Radiant page?

because the content of the page is constructed automatically by  
scrapping News pages from say google news. Hence it would not be  
convenient to cut-and-paste by hand, say everyday.

saji  
…

- Keymone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [2007-07-04 09:40:45 +0300]:

> > > saji  
> > > Radiant mailing list
> 
> –  
> Regards, Keymone
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Saji N. Hameed

APEC Climate Center +82 51 668 7470  
National Pension Corporation Busan Building 12F  
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 removed\_email\_address@domain.invalid  
KOREA

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 10:28am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/6 "2007-07-04T10:28:32Z")

</div>

Some time ago I used this method to include static html pages in a  
Radiant site without using iframes. This method is far from to be  
cmplete, there are many improvements, adn I hope I will have time to do  
them, but it works. The biggest problem to resolve is the redirection of  
inner links. I am working on this using apricot, but this part is not  
complete. I hope I will be able to complete it soon.  
If you need more feel free to ask me.

The possibility of capturing query parameters is not limited to  
addressing different part of pages, but it could be useful in many ways,  
I hope this possibility will be included in standard radiant  
distribution.  
In this case I used it to include static html pages into radiant  
generated pages.  
I have a customer that decided one of his emplyee MUST do some pages  
using an editor like nvu. (Learning to use radiant cms is too difficult  
for her)  
But the rest of the site is generated from radiant, menu and pages etc.  
For the moment the tag is customised to my needs, but I think it could  
be easily modified to any needs.  
First of all I modified the site\_controller.rb according to this post  
[http://lists.radiantcms.org/pipermail/radiant/2007-February/003480.html](http://lists.radiantcms.org/pipermail/radiant/2007-February/003480.html)

Then I created a custom tag

…  
require ‘net/http’  
require ‘uri’

tag ‘inner\_site’ do |tag|

# site is the url of the site I want to include risposta is the html

page I will get back

```
site = tag.attr['site']
risposta=""

```

# this is the radiant pag with “inner\_site” tag for example

[http://www.mysite.org/including](http://www.mysite.org/including)

# the page “including” shoud be simply \<r:inner\_site

site=“[http://radiantcms.org](http://radiantcms.org)” /\>

```
server=request.env['PATH_INFO']

```

# this caputures the query string parameter (it should be made better

capturing all parameters in a hash with name and value, bu for the  
moment it woks) The var @pagina contains the stati html page I want to  
include. i.e /html/iniziative.html

```
tag.globals.page.request.params.each do | param |
  @pagina = param[1].to_s.dup
end
if site
  url = URI.parse(site)
  res = Net::HTTP.start(url.host, url.port) {|http|
    @pagina ? http.get(@pagina) : http.get("/html/iniziative.html")
  }

```

# here I replace every internal link with a link to the radiant page

adding in the url the query string for the new page  
#external links (those starting with http://) are leaved unchanged

# this part need a lot of work to be useful in every situation (pages

made with mac osx have different new line charachter, there should be a  
better way to control if the link is internal or external) but form my  
needs work enought.

# images and css paths are unchanged, so you will not see images and css

formatting  
res.body.each\_line {|line|  
risposta+= line=~/http/ ? line :  
line.gsub(/href=“(.\*)”/,“href="#{server}?pag=”+‘\1"’)  
}  
end  
risposta  
end

now you can use this form to include radiant site in your page  
[http://www.mysite.org/including?pag=/index](http://www.mysite.org/including?pag=/index)

–  
Francesco L.  
Ymir s.r.l.  
Viale Verona 190/11  
38100 Trento

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 8:48am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/7 "2007-07-04T08:48:24Z")

</div>

oh… sorry 🙂 missed that one

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/8 "2007-07-04T18:10:30Z")

</div>

This is a great alternative to messy iframes…

Have you considered making this an extension, to easily add the tag,  
and possibly a GUI to manage external pages, so they can be handled  
by a name or other identifier, with the record keeping track of URL  
and query parameters?

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 4, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/9 "2007-07-04T22:17:57Z")

</div>

Another alternative is to have your automatic scraping process run a  
Ruby script (with script/runner) that loads the result of your  
scraping into a page-part or snippet. Then you can freely use this in  
your pages and be confident that it will be updated automatically.

Sean

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 5, 2007, 3:00am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/10 "2007-07-05T03:00:16Z")

</div>

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  
…

- Francesco L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [2007-07-04 10:26:35 +0200]:

> for her)  
> require ‘uri’  
> [http://www.mysite.org/including](http://www.mysite.org/including)  
> tag.globals.page.request.params.each do | param |
> 
> # this part need a lot of work to be useful in every situation (pages
> 
> ```
> risposta
> 
> ```
> 
> Ymir s.r.l.  
> Viale Verona 190/11  
> 38100 Trento
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Saji N. Hameed

APEC Climate Center +82 51 668 7470  
National Pension Corporation Busan Building 12F  
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 removed\_email\_address@domain.invalid  
KOREA

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 5, 2007, 3:05am UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/11 "2007-07-05T03:05:17Z")

</div>

Sean,

Thanks for this suggestion. Earlier the folks in the list helped me  
to write a script to automate the creation of a page. I will try  
using this to automatically create a page.

Nevertheless it will be nice if Radiant had a way to insert  
local html files in an easy way (something in the way Francesco  
is pointing to ).

thanks,

saji  
…

- Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [2007-07-04 15:17:08 -0500]:

> > because the content of the page is constructed automatically by
> > 
> > > On 7/4/07, d n [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > > 
> > > > > Would it be possible to insert a local html page into a  
> > > > > Saji N. Hameed  
> > > > > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)  
> > > > > –  
> > > > > APEC Climate Center +82 51 668 7470  
> > > > > Radiant mailing list  
> > > > > Post: removed\_email\_address@domain.invalid  
> > > > > Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> > > > > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Saji N. Hameed

APEC Climate Center +82 51 668 7470  
National Pension Corporation Busan Building 12F  
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 removed\_email\_address@domain.invalid  
KOREA

---

<div class="post-metadata">

**Author:** ![saji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@saji](https://www.ruby-forum.com/u/saji)\
**Post date:** [July 5, 2007, 2:52pm UTC](https://www.ruby-forum.com/t/inserting-a-local-html-page/108509/12 "2007-07-05T14:52:15Z")

</div>

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
