Q

Programmatic generation of HTML

Often, within helpers, I want to output some HTML without resorting to a templating language. Here is my attempt to do so:

=> Q {_div { __'this my divs contents' }}
<= <div>This is my divs contents</div>

Or, with attributes

=> Q {_div(:id => 'test') { __'this my divs contents' }}
<= <div id="test">This is my divs contents</div>

Of course, this is all escaped

=> Q {_div { __'<tag! tag!>' }}
<= <div>&lt;tag! tag!&gt;</div>

Or, you can turn that off

=> Q {_div { __no_escape'<tag! tag!>' }}
<= <div><tag! tag!></div>

Or, you can indent too

=> Q(:indent => 2) {_div { __'some awesome contents' }}
<= <div>
     Some awesome contents
   </div>

And, you can one-line those values

> Q ‘some awesome contents’ }

<= <div>Some awesome contents</div>

Nest as much as you want, and use the QX method for XHTML based output.