Class | Mustache::Parser |
In: |
lib/mustache/parser.rb
|
Parent: | Object |
The Parser is responsible for taking a string template and converting it into an array of tokens and, really, expressions. It raises SyntaxError if there is anything it doesn‘t understand and knows which sigil corresponds to which tag type.
For example, given this template:
Hi {{thing}}!
Run through the Parser we‘ll get these tokens:
[:multi, [:static, "Hi "], [:mustache, :etag, "thing"], [:static, "!\n"]]
You can see the array of tokens for any template with the mustache(1) command line tool:
$ mustache --tokens test.mustache [:multi, [:static, "Hi "], [:mustache, :etag, "thing"], [:static, "!\n"]]
SKIP_WHITESPACE | = | [ '#', '^', '/' ] | After these types of tags, all whitespace will be skipped. | |
ALLOWED_CONTENT | = | /(\w|[?!\/-])*/ | The content allowed in a tag name. | |
ANY_CONTENT | = | [ '!', '=' ] | These types of tags allow any content, the rest only allow ALLOWED_CONTENT. |
ctag | [W] | |
otag | [W] | |
result | [R] | |
scanner | [R] |
Raises a SyntaxError. The message should be the name of the error - other details such as line number and position are handled for you.