Son of WebPage #
Okay, once again, the idea here is to make HTML easily expressible for beginnies during a tutorial. If we can show that Ruby can be used to assemble a blog template pretty nicely, then someone might go, “Okay, I’m doing this!”
Here’s the latest webpage.rb. And here’s RedHanded sort-of-translated to webpage-test.rb.
Peek:
div.entry do h2.entryTitle 'Son of WebPage' div.entrySection %{by "why(Visit why's homepage)":http://whytheluckystiff.net/} div.entryContent '_Okay_, once again, the idea here is ...' end
Main changes:
- Give elements a class (or classes) by attaching a method:
div.button.red
translates to<div class="button red">
. - Give elements an ID by adding a bang to that method:
div.page!
translates to<div id="page">
. - Got rid of
link_to
, using normala
. - Divs can now take a string containing Textile.
I wasn’t gonna do the bang but it looks cool. The method attachment trick is done in CssProxy
.
Alisdair
It’s very cool, but I’m not sure I understand why you’d want to do it. You still have to know HTML , but then you also have to learn the special Ruby syntax for it as well.
ERB still seems much clearer to me. Perhaps that’s because I’m used to PHP and other templating languages, though.
MenTaLguY
Ennh. Well, maybe there is some value-add waiting in the wings here once we get HTML shoehorned into the Ruby syntax neatly. Don’t really know until we try.
Oh! Here is one: add the ability to define “custom” elements, which expand into combinations of standard HTML elements. Like, HTML macros sort of.
MenTaLguY
Well, also, then we give the nooobies some convenient standard “meta-elements” to start with. Obviously they will not be building their own right away.
Nyarly
I hate to be the downpour on the procession, but what advantage does this really have over erb? There’s something to be said for SOC , and erb kind of runs roughshod over that. Reversing the relationship, and putting the HTML in the Ruby rather than vice versa doesn’t improve matters, does it?
why
I don’t really know. Just fooling around with it, I’m really diggin it over the tag soup. Plus we can make it ensure XHTML compliance. I mean imagine letting the interpreter detect that for you.
I understand the reluctance, since it’s kind of dumbing down HTML and that’s never worked (Dreamweaver, GoLive!, etc.) So I’m prepared to go bust on this.
However, in playing with this, it feels competitive to erb and it’s much, much preferrable to Smarty, HTML ::Mason, stuff where you have two syntaxes going on which aren’t even the language you’re coding in.
Jan
meh, it’s just cool
Chris
Hey, just out of curiosity, have you seen Watir? http://wtr.rubyforge.org. It’s a way to poke at stuff on web pages, and your thingie here is eerily evocative of Watir.
Amr
Superb! somehow, this appeals to the Nuby in me..
<|:{
Keep up the good work. Sometimes the payoff isn’t immediately obvious on stuff like this, but you never know what experimentation might lead to.
I like it.
Durante
I did something similar a few months ago (just spent 3 hours or so on it). It was fun, if not really useful.
Here’s the page.
Your method attachment idea is nice.
average_joe
Can we have entry_section instead of the camelCased one?
thx
dans
average_joe: I guess it is up to you, just replace entrySection with your prefered class name.
But I think it’s a confusing use of methods – especially if this is aimed att newbies (like me).
gmosx
Interesting, I especially like the use of textile ;-)
jim
I’ve run across this one: webgen.rubyforge.org
why
Durante: see, yes!
average_joe: Yes, either.
jim: Wild. That Qt app that goes with it.
Libraries. They’re buried all over the hill.
hgs
I’ve been reading “The Art of Unix Programming” recently. This almost runs counter to Generation: Pushing the Specification Level Upwards because something declarative is being turned into code. I see that we get Ruby to check the structure “for free”, but we’d get that from some kinds of data structure, possibly: Is it possible to declare YAML types that can’t contain certain types (to respect the nesting restrictions on HTML , but still have readability) for example?
There are interesting things going on at this “data generates code”/”code generates data” boundary, similar to the declarative/imperative boundary in languages….
MenTaLguY
hgs: You’re thinking YAML schemas, basically?
netghost
I have once or twice embarked on making an SVG (or otherwise) charting library, I think this approach could be really useful for creating the markup.
hgs
MenTaLguY: Yes, because it is intended to be less verbose that XML and thus SGML /HTML documents. But not necessarily YAML ; any concise declarative language may do.
But what interests me is what the issues are when a procedural versus declarative choice isn’t obvious. I think available tools to support getting information out must be one factor. Since I’ve always found parsers difficult to get correct I have a leaning towards using code rather than data. This is probably because I’ve not found ways to make my data-to-be-parsed sufficiently simple. But maybe even with all the drilling of pilot holes and using countersink bits, it is still better to put things together with screws than nails.
okk
How about amrita.sourceforge.jp!?
Comments are closed for this entry.