New HTML Toolkit Idea

B

Bill Atkins

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.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:

<html>
<head>
<title>
<link rel="stylesheet" href="style/rhtk.css">
</head>
<body>
<h1 class="modern">Here's a sample header.</h1>
<table>
<!-- main table begin -->
<tr>
<td>
1
</td>
<td>
2
</td>
<td>
3
</td>
</tr>
<tr>
<td>
4
</td>
<td>
5
</td>
<td>
6
</td>
</tr>
<!-- main table end -->
that's all for now
</body>
</html>

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.

Bill
 
R

Robert Klemme

Bill Atkins said:
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.

Kind regards

robert
 
G

gabriele renzi

il 14 Apr 2004 08:04:29 -0700, (e-mail address removed) (Bill Atkins) ha
scritto::
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


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.
 
K

Kaspar Schiess

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill Atkins wrote:

| 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.

HTML generation in Borges (http://borges.rubyforge.org) works much that
way.

kaspar - code philosopher

- -- 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/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAfXrDFifl4CA0ImQRAkOVAJ93fohmT9F/RNLzxkNsMIGD0HUYxQCfVDGd
DP3L0ooTg4gu0YRcmGop9hs=
=3kor
-----END PGP SIGNATURE-----
 
O

Ollivier Robert

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.

Amrita is the way IMNSHO.
 
K

Kaspar Schiess

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

| 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAf7zTFifl4CA0ImQRAoThAKCvokIdTOSTAzP1a+/ZRVU5bdAd/wCfQuX0
9PmHYiJ8OCGa4xfNsNXc5WI=
=22WG
-----END PGP SIGNATURE-----
 
O

Ollivier Robert

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.
 
K

Kaspar Schiess

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

| 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


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAf9cSFifl4CA0ImQRAuJfAJ4kx/XinOYb/m+HDe+YJ16zQTK/aACeJ1FP
nVRLlcmlo7LJSkWKuNrSnOw=
=cehg
-----END PGP SIGNATURE-----
 
K

Kaspar Schiess

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello it's me,

| 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAgU5nFifl4CA0ImQRAnD3AJ4yRlTVYbpJvjHGkzf2gHttWtmapACfZzqo
o4tZmK28bk8iksORd76M/L8=
=jgU7
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top