[Uw-ruby] Uw-ruby Digest, Vol 2, Issue 18
Jim Clark
diegoslice at gmail.com
Fri Nov 23 10:10:14 PST 2007
Steve
> Jim Clark made a good suggestion which was to store all of the <style>
> information in a separate file and then read it in using the Ruby CGI
> tools. I'll also have to look at what Ryan was suggesting. I was also
> interested in how to perform graphing options from CGI and it looks like
> there are some great Class libraries out there for that sort of thing also.
>
By having an external style sheet, you never need to read it in at all.
Your dynamic output from Ruby just references the CSS styles when
creating HTML tags that the browser will go fetch when it is time to
render the page. However, with that said, now that I see what you are
doing, I would look more at a templating system. For example, you could
start out with an exported Word or Excel file that is in HTML format.
Now you rename it to .rhtml and start embedding ruby code in the page.
For instance, for the Strongbox values you would first create the
Strongbox object near the top of the page and populate it's values from
a database or text file. Then further down in the page you would use
additional embedded Ruby code to insert the correct values. For
instance, the HTML for the Strongbox heading might look like:
<TD>Heading</TD><TD><%= Strongbox.Heading.to_s %></TD>
If the external CSS file defines how the the TD element should appear,
your HTML stays very clean.
The ruby CGI class and CGI::HtmlExtension classes are best used when
creating a page from scratch. This isn't to say you might not find them
useful but most of their functionality won't be needed when working with
a template.
The other thing that needs to be done is to ensure that your web server
is configured to use Ruby to parse the .rhtml document. Just renaming
something from .html to .rhtml isn't enough. If using Apache on Windows,
take a look at http://www.hiveminds.co.uk/node/3094. Otherwise, if you
are using IIS, http://www.hiveminds.co.uk/node/3100.
> The key idea of my script is to build an extended CGI Class that can
> dump some dynamic output and graph some sensor data as a starting point
> for a much richer application.
>
> -Steve
>
HTH,
Jim
More information about the Uw-ruby
mailing list