FragmentTag

class
Superclass
Inversion::Template::Tag
Included Modules
Inversion::Template::ContainerTag

Inversion 'fragment' tag.

This tag provides a way to generate a fragment of content once in a template as an attribute, and then reuse it later either in the same template or even outside of it.

Syntax

<?fragment subject ?>Receipt for Order #<?call order.number ?><?end subject ?>

Attributes

key[R]

The fragment key; corresponds to the name of the attribute that will be set by the rendered contents of the fragment.

Public Class Methods

anchor
new( body, line=nil, column=nil )

Create a new FragmentTag with the given body.

# File lib/inversion/template/fragmenttag.rb, line 23
def initialize( body, line=nil, column=nil )
        super

        key = self.body[ /^([a-z]\w+)$/ ] or
                raise Inversion::ParseError,
                        "malformed key: expected simple identifier, got %p" % [ self.body ]
        @key = key.to_sym
end

Public Instance Methods

anchor
render( renderstate )

Render the fragment and store it as an attribute.

# File lib/inversion/template/fragmenttag.rb, line 43
def render( renderstate )
        self.log.debug "Publishing %d nodes as %s" % [ self.subnodes.length, self.key ]
        rendered_nodes = []
        renderstate.with_destination( rendered_nodes ) do
                sn = self.render_subnodes( renderstate )
                # self.log.debug "  subnodes are: %p" % [ sn ]
                sn
        end

        # self.log.debug "  rendered nodes are: %p" % [ rendered_nodes ]
        renderstate.add_fragment( self.key, rendered_nodes )

        return nil
end