Earlier quoted context omitted.
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.
Idea: using code rather than templates to generate HTML
51–60 of 74 posts
Re: Idea: using code rather than templates to generate HTML
#52Re: Idea: using code rather than templates to generate HTML
#53Earlier quoted context omitted.
What if you want to repeat a similar chunk of HTML in a loop? What if you want variables? Functions? ? The world has spent too much time trying to hammer programming language constructs into XML-based languages and templating systems. There simply has to be a better, way, but no one has successfully come up with one that satisfies everybody yet.
Certainly there could be a better way, but HTML and CSS are what we have (and frankly they work pretty well considering that the web comprises mostly documents). Emitting HTML from a programming language can be useful, but it doesn't solve the fundamental inelegance of nested markup. Solutions like this are just indirecting the problem, adding another layer of complexity without a meaningful abstraction.
$table = new Sprocket( 'table' );
$tr = $table->tr();
$tr->td( "OMG I'm in a sprocket" );
I've done similar things using XElement in C#, though using PHP's magic methods makes for very short readable code.
I agree that templates are handy for separation of concerns though.
Re: Idea: using code rather than templates to generate HTML
#54http://search.cpan.org/~jrockway/Template-Refine-0.02/
I like the second one better, for some reason.
Re: Idea: using code rather than templates to generate HTML
#55Re: Idea: using code rather than templates to generate HTML
#56Earlier quoted context omitted.
you've hit on why html (or css or javascript) generators will never catch on. they do not fit within the traditional workflow. you cannot take a delivered html document and convert it into whatever html-generator you use. the designer will have no clue how to use your (hand) converted file in dreamweaver to make small changes. in the end, it just makes life harder for everyone and costs more money.
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…
Designers being able to do it isn't the problem, justifying why designers should need to is the problem.
Re: Idea: using code rather than templates to generate HTML
#57I've been thinking "templating system" for the last week none-stop. After seeing that project I just could not stop laughing. Yea why not code...
O well back to templating :)
Re: Idea: using code rather than templates to generate HTML
#58Re: Idea: using code rather than templates to generate HTML
#591) I want to do projects alone, without a designer in the loop. Why should I use a template when it's wrong for me? This lets me go faster. Therefore the workflow argument is useful, since this is hacker news and not designer news.
2) It's not a new idea. I have seen a bunch of similar libraries, although they tend to use datastructures, more than code directly. I think the small novel bit is that the object mutators return the underlying objects for further mutation (read the code; it's scary)
3) It's not a DSL. It is the language itself. The template programming languages are awful; as soon as you want to do something that they don't define, you are in hell. And the ones with embedded code are a nightmare to look at and format (delicious was in HTML::Mason.)
Markaby is pretty close to what I wanted to do. The other ones I saw for python were not so much.
4) I haven't seen anywhere the notion of context-aware encoding. Unfortunately, I managed to nuke that bit of source while cleaning up and renaming things before sending it to github.
5) I apologize for my code. I am still new to python.
Re: Idea: using code rather than templates to generate HTML
#60One thing: use the "with" keyword so that you don't have to do td.close(), etc every time. It's cleaner and reduces bugs. Also, I agree. I'm using templates that are just python functions in my new Python web framework, Webify ( http://github.com/jperla/webify/tree/master ). I honestly don't think I've made it clean enough though (there are a lot of yield's there). Nevertheless, I think I'm on the right track. The on…