Erector API Cheatsheet
code | output |
---|---|
element('foo') |
<foo></foo> |
empty_element('foo') |
<foo /> |
html |
<html></html> …and likewise for all non-deprecated elements from the HTML 4.0.1 spec |
b 'foo' |
<b>foo</b> |
div { b 'foo' } |
<div><b>foo</b></div> |
text 'foo' |
foo |
text '&<>' |
&<> …all normal text is HTML escaped, which is what you generally want, especially if the text came from the user or a database |
text raw('&<>') |
&<> …raw text escapes being escaped |
rawtext('&<>') |
&<> …alias for text(raw()) |
text!('&<>') |
&<> …another alias for text(raw()) |
div { text 'foo' } |
<div>foo</div> |
div 'foo' |
<div>foo</div> |
foo = 'bar' |
<div>bar</div> |
a(:href => 'foo.div') |
<a href="foo.div"></a> |
a(:href => 'q?a&b') |
<a href="q?a&b"></a> …attributes are escaped like text is |
a(:href => raw('&')) |
<a href="&"></a> …raw strings are never escaped, even in attributes |
a 'foo', :href => "bar" |
<a href="bar">foo</a> |
text nbsp('Save Doc') |
Save Doc …turns spaces into non-breaking spaces |
text nbsp |
  …a single non-breaking space |
text character(160) |
  …output a character given its unicode code point |
text character(:right-arrow) |
→ …output a character given its unicode name |
instruct |
<?xml version="1.0" encoding="UTF-8"?> |
comment 'foo' |
<!--foo--> |
url 'http://example.com' |
<a href="http://example.com">http://example.com</a> |
capture { div } |
<div></div> …returns the block as a string, doesn't add it to the current output stream |
div :class => ['a', 'b'] |
<div class="a b"></div> |
javascript( |
<script type="text/javascript"> |
jquery '$("p").wrap("<div></div>");' |
<script type="text/javascript"> |
join([widget1, widget2], |
…See examples/join.rb for more explanation |
Lots more documentation is at the RDoc API pages especially for Erector::Widget so don't go saying we never wrote you nothin'.