I was thinking today about how much I hate writing scripts to generate
HTML and I sat down and wrote some code. I’m thinking about making a
simple toolkit to generate HTML in an abstract way. Here’s my sample
code:
tests a simple HTML generation toolkit - this is how a working
script ought to work
data = [[1, 2, 3], [4, 5, 6]]
puts RHTk.new do
title "A Test of RHTk - The Ruby HTML ToolKit"
include_css "style/rhtk.css"
body do
header1 “Here’s a sample header”, :class => 'modern’
table do
data.each do |i|
row do
data[i].each do |d|
column d
end
end
end
end
out "that’s all for now"
end
end
The RHTk constructor assembles a string of HTML based on all the code
executed within its block. The output would be neatly tabified, giving
you something like this:
Here's a sample header.
1
2
3
4
5
6
that's all for now
Is this worth pursuing? Is there something already in existence that
does the same thing? I’d like to hear what everyone’s thoughts about
this are.
Is this worth pursuing? Is there something already in existence that
does the same thing? I’d like to hear what everyone’s thoughts about
this are.
Class CGI does already HTML generation although IMHO this should be put
into a separate class since HTML generation is not limited to web
application. Dunno though whether someone has factored that code out
already. If not, you could join forces.
this is much like CGI.rb.
Anyway I’d use one of (red|blue)cloth or RDoc to write html in a more
simple way, then tweak the interface a little with a css.
I was thinking today about how much I hate writing scripts to generate
HTML and I sat down and wrote some code. I’m thinking about making a
simple toolkit to generate HTML in an abstract way. Here’s my sample
code:
tests a simple HTML generation toolkit - this is how a working
– stolen off the net –
a dozen dogs bark
outside m[y] jail window
they love to irritate
let us in gruff bang
lo nice quie[t] reappears
once i have my ax
– a Scrabble poem, using all the tiles, http://www.cheapass.com/
I was thinking today about how much I hate writing scripts to generate
HTML and I sat down and wrote some code. I’m thinking about making a
simple toolkit to generate HTML in an abstract way. Here’s my sample
code:
puts RHTk.new do
title "A Test of RHTk - The Ruby HTML ToolKit"
include_css "style/rhtk.css"
body do
I know these methods of wrapping HTML tags into classes/objects is “en
vogue” but really you ought to work in a MVC-based system, separating the
code from data and presentation. The code (controller) should instanciate
the data (model) through templates (view).
That way you don’t have to change the code to change presentation or your
data. Even if you have to change the code, it will be a code change, not
a presentation one.
I know these methods of wrapping HTML tags into classes/objects is “en
vogue” but really you ought to work in a MVC-based system, separating the
code from data and presentation. The code (controller) should instanciate
the data (model) through templates (view).
I find that these separations add invariably a lot of complexity to the
system and often are not really used; redesigns are often on all three
sides (m v and c).
So I reverted to making clean html and doing the rest in css. Of course
I can see a lot of projects where that is not an option; Amrita is
definitly a good (=lean) solution to the MVC pattern.
Cocoon shows how complicated one can get…
kaspar - code philosopher
– stolen off the net –
I’m inclined to think that caffeine, sugar, fat and alcohol are the four
basic food groups. This means that an Irish coffee is the most
nourishing drink ever made, because it contains all four.
– Dave Brown
I find that these separations add invariably a lot of complexity to the
system and often are not really used; redesigns are often on all three
sides (m v and c).
I’d the minimum is to separate HTML from the code and going through
templates. CSS is of course to be used fro the presentation layer.
So I reverted to making clean html and doing the rest in css. Of course
I can see a lot of projects where that is not an option; Amrita is
definitly a good (=lean) solution to the MVC pattern.
Cocoon shows how complicated one can get…
–
Ollivier ROBERT -=- FreeBSD: The Power to Serve! -=- roberto@keltia.freenix.fr
Darwin snuadh.freenix.org Kernel Version 7.3.0: Fri Mar 5 14:22:55 PST 2004
I’d the minimum is to separate HTML from the code and going through
templates. CSS is of course to be used fro the presentation layer.
Using the term minimum like that, you have to define what for. If I
write a small web application that needs to display some data, then the
Borges way is good enough. Adding an MVC pattern to that seems overhead
and adding to the complexity of thought more than anything else.
I have helped develop a major CMS system and been trough with seperation
~ of code from presentation. Code and presentation can be thought of
apart, but in real world they have many inherent dependencies.
I just advise people to do things simple while that works, and use the
big cannons on big animals. Did the point of cocoon being the thing to
look at at the other end of the complexity scale get across ?
kaspar - code philosopher
– stolen off the net –
Excess on occasion is exhilarating. It prevents moderation from
acquiring the deadening effect of a habit.
~ – W. Somerset Maugham
I have helped develop a major CMS system and been trough with seperation
~ of code from presentation. Code and presentation can be thought of
apart, but in real world they have many inherent dependencies.
Would that be typo3?
What are your thoughts on using Ruby and/or a Borges-like framework in some
future incarnation of a CMS?
I have a Borges app that builds a static photogallery 2/3rds done.
My camera uses the DCIM “format”, so images are dumped by groups of 100
into directories named 100, 101, 102, … Rather than organize these
images by hand, (I’d be highly likely to delete them) I instead leave
the originals as they are, and instead create symlinks to them from the
appropriate categories.
Creating an ‘live’ photo gallery with Borges may be overkill, since most
users will be just browsing, not reading.
You could take the Component model of Borges, lift it off of the
continuation-based session management, and use a more conventional
session managment model instead.
I have helped develop a major CMS system and been trough with seperation
~ of code from presentation. Code and presentation can be thought of
apart, but in real world they have many inherent dependencies.
What are your thoughts on using Ruby and/or a Borges-like framework in some
future incarnation of a CMS?
Would that be typo3?
No, its not. The thing I am talking about is called ‘obtree’, is not
open source at all and was programmed in c++.
What is interesting is that at some point or another, all these systems
contain a scripting language, in our case ECMA-Script.
What are your thoughts on using Ruby and/or a Borges-like framework in
some
future incarnation of a CMS?
I think that is a good idea, as long as you manage a good synthesis
between Application-like design and the Page metaphor that often
underlies CMS systems.
Do you know about Cocoon and Cocoon Flow ?
I have some experience on the field, but I cannot say that it makes me a
positive person to converse with about these issues. I have more often
than not seen CMS systems detourned as application servers where they
should not have been. I think it is unhealthy to stay with one metaphor,
but one should really know about both.
I guess what I am trying to say is that keeping things simple plays an
important part when it comes to … creating html pages, because that is
what the fuzz is often about. Few people have content-syndication or
multiple output formats implemented. And those who have… often did it
from scratch.
What kind of system are you thinking about ?
~ kaspar - code philosopher
– stolen off the net –
Please help me. When you download files on hacking and the file
extension is “c” how do you use it?
– antons @ iafrica.com, in alt.hackers.malicious