Inversion attribute tag.
Attribute tags add an accessor to a template like ‘attr_accessor’ does for Ruby classes.
<?attr foo ?> <?attr "%0.2f" % foo ?>
the format string used to format the attribute in the template (if one was declared)
the chain of methods that should be called (if any).
the name of the attribute
Create a new AttrTag with the given
name, which should be a valid Ruby identifier. The
linenum and colnum should be the line and column
of the tag in the template source, if available.
# File lib/inversion/template/attrtag.rb, line 53
def initialize( body, linenum=nil, colnum=nil )
@name = nil
@format = nil
@methodchain = nil
super
# Add an identifier for the tag name
self.identifiers << self.name.untaint.to_sym
end
Render the tag as the body of a comment, suitable for template debugging.
# File lib/inversion/template/attrtag.rb, line 101
def as_comment_body
comment = "%s: { template.%s" % [ self.tagname, self.name ]
comment << self.methodchain if self.methodchain
comment << " }"
comment << " with format: %p" % [ self.format ] if self.format
return comment
end
Evaluate the body of the tag in the context of renderstate and
return the results.
# File lib/inversion/template/attrtag.rb, line 94
def evaluate( renderstate )
code = [ self.name.to_s, self.methodchain ].join( '' )
return renderstate.eval( code )
end
Render the tag attributes of the specified renderstate and
return them.
# File lib/inversion/template/attrtag.rb, line 81
def render( renderstate )
value = self.evaluate( renderstate ) # :FIXME: or return value # nil or false?
# Apply the format if there is one
if self.format
return self.format % value
else
return value
end
end