view Lib/IMPL/Web/View/TTView.pm @ 353:feeb3bc4a818

corrected error handling while loading templates corrected variables lookup in controls updated handles to use the new view features
author cin
date Fri, 11 Oct 2013 15:49:04 +0400
parents cfd7570c2af2
children 9330835535b9
line wrap: on
line source

package IMPL::Web::View::TTView;
use strict;

use IMPL::lang qw(hashMerge);
use IMPL::Const qw(:prop);
use IMPL::declare {
	require => {
		Context => 'IMPL::Web::View::TTContext'
	},
	base => [
		'IMPL::Object' => undef,
		'IMPL::Object::Autofill' => '@_',
		'IMPL::Object::Serializable' => undef
	],
	props => [
		options => PROP_RW,
		viewBase => PROP_RW,
		layoutBase => PROP_RW,
		layout => PROP_RW,
		tt_ext => PROP_RW,
		includes => PROP_RW | PROP_LIST,
		globals => PROP_RW
	]
};

sub CTOR {
	my ($this) = @_;
	
	$this->tt_ext('tt') unless defined $this->tt_ext;
}

sub display {
	my ($this,$model,$template,$args) = @_;
	
	my $context = Context->new($this->options);
	my $layout = delete $args->{layout} || $this->layout;
	
	return $context->invoke_environment(
		sub {
			my $ctx = shift;
			if ($layout) {
				return $ctx->invoke_environment(
					sub {
						return $ctx->render($layout,$args);
					},
					{
						base => $this->layoutBase,
						content => sub {
							$ctx->invoke_environment(
								sub {
									return shift->display_model($model,$template,$args);
								},
								{
									base => $this->viewBase
								}
							)
						}
					}
				);
			} else {
				return $ctx->invoke_environment(
					sub {
						return $ctx->display_model($model,$template,$args);
					},
					{
						base => $this->viewBase
					}
				);
			}
		},hashMerge(
			{
				includes => scalar($this->includes),
				tt_ext => $this->tt_ext,
				document => {},
				debug => sub {
					warn @_;
				}
			},
			$this->globals
		)
	);
}

1;