#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) require File.join( currentPath, '../../lib/masterview/directives/import_render') class TestImportRender < Test::Unit::TestCase include MasterView::Directives include MasterView::DirectiveHelpers def setup @mio_output_tree = MasterView::StringHashMIOTree.new @renderer = MasterView::Renderer.new(:output_mio_tree => @mio_output_tree) #this sets up Renderer.last_renderer for import_test @directives = MasterView::DirectiveSet.new end def test_import_render import_render_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, nil) @directives.directives = [] attr_value = ":partial => 'foo/bar'" @directives << Import_render.new(attr_value) dcs = @directives.determine_dcs(:stag) dcs.context = import_render_tag.create_context assert_equal nil, dcs.render dcs = @directives.determine_dcs(:etag) dcs.context = import_render_tag.create_context assert_equal ERB_EVAL+'render( '+attr_value+' )'+ERB_END, dcs.render.join end def test_import_render_keyword_expansion @renderer.keyword_expander.set_template_pathname('foo/bar.html', '.rhtml') import_render_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, nil) @directives.directives = [] attr_value = %q[:partial => '{template_dir_path}/{template_basename}'] @directives << Import_render.new(attr_value) dcs = @directives.determine_dcs(:stag) dcs.context = import_render_tag.create_context assert_equal nil, dcs.render dcs = @directives.determine_dcs(:etag) dcs.context = import_render_tag.create_context assert_equal ERB_EVAL+ %q[render( :partial => 'foo/bar' )]+ERB_END, dcs.render.join end def test_import_render_keyword_expansion_subdir @renderer.keyword_expander.set_template_pathname('one/foo/bar.html', '.rhtml') import_render_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, nil) @directives.directives = [] attr_value = %q[:partial => '{template_dir_path}/{template_basename}'] @directives << Import_render.new(attr_value) dcs = @directives.determine_dcs(:stag) dcs.context = import_render_tag.create_context assert_equal nil, dcs.render dcs = @directives.determine_dcs(:etag) dcs.context = import_render_tag.create_context assert_equal ERB_EVAL+ %q[render( :partial => 'one/foo/bar' )]+ERB_END, dcs.render.join end end