Inversion::Template::

PublishTag class

Inversion publish tag.

The publish tag exports one or more subnodes to enclosing templates.

Syntax

<!-- Outer template -->
<html>
  <head>
    <?subscribe headers ?>
  </head>
  <body><?attr body ?></body>
</html>

<!-- In the body template, add a stylesheet link to the outer
     template's <head> -->
<?publish headers ?>
   <link rel="stylesheet" ... />
<?end ?>
<div>(page content)</div>

Attributes

key R

The name of the key the nodes will be published under

Public Class Methods

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

Create a new PublishTag with the given ‘body`.

# File lib/inversion/template/publishtag.rb, line 33
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

as_comment_body()

Render the tag as the body of a comment, suitable for template debugging.

# File lib/inversion/template/publishtag.rb, line 70
def as_comment_body
        return "Published %d nodes as %s" % [ self.subnodes.length, self.key ]
end
render( renderstate )

Render the published subnodes in the context of the given ‘renderstate`, but save them for publication after the render is done.

# File lib/inversion/template/publishtag.rb, line 53
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.publish( self.key, *rendered_nodes ) unless rendered_nodes.empty?

        return nil
end