Skip to content

Commit

Permalink
Merge pull request wycats#12 from scottgonzalez/expressions
Browse files Browse the repository at this point in the history
Cleaned up expressions page.
  • Loading branch information
wycats committed Jun 30, 2011
2 parents 82cf4af + 5d003fa commit 9afa4ae
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/pages/expressions.haml
Expand Up @@ -53,49 +53,49 @@
in "Basic Usage".
:javascript
Handlebars.registerHelper('link', function(object) {
return "<a href='" + object.url + "'>" + object.text + "</a>"
return "<a href='" + object.url + "'>" + object.text + "</a>";
});

.bullet
.description
You can also pass a simple String as a parameter to Handlebars
helpers.
:html
{{link "See more..." story.url}}
{{{link "See more..." story.url}}}
.notes
In this case, Handlebars will pass the link helper two parameters:
the String <code>"See more..."</code> and the result of evaluating
<code>story</code> in the current context.
<code>story.url</code> in the current context.
:javascript
Handlebars.registerHelper('link', function(text, url) {
return "<a href='" + url + "'>" + text + "</a>"
return "<a href='" + url + "'>" + text + "</a>";
});
.notes
You could use the exact same helper with dynamic text based on
the value of <code>story.text</code>:
:html
{{link story.text story}}
{{{link story.text story.url}}}

.bullet
.description
Handlebars helpers can also receive an optional sequence of key-value
pairs as their final parameter (referred to as hash arguments in
the documentation):
:html
{{link "See more..." href=story.url class="story"}}
{{{link "See more..." href=story.url class="story"}}}
.notes
The keys in hash arguments must each be simple identifiers, and the
arguments are Handlebars expressions. This means that values can
values are Handlebars expressions. This means that values can
be simple identifiers, paths, or Strings.
:javascript
Handlebars.registerHelper('link', function(text, options) {
var attrs = []
var attrs = [];

for(var prop in options.hash) {
attrs.push(prop + '="' + options.hash[prop] + '"');
}

return "<a " + attrs.join(" ") + ">" + text + "</a>"
return "<a " + attrs.join(" ") + ">" + text + "</a>";
});
.notes
Handlebars provides additional metadata, such as Hash arguments,
Expand Down

0 comments on commit 9afa4ae

Please sign in to comment.