Inversion attribute tag.
Attribute tags add an accessor to a template like 'attr_accessor' does for Ruby classes.
<?attr foo ?> <?attr "%0.2f" % foo ?>
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 117 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 97 def evaluate( renderstate ) value = nil attribute = renderstate.attributes[ self.name.to_sym ] self.log.debug " initial attribute: %p" % [ attribute ] # Evaluate the method chain (if there is one) against the attribute if self.methodchain methodchain = "self" + self.methodchain self.log.debug " evaling methodchain: %p on: %p" % [ methodchain, attribute ] value = attribute.instance_eval( methodchain ) else value = attribute end self.log.debug " evaluated value: %p" % [ value ] return value end
Render the tag attributes of the specified renderstate and return them.
# File lib/inversion/template/attrtag.rb, line 81 def render( renderstate ) self.log.debug "Rendering %p with state: %p" % [ self, renderstate ] # Evaluate the tag body and return either false value value = self.evaluate( renderstate ) or return value # Apply the format if there is one if self.format return self.format % value else return value end end
Generated with the Darkfish Rdoc Generator 2.