class Inversion::Template::AttrTag
Inversion
attribute tag.
Attribute tags add an accessor to a template like ‘attr_accessor’ does for Ruby classes.
Syntax¶ ↑
<?attr foo ?> <?attr "%0.2f" % foo ?>
Attributes
format[RW]
the format string used to format the attribute in the template (if one was declared)
methodchain[RW]
the chain of methods that should be called (if any).
name[RW]
the name of the attribute
Public Class Methods
new( body, linenum=nil, colnum=nil )
click to toggle source
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.
Calls superclass method
Inversion::Template::Tag::new
# File lib/inversion/template/attrtag.rb, line 56 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.to_sym end
Public Instance Methods
as_comment_body()
click to toggle source
Render the tag as the body of a comment, suitable for template debugging.
# File lib/inversion/template/attrtag.rb, line 104 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( renderstate )
click to toggle source
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 ) code = [ self.name.to_s, self.methodchain ].join( '' ) return renderstate.eval( code ) end
render( renderstate )
click to toggle source
Render the tag attributes of the specified ‘renderstate` and return them.
# File lib/inversion/template/attrtag.rb, line 84 def render( renderstate ) value = self.evaluate( renderstate ) # :FIXME: or return value # nil or false? # Apply the format if there is one if self.format && value return self.format % value else return value end end