Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/TTFactory.pm @ 336:86336d451b82
sync
| author | cin | 
|---|---|
| date | Fri, 14 Jun 2013 03:32:55 +0400 | 
| parents | 75a78cbf7dcf | 
| children | f4e14f32cf54 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 335:e8be9062ecf2 | 336:86336d451b82 | 
|---|---|
| 5 | 5 | 
| 6 use Carp qw(carp); | 6 use Carp qw(carp); | 
| 7 use IMPL::lang qw(:hash is); | 7 use IMPL::lang qw(:hash is); | 
| 8 use IMPL::Exception(); | 8 use IMPL::Exception(); | 
| 9 use Scalar::Util qw(weaken); | 9 use Scalar::Util qw(weaken); | 
| 10 use IMPL::Resources::Format qw(FormatMessage); | |
| 11 use IMPL::Resources::Strings(); | |
| 10 | 12 | 
| 11 | 13 | 
| 12 use IMPL::Const qw(:prop); | 14 use IMPL::Const qw(:prop); | 
| 13 use IMPL::declare { | 15 use IMPL::declare { | 
| 14 require => { | 16 require => { | 
| 27 context => PROP_RW, | 29 context => PROP_RW, | 
| 28 baseLocation => PROP_RW, | 30 baseLocation => PROP_RW, | 
| 29 base => PROP_RW, | 31 base => PROP_RW, | 
| 30 registry => PROP_RO, | 32 registry => PROP_RO, | 
| 31 blocks => PROP_RO, | 33 blocks => PROP_RO, | 
| 34 path => PROP_RO, | |
| 32 _instance => PROP_RW | 35 _instance => PROP_RW | 
| 33 ] | 36 ] | 
| 34 }; | 37 }; | 
| 35 | 38 | 
| 36 sub CTOR { | 39 sub CTOR { | 
| 48 | 51 | 
| 49 $this->activation($template->activation || 'new'); | 52 $this->activation($template->activation || 'new'); | 
| 50 $this->template($template); | 53 $this->template($template); | 
| 51 $this->context($context); | 54 $this->context($context); | 
| 52 $this->baseLocation($baseLocation); | 55 $this->baseLocation($baseLocation); | 
| 56 $this->path($path); | |
| 53 $this->registry($registry); | 57 $this->registry($registry); | 
| 54 | 58 | 
| 55 if (my $baseTplName = $template->extends) { | 59 if (my $baseTplName = $template->extends) { | 
| 56 $baseTplName =~ s{^\./}{$baseLocation/}; | 60 $baseTplName =~ s{^\./}{$baseLocation/}; | 
| 57 | 61 | 
| 96 while (my ($name,$block) = each %$blocks) { | 100 while (my ($name,$block) = each %$blocks) { | 
| 97 $context->define_block($name,$block); | 101 $context->define_block($name,$block); | 
| 98 } | 102 } | 
| 99 } | 103 } | 
| 100 | 104 | 
| 101 $context->stash->update({ require => sub { | 105 $context->stash->update({ | 
| 102 my ($module) = @_; | 106 require => sub { | 
| 103 | 107 my ($module) = @_; | 
| 104 $module =~ s/^\.\//$baseLocation\//; | 108 | 
| 105 return $registry->Require($module); | 109 $module =~ s/^\.\//$baseLocation\//; | 
| 106 }}); | 110 return $registry->Require($module); | 
| 111 } | |
| 112 }); | |
| 107 } | 113 } | 
| 108 | 114 | 
| 109 sub MergeParameters { | 115 sub MergeParameters { | 
| 110 my $this = shift; | 116 my $this = shift; | 
| 111 my $refProps = shift || {}; | 117 my $refProps = shift || {}; | 
| 117 $refProps->{name} ||= $name; | 123 $refProps->{name} ||= $name; | 
| 118 } | 124 } | 
| 119 | 125 | 
| 120 $refProps->{factory} = $this; | 126 $refProps->{factory} = $this; | 
| 121 my $ctx = $this->CloneContext(); | 127 my $ctx = $this->CloneContext(); | 
| 128 | |
| 129 my $t = $ctx; | |
| 130 weaken($t); | |
| 131 | |
| 132 $ctx->stash->update({ | |
| 133 strings => sub { | |
| 134 my ($labels) = @_; | |
| 135 if(ref($labels) eq 'HASH') { | |
| 136 #TODO make strings map shared between controls | |
| 137 my $map; | |
| 138 my $vars; | |
| 139 while(my ($label,$text) = each %$labels) { | |
| 140 $vars->{$label} = sub { | |
| 141 my ($params) = @_; | |
| 142 | |
| 143 my $locale = 'ru_RU'; | |
| 144 | |
| 145 unless($map->{$locale}) { | |
| 146 my $file = $this->registry->loader->ResolveFileName($this->path); | |
| 147 if($file and -f "$file.$locale") { | |
| 148 warn "STRINGS: $file.$locale"; | |
| 149 $map->{$locale} = IMPL::Resources::String::ParseStringsMap("$file.$locale"); | |
| 150 } else { | |
| 151 $map->{$locale} = {}; | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 return FormatMessage(($map->{$locale}{$label} || $text),$params); | |
| 156 } | |
| 157 } | |
| 158 $t->stash->update($vars); | |
| 159 } | |
| 160 return; | |
| 161 } | |
| 162 }); | |
| 122 | 163 | 
| 123 return ($this->template, $ctx, $refProps); | 164 return ($this->template, $ctx, $refProps); | 
| 124 } | 165 } | 
| 125 | 166 | 
| 126 sub CreateObject { | 167 sub CreateObject { | 
