Created
March 18, 2013 07:46
-
-
Save mikeknoop/5185647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# accessor: returns the article "a" or "an" depending on the context string. Eg. "Computer" will return "a" | |
# and "Elephant" will return "an". Can pass a hash option `capitalize` which will capitalize the article. | |
# usage: {{#article}}string{{/article}} outputs "a string" | |
Handlebars.registerHelper "article", (options) -> | |
# options: pass `capitalize` true to get a capital article | |
string = options.fn(@) | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
vowel = false | |
letter = string.toLowerCase()[0] | |
vowel = true for v in vowels when letter == v | |
article = 'an ' if vowel | |
article = 'a ' if not vowel | |
article = _.str.capitalize(article) if options.hash?.capitalize | |
return article + string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment