Method: Innate::Node#layout

Defined in:
lib/innate/node.rb

#layout(layout_name = nil, &block) ⇒ Proc, String

Define a layout to use on this Node.

A Node can only have one layout, although the template being chosen can depend on #provides.

Examples:

layout :foo
layout do |name, wish|
  name == 'foo' ? 'dark' : 'bright'
end
layout :foo do |name, wish|
  wish == 'html'
end

Parameters:

  • layout_name (String, #to_s) (defaults to: nil)

    basename without extension of the layout to use

  • block (Proc, #call)

    called on every dispatch if no name given

Returns:

  • (Proc, String)

    The assigned name or block

See Also:

Author:

  • manveru



682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'lib/innate/node.rb', line 682

def layout(layout_name = nil, &block)
  if layout_name and block
    # default name, but still check with block
    trait(:layout => lambda{|name, wish| layout_name.to_s if block.call(name, wish) })
  elsif layout_name
    # name of a method or template
    trait(:layout => layout_name.to_s)
  elsif block
    # call block every request with name and wish, returned value is name
    # of layout template or method
    trait(:layout => block)
  else
    # remove layout for this node
    trait(:layout => nil)
  end

  return ancestral_trait[:layout]
end