#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) require File.join( currentPath, '../test_helper' ) class Parent < MasterView::DirectiveBase metadata :namespace => 'exa', :priority => 'High', :category => 'example', :description => 'Example of a parent directive which takes input from its children' def initialize(dcs) super @children_ids = [] end def add_child_id(id) @children_ids.push id end event :after_etag do render @children_ids.inspect end end class Child < MasterView::DirectiveBase metadata :namespace => 'exa', :category => 'example', :description => 'Example of a child directive which communicates with the parent' event :stag do parent = find_parent_directive(Parent) parent.add_child_id(attr_value) if parent end end class ChildWithBlock < MasterView::DirectiveBase metadata :namespace => 'exa', :category => 'example', :description => 'Example of a child directive which contains a filter block which communicates with the parent' event :stag do parent = find_parent_directive(Parent){ |d| d.attr_value=="hello" } parent.add_child_id(attr_value) if parent end end class TestFindDirectiveParent < Test::Unit::TestCase def setup MasterView::IOMgr.erb = MasterView::MIO::StringHashMIOTree.new({}, '.rhtml', :logging => true) end def test_find_multiple_levels template = <<-END