Fast, fun, east HTML generation from Ruby
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
Gemfile
Gemfile.lock
README.rdoc
Rakefile
q.gemspec

README.rdoc

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 {_div 'some awesome contents' }}
<= <div>Some awesome contents</div>

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