# HG changeset patch # User cin # Date 1382017730 -14400 # Node ID 97131d500f1657b669194816a9009dae5860da04 # Parent 8dfb9df07d02d5989ebd2a162ce1fbddbd269530 TTView: added identifiers support diff -r 8dfb9df07d02 -r 97131d500f16 Lib/IMPL/Web/View/TTContext.pm --- a/Lib/IMPL/Web/View/TTContext.pm Thu Oct 17 01:04:37 2013 +0400 +++ b/Lib/IMPL/Web/View/TTContext.pm Thu Oct 17 17:48:50 2013 +0400 @@ -34,6 +34,7 @@ includes modules aliases + id )) { my $t = $prop; @@ -65,6 +66,14 @@ return $clone; } +sub get_next_id { + my ($this) = @_; + + my $id = $this->stash->get('document.nextId') || 0; + $this->stash->set('document.nextId', $id + 1); + return "w-$id"; +} + sub find_template { my ($this,$name) = @_; @@ -267,7 +276,7 @@ } if (my $class = $info->{class}) { - $class->new($this,$info->{template})->Render($args); + $class->new($ctx,$info->{template},$args)->Render($args); } else { return $ctx->include($info->{template},$args); } @@ -276,7 +285,8 @@ $info->{labels} || {}, { base => $info->{base}, - parent => $this + parent => $this, + id => $this->get_next_id } ) ) @@ -288,9 +298,9 @@ die ArgException->new(prefix => "the prefix must be specified") unless defined $prefix; - #TODO handle DOM models + - if (my $res = $this->stash->get(['resolver', [$this,$prefix,$args]] ) ) { + if (my $res = $this->stash->get(['resolve', [$this,$prefix,$args]] ) ) { return $res; } diff -r 8dfb9df07d02 -r 97131d500f16 Lib/IMPL/Web/View/TTControl.pm --- a/Lib/IMPL/Web/View/TTControl.pm Thu Oct 17 01:04:37 2013 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Thu Oct 17 17:48:50 2013 +0400 @@ -13,22 +13,10 @@ ], props => [ context => PROP_RO, - template => PROP_RO, - id => { - get => sub { shift->_stash->get('id') }, - set => sub { shift->_stash->set('id',shift) } - } + template => PROP_RO ] }; - -{ - my $nextId = 1; - sub _GetNextId { - return '_' . $nextId++; - } -} - our $AUTOLOAD_REGEX = qr/^[a-z]/; sub CTOR { @@ -40,6 +28,20 @@ or die ArgException->new(template => 'A template is required'); } +sub _PopulateMethods { + my ($this,@methods) = @_; + + $this->_stash->update({ + map { + my $name = $_; + $name, + sub { + $this->$name(@_); + } + } @methods + }); +} + sub _stash { $_[0]->context->stash; }