[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Add comments to static web pages ?

Its Me

1/20/2005 6:32:00 PM

I have a web of static pages, and would like to allow adding comments at the
ends of any of those pages (and display with those comments). Not
(currently) on Rails or any such framework.

Any suggestions on simple ways (preferably Ruby-based) to do this? Or where
would be a good place to start looking?

Thanks.


7 Answers

Thursday

1/20/2005 7:10:00 PM

0

itsme213 wrote:
> I have a web of static pages, and would like to allow adding comments at the
> ends of any of those pages (and display with those comments). Not
> (currently) on Rails or any such framework.
>
> Any suggestions on simple ways (preferably Ruby-based) to do this? Or where
> would be a good place to start looking?
>
> Thanks.
>
>

How about Instiki? If it doesn't already, perhaps it can be modified to
keep certain portions of the page static.

Aredridel

1/20/2005 7:26:00 PM

0

On Fri, 21 Jan 2005 03:35:59 +0900, itsme213 <itsme213@hotmail.com> wrote:
> I have a web of static pages, and would like to allow adding comments at the
> ends of any of those pages (and display with those comments). Not
> (currently) on Rails or any such framework.
>
> Any suggestions on simple ways (preferably Ruby-based) to do this? Or where
> would be a good place to start looking?
>

Iff the pages are XHTML, it should be really easy to parse them with
REXML, add what you want, and dump them back out again, all with a
script. I'd search to the end of <body>, or some other easy to define
tag (perhaps right after an <hr> with id='postsgohere', even).

The script to do that would trvially be about 20 lines long; perhaps a
bit more with aggressive error checking.

Ari


Nicholas Van Weerdenburg

1/20/2005 7:34:00 PM

0

Do you want to add anything to the static pages, or do it all
magically without touching them?

With ruby cgi you could so something like:

Replace links like this:
http://mysite/page1.html

with:
http://mysite/cgi-bin/enhancepage.rb?page=page1.html&action="comments"

And not have to change the static pages, keeping comments in a file or
database keyed on the page name. You could even use mod_rewrite to do
this automatically, changing no links on the site.

A simple eruby solution would involve changing all the pages from
html to rhtml and use eruby and embedding ruby in the pages. That
could be automated with a script to add some ruby code to the bottom
of each page to include the comment logic.

Nick
--
Nicholas Van Weerdenburg

On Fri, 21 Jan 2005 03:35:59 +0900, itsme213 <itsme213@hotmail.com> wrote:
> I have a web of static pages, and would like to allow adding comments at the
> ends of any of those pages (and display with those comments). Not
> (currently) on Rails or any such framework.
>
> Any suggestions on simple ways (preferably Ruby-based) to do this? Or where
> would be a good place to start looking?
>
> Thanks.
>
>


Douglas Livingstone

1/20/2005 7:35:00 PM

0

On Fri, 21 Jan 2005 03:35:59 +0900, itsme213 <itsme213@hotmail.com> wrote:
> Any suggestions on simple ways (preferably Ruby-based) to do this? Or where
> would be a good place to start looking?

I don't know how to do it in Ruby (I'm just just starting) but you can
use Apache/PHP if you want. Have a look here:

http://www.ilovejackdaniels.com/php/google-style-keyword-hig...

That describes a way to attach a PHP file at the beginning and end of
every file in a directory. Instead of a word highlighting script,
replace it with a script to pull comments from a database. The last
step is to set the following in your .htaccess file to make html files
act as PHP files:

AddType application/x-httpd-php html htm

Can this be done with Ruby?

Douglas


Douglas Livingstone

1/20/2005 7:36:00 PM

0

On Fri, 21 Jan 2005 04:25:58 +0900, Aredridel <aredridel@gmail.com> wrote:
> Iff the pages are XHTML, it should be really easy to parse them with
> REXML, add what you want, and dump them back out again, all with a
> script. I'd search to the end of <body>, or some other easy to define
> tag (perhaps right after an <hr> with id='postsgohere', even).
>
> The script to do that would trvially be about 20 lines long; perhaps a
> bit more with aggressive error checking.
>

How do you get Ruby to phrase the file if the URL is
http://example.com/... for example?

Douglas


Eric Anderson

1/20/2005 9:40:00 PM

0

itsme213 wrote:
> I have a web of static pages, and would like to allow adding comments at the
> ends of any of those pages (and display with those comments). Not
> (currently) on Rails or any such framework.
>
> Any suggestions on simple ways (preferably Ruby-based) to do this? Or where
> would be a good place to start looking?

Seems this would be a good use of an Apache output filter. I don't think
mod_ruby supports writing output filters yet but I think you can do so
in perl or python.

If you really want ruby it sounds like a combination of mod_rewrite and
a ruby script as Nick suggested would be your best route. You could also
use mod_ruby as a handler that will handle all requests and use the
request string to figure out what file to load. This would be similar to
the mod_rewrite/script suggestion except your script is more integrated
with Apache.

Eric

Its Me

1/21/2005 3:19:00 AM

0


"Nicholas Van Weerdenburg" <vanweerd@gmail.com> wrote in message

> Do you want to add anything to the static pages, or do it all
> magically without touching them?

I can add to the static pages, as I generate them statically from Ruby.

From the suggestions so far, one lightweight approach seems to be to have a
comments file per static html file. At the bottom of each static html file I
could include an <iframe> or <object> to show current comments via some
comments_for(x) script, and a form that submits to some add_comment_for(x)
script.

Thoughts?

This will be my very first venture into the web with Ruby so please excuse
my naivete. If I do this on a LAMP web host with Ruby and cgi (not too
worried about performance of the comments right now), would it be anything
like this:

#comments_for.rb
#!/bin/ruby
require 'cgi'
cgi = CGI.new
file = cgi['file_name']
comments = IO.read "#{file_name}.comments"
cgi.out{
cgi.html{
cgi.head {}
cgi.body {
cgi.div { comments }
}
}
}

#add_comment_for.rb
#!/bin/ruby
require 'cgi'
cgi = CGI.new
file = cgi['file_name']
comment = cgi['comment']
File.open(file, "a") {|f| f << commoent }

Thanks!