[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Write webpages in Ruby without Rails? - Newb Question

rgossen

11/7/2007 12:51:00 AM

I am a programming newb and I just bought the book "Software
Engineering for Internet Applications," and I need a server to go
through the labs. Unfortunately, the extent of my server experience
is using script/server in Rails. To do these labs, I need to write
webpages in Ruby without Rails (or any framework), but I am not sure
exactly how to go about it.

I started to use the Apache 1.3 webserver that comes with os x and
attempted to install eruby. That doesn't seem to be working. I am
thinking there has to be an easier way. Is there a way for me to use
Mongrel or Webrick outside of Rails? I initially installed everything
using the Hivelogic instructions.

7 Answers

Jeremy Woertink

11/7/2007 1:12:00 AM

0

rgossen wrote:
> I am a programming newb and I just bought the book "Software
> Engineering for Internet Applications," and I need a server to go
> through the labs. Unfortunately, the extent of my server experience
> is using script/server in Rails. To do these labs, I need to write
> webpages in Ruby without Rails (or any framework), but I am not sure
> exactly how to go about it.
>
> I started to use the Apache 1.3 webserver that comes with os x and
> attempted to install eruby. That doesn't seem to be working. I am
> thinking there has to be an easier way. Is there a way for me to use
> Mongrel or Webrick outside of Rails? I initially installed everything
> using the Hivelogic instructions.

well, you can write HTML like a string, then have the output be an HTML
file. So,


html_file = File.new("C:\web_pages\index.html", "w+")

html_file.write("<html>\n<head>\n<title>OMG THIS IS GOING TO TAKE A LONG
TIME</title>\n</head>\n</html>")

html_file.close


Hopefully someone has a better idea :)

Good luck

~Jeremy
--
Posted via http://www.ruby-....

Colin Summers

11/7/2007 1:19:00 AM

0

This is really a question for the rails-talk list, but since I am
right now in rails...

I would create a rails application and a default controller and index
action. Then you can just write Ruby inside a <% %> pair in the
index.rhtml file.

I am sure you'll get a dozen responses about how to set it up simpler,
but that's the way I know you can get it to work from where you are.

--Colin

Todd Benson

11/7/2007 2:54:00 AM

0

On 11/6/07, rgossen <rgossen@gmail.com> wrote:
> I am a programming newb and I just bought the book "Software
> Engineering for Internet Applications," and I need a server to go
> through the labs. Unfortunately, the extent of my server experience
> is using script/server in Rails. To do these labs, I need to write
> webpages in Ruby without Rails (or any framework), but I am not sure
> exactly how to go about it.
>
> I started to use the Apache 1.3 webserver that comes with os x and
> attempted to install eruby. That doesn't seem to be working. I am
> thinking there has to be an easier way. Is there a way for me to use
> Mongrel or Webrick outside of Rails? I initially installed everything
> using the Hivelogic instructions.

I haven't played with Ruby and web outside of frameworks (Rails,
Camping, etc.), but you can use Apache with mod_ruby I think. Your
files will probably have to take on the eruby syntax of <% %>
encapsulating code tags, which would be similar to other interactive
web code (ala CodeFusion and others).

As far as I can tell, Mongrel knows how to feed a web server( like
Apache), but is not necessarily a complete web server itself.
Somebody correct me if I'm wrong, because I can't seem to find any
straight example of somebody just using Mongrel with Ruby by
themselves to serve pages!

thx,
Todd

dusty

11/7/2007 2:59:00 AM

0

On Nov 6, 7:51 pm, rgossen <rgos...@gmail.com> wrote:
> I am a programming newb and I just bought the book "Software
> Engineering for Internet Applications," and I need a server to go
> through the labs. Unfortunately, the extent of my server experience
> is using script/server in Rails. To do these labs, I need to write
> webpages in Ruby without Rails (or any framework), but I am not sure
> exactly how to go about it.
>
> I started to use the Apache 1.3 webserver that comes with os x and
> attempted to install eruby. That doesn't seem to be working. I am
> thinking there has to be an easier way. Is there a way for me to use
> Mongrel or Webrick outside of Rails? I initially installed everything
> using the Hivelogic instructions.

Check out webrick. Here is a simple script that will do a directory
listing on wherever you run it. Just open up your browser to port
2000.

Now, to get it to actually output html content-types and all, will
require some more work. But, perhaps this will get you started.

#!/bin/env ruby
require 'webrick'
include WEBrick

s = HTTPServer.new(
:Port => 2000,
:DocumentRoot => Dir::pwd
)

trap("INT"){ s.shutdown }
s.start

Nathan Grant

11/7/2007 3:15:00 AM

0

I would recommend the "serve" gem

http://wiseheartdesign.com/2007/9/25/introduc...

It makes it simple to code and serve webpages with ruby.

But there are lots of options for generating HTML code using ruby,
check rubyforge.org for gems like "markaby" or "xx".

You can serve page with Mongrel like this:

require 'rubygems'
gem 'mongrel'
require 'mongrel'

HOST = '0.0.0.0'
PORT = 999

config = Mongrel::Configurator.new :host => HOST, :port => PORT do
listener do
uri "/", :handler => Mongrel::DirHandler.new(Dir.pwd)
end

trap("INT") { stop }
run
end

puts "Mongrel running on #{HOST}:#{PORT} with docroot #{Dir.pwd}"
config.join

rgossen

11/7/2007 4:47:00 AM

0

On Nov 6, 8:14 pm, Nathan Grant <grant.nat...@gmail.com> wrote:
> I would recommend the "serve" gem
>
> http://wiseheartdesign.com/2007/9/25/introduc...
>
> It makes it simple to code and serve webpages with ruby.

Wow, this looks perfect. I was not familiar with haml, but after
looking at the tutorial, it looks like a great alternative to rhtml
for templating. Thanks so much for the tip.

Jeremy Hinegardner

11/7/2007 8:05:00 AM

0

On Wed, Nov 07, 2007 at 11:53:37AM +0900, Todd Benson wrote:
>
> As far as I can tell, Mongrel knows how to feed a web server( like
> Apache), but is not necessarily a complete web server itself.
> Somebody correct me if I'm wrong, because I can't seem to find any
> straight example of somebody just using Mongrel with Ruby by
> themselves to serve pages!

You might want to give heel a try, that's pretty much what it is, mongrel with
some mime-type sugar and nice directory listings.

% sudo gem install heel
% heel
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** heel running at http://127.... with document root /home/jeremy/proj
** Use Ctrl-C to stop.
** Launching your browser...
127.0.0.1 - - [07/Nov/2007:00:58:17 MST] "GET / HTTP/1.1" 200 46615
127.0.0.1 - - [07/Nov/2007:00:58:17 MST] "GET /icons/folder.png HTTP/1.1" 200 537
127.0.0.1 - - [07/Nov/2007:00:58:17 MST] "GET /icons/application.png HTTP/1.1" 200 464

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org