Live data from Hacker News

Idea: using code rather than templates to generate HTML

github.com

11–20 of 74 posts

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

#11
post #2

I've been sitting on this for a while and finally pushed it out, having never really had the chance to give the idea the work it deserves. Anyway, the idea is simple: templates are a mess. They have goofy language variants, etc. Your editor can't color them. Why not just use code to generate the HTML? Still needs: Context-sensitive escaping, css generation, javascript inclusion.

It's not well advertised, but Genshi is great at python based markup. It's mostly meant for inserting things into streams, but I could easily see it being adapter for full python markup.

http://genshi.edgewall.org/wiki/ApiDocs/genshi.builder

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

#13
post #2

I've been sitting on this for a while and finally pushed it out, having never really had the chance to give the idea the work it deserves. Anyway, the idea is simple: templates are a mess. They have goofy language variants, etc. Your editor can't color them. Why not just use code to generate the HTML? Still needs: Context-sensitive escaping, css generation, javascript inclusion.

I don't want too sound negative, but there are a number of reasons this is a less than feasible idea.

First it's overkill. The reason we have a www at all is because HTML and its variants are dead simple. If the client decides that six key sentences should be yellow and emphasized, I go into my template and add a Yellow text! to my template.

Using your generator, I now have to figure out a whole new way of doing that.

The second point follows: Any first year web monkey can learn to add spans and em's. It takes a bit more effort to understand python. While this might not matter to someone who understands both, it offers much less flexibility to the already available alternative.

Django's template implementation is very, very good. It fits quite well into your average web shop and even fails silently.

I like your desire to scratch your own itch, but I felt I should answer your question.

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

#14
Not to rain on your parade, but this is a pretty ancient idea. I don't have links handy but I remember doing this with PHP (amusingly enough) around the turn of the century, and I'm pretty sure Perl has had something in place for eons. There are also a number of Python options if you google around.

Though, at least looking at the Python implementation it seems very clean and simple compared to others I've seen (though you're importing pprint twice), but then again I'm pretty opposed to the idea in the first place so I haven't really browsed the available options.

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

#15
post #2

I've been sitting on this for a while and finally pushed it out, having never really had the chance to give the idea the work it deserves. Anyway, the idea is simple: templates are a mess. They have goofy language variants, etc. Your editor can't color them. Why not just use code to generate the HTML? Still needs: Context-sensitive escaping, css generation, javascript inclusion.

The reason why not is that eventually you will want to hand the site to a designer and not have to do a half-hour of work on it every coupla weeks for the rest of its life. Making things easier for the designer reduces your total work; forcing the designer to work inside the HTML your tool produces will either limit the nifty things she can do, or require you to come back and touch this code again and again. Even the…

Indeed, the most effective team will be at least minimally cross-disciplined. I think the desire to generate HTML via code is just a case of unfamiliarity. I've been writing code since 1986 and HTML since 1994, and I have to say that there is no advantage to generating via HTML per se (frameworks like Seaside notwithstanding). If you have a decent text editor it can color and edit templating languages just fine.

Developers should write HTML for the same reason that business people should learn to edit HTML--it's the best canonical format for all stakeholders.

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

#17
post #2

I've been sitting on this for a while and finally pushed it out, having never really had the chance to give the idea the work it deserves. Anyway, the idea is simple: templates are a mess. They have goofy language variants, etc. Your editor can't color them. Why not just use code to generate the HTML? Still needs: Context-sensitive escaping, css generation, javascript inclusion.

I don't want too sound negative, but there are a number of reasons this is a less than feasible idea. First it's overkill. The reason we have a www at all is because HTML and its variants are dead simple. If the client decides that six key sentences should be yellow and emphasized, I go into my template and add a Yellow text! to my template. Using your generator, I now have to figure out a whole new way of doing that…

If you ever name a class yellow, you've entirely missed the point of CSS.

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

#18
post #5

Seaside ( http://seaside.st/ ) does this. And the approach taken to an extreme works very well. It supports components with states with example.

Reading over the comments on this thread, it appears that you don't get to generate HTML from code unless you're Avi Bryant.

"I am Avi Bryant, your argument is invalid."

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

#19

Earlier quoted context omitted.

I don't want too sound negative, but there are a number of reasons this is a less than feasible idea. First it's overkill. The reason we have a www at all is because HTML and its variants are dead simple. If the client decides that six key sentences should be yellow and emphasized, I go into my template and add a Yellow text! to my template. Using your generator, I now have to figure out a whole new way of doing that…

If you ever name a class yellow, you've entirely missed the point of CSS.

I think it's safe to assume that the class name was chosen for demonstration purposes only.

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

#20

Earlier quoted context omitted.

I don't want too sound negative, but there are a number of reasons this is a less than feasible idea. First it's overkill. The reason we have a www at all is because HTML and its variants are dead simple. If the client decides that six key sentences should be yellow and emphasized, I go into my template and add a Yellow text! to my template. Using your generator, I now have to figure out a whole new way of doing that…

If you ever name a class yellow, you've entirely missed the point of CSS.

Yes, that's true, but I was trying to illustrate a simple concept.
Post reply on HN