Inversion::Template::
CodeTag class
Superclass | Inversion::Template::Tag |
Included Modules |
The base class for Inversion
tags that parse the body section of the tag using a Ruby parser.
It provides a ‘tag_pattern` declarative method that is used to specify a pattern of tokens to match, and a block for handling tag instances that match the pattern.
class Inversion::Template::MyTag < Inversion::Template::CodeTag # Match a tag that looks like: <?my "string of stuff" ?> tag_pattern 'tstring_beg $(tstring_content) tstring_end' do |tag, match| tag.string = match.string( 1 ) end end
The tokens in the ‘tag_pattern` are Ruby token names used by the parser. If you’re creating your own tag, you can dump the tokens for a particular snippet using the ‘inversion’ command-line tool that comes with the gem:
$ inversion tagtokens 'attr.dump! {|thing| thing.length }' ident<"attr"> period<"."> ident<"dump!"> sp<" "> lbrace<"{"> op<"|"> \ ident<"thing"> op<"|"> sp<" "> ident<"thing"> period<"."> \ ident<"length"> sp<" "> rbrace<"}">
:todo: Finish the tag_pattern
docs: placeholders, regex limitations, etc.
Attributes
- body R
the body of the tag
- identifiers R
the identifiers in the code contained in the tag
Public Class Methods
Declarative that forces a tag to inherit existing patterns from its parent, rather than replacing them. Afterwards, you can use ‘tag_pattern` regularly, appending to the list.
Declare a ‘token_pattern` for tag bodies along with a `callback` that will be called when a tag matching the pattern is instantiated. The `callback` will be called with the tag instance, and the MatchData object that resulted from matching the input, and should set up the yielded `tag` object appropriately.
Return the tag patterns for this class, or those of its superclass if it doesn’t override them.
Protected Instance Methods
Initialize a new tag that expects Ruby code in its ‘body`. Calls the tag’s parse_pi_body method with the specified ‘body`.
Match the given ‘body` against one of the tag’s tag patterns, calling the block associated with the first one that matches and returning the matching pattern.