Class: Inversion::Template::PublishTag
- Includes:
- ContainerTag
- Defined in:
- lib/inversion/template/publishtag.rb
Overview
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>
Constant Summary
Constants inherited from Tag
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
The name of the key the nodes will be published under.
Attributes included from ContainerTag
Attributes inherited from Tag
Attributes inherited from Node
Instance Method Summary collapse
-
#as_comment_body ⇒ Object
Render the tag as the body of a comment, suitable for template debugging.
-
#initialize(body, line = nil, column = nil) ⇒ PublishTag
constructor
Create a new PublishTag with the given
body. -
#render(renderstate) ⇒ Object
Render the published subnodes in the context of the given
renderstate, but save them for publication after the render is done.
Methods included from ContainerTag
#<<, #is_container?, #render_subnodes
Methods inherited from Tag
create, #derivatives, inherited, load, load_all, #tagname, types, #types
Methods included from MethodUtilities
#singleton_attr_accessor, #singleton_attr_reader, #singleton_attr_writer
Methods included from AbstractClass
Methods included from AbstractClass::ClassMethods
Methods inherited from Node
#after_appending, #after_rendering, #before_appending, #before_rendering, #is_container?, #location
Constructor Details
#initialize(body, line = nil, column = nil) ⇒ PublishTag
Create a new PublishTag with the given body.
34 35 36 37 38 39 40 41 |
# File 'lib/inversion/template/publishtag.rb', line 34 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 |
Instance Attribute Details
#key ⇒ Object (readonly)
The name of the key the nodes will be published under
49 50 51 |
# File 'lib/inversion/template/publishtag.rb', line 49 def key @key end |
Instance Method Details
#as_comment_body ⇒ Object
Render the tag as the body of a comment, suitable for template debugging.
71 72 73 |
# File 'lib/inversion/template/publishtag.rb', line 71 def as_comment_body return "Published %d nodes as %s" % [ self.subnodes.length, self.key ] end |
#render(renderstate) ⇒ Object
Render the published subnodes in the context of the given renderstate, but save them for publication after the render is done.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/inversion/template/publishtag.rb', line 54 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 |