Live data from Hacker News

Idea: using code rather than templates to generate HTML

github.com

71–74 of 74 posts

Re: Idea: using code rather than templates to generate HTML

#71
post #56
post #43

Earlier quoted context omitted.

Your argument assumes workflows never change. If that were true, we would still be using whatever workflows our forebears used for every task. Since that is clearly untrue, workflows must be able to change. However, given that business are formed to turn a profit, the standard workflow will remain unchanged until it is profitable to do otherwise. If a markup-generating DSL was simple enough for designers to pick up q…

> If a markup-generating DSL was simple enough for designers to pick up quickly, it would make good business sense to push them through the transition. Designers being able to do it isn't the problem, justifying why designers should need to is the problem.

Ah, I was making a couple of assumptions:

  any DSL which generates markup must be more concise than the markup itself
Otherwise, there will have been no point in creating the DSL. This assumption is probably fair. An example of this would be Seaside's HTML generation DSL.

  a more concise language will be better in the long run
This assumption is flawed and doesn't take the designers' tools into account. A DSL would need its own tools before it became a valuable long-term investment.

Re: Idea: using code rather than templates to generate HTML

#72

Answer to "why not just use code to generate HTML?": to facilitate communication between the programmer and the designer. If you work with designers who create the HTML for you, it is much easier for them to deal with back-and-forth tweaks and edits using a template. But if you are acting as both the programmer and the designer on a project, then yes it's possible that coding the HTML might be better.

I discussed this issue at http://softwaresimply.blogspot.com/2008/03/to-template-or-no....

It seems like people tend to prefer templates, however I'm not yet convinced. I think there are good arguments for language-generated code, especially with a language that is powerful enough. HSP in Haskell provides some interesting possibilities here (http://www.cs.chalmers.se/~d00nibro/hsp/thesis.pdf). Text.XHtml is another Haskell library that does this (http://www.haskell.org/ghc/dist/current/docs/libraries/xhtml...).

Re: Idea: using code rather than templates to generate HTML

#73
post #61
post #10

I completely agree, may I suggest http://hotwax.infogami.com/HeRF as well? It's maybe not too fancy, but it's very short and simple to deal with. It also ensures correct tag closing without any special effort on your part.

["head", ["title", "HeRF Demo"]], ["body", ["div", {"id": "content"}, ["h1", "HeRF - The HTML Rendering Framework"], ["hr"], This seems almost as painful as writing out html.

It's almost exactly like writing out HTML. The advantages are that you're writing something that your editor and your program can understand. The editor can highlight things appropriately, the program can insert or delete html easily since you've encoded it as a standard data structure.

Also, you may not have noticed that even though it can handle the data in tuples, if you write it in list form (as in your comment), it's trivial for a program to add extra items enclosed in a particular tag. So if I have:

   x = ["ul"]
I can just append elements to x to fill out the list:

   for i in range(10): x.append(["li", "Item %s" % i])
However, I don't think that it's _quite_ as painful as writing HTML... You don't have to worry about closing tags, for instance. That said, I really wish Python could deal with barewords in data structures, because that would really clean it up otherwise.

Re: Idea: using code rather than templates to generate HTML

#74
post #61

Earlier quoted context omitted.

["head", ["title", "HeRF Demo"]], ["body", ["div", {"id": "content"}, ["h1", "HeRF - The HTML Rendering Framework"], ["hr"], This seems almost as painful as writing out html.

Interesting you say that. I'm fleshing out a design that uses a similar syntax - In python: (html, (body, (h1, "header one text") ) ) To me it's certainly not as painful as writing out html. I'm still working on it - hope to have a demo soon but its not a high priority, more something to sketch in the notebook when bored. I have wondered if anyone would be interested in a templating syntax like this and got some resp…

I think this sorta thing is more data-structure-ey than code-ey.
Post reply on HN