Blame view

mobile/source/ext/phptal/PHPTAL/Php/Attribute/TAL/Content.php 2.62 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  <?php
  /**
   * PHPTAL templating engine
   *
   * PHP Version 5
   *
   * @category HTML
   * @package  PHPTAL
   * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
   * @author   Kornel LesiƄski <kornel@aardvarkmedia.co.uk>
   * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
   * @version  SVN: $Id: Content.php 605 2009-05-03 02:50:26Z kornel $
   * @link     http://phptal.org/
   */
  
  
  /** TAL Specifications 1.4
   *
   *     argument ::= (['text'] | 'structure') expression
   *
   * Example:
   *
   *     <p tal:content="user/name">Fred Farkas</p>
   *
   *
   *
   *
   * @package PHPTAL
   * @subpackage Php.attribute.tal
   * @author Laurent Bedubourg <lbedubourg@motion-twin.com>
   */
  class PHPTAL_Php_Attribute_TAL_Content
  extends PHPTAL_Php_Attribute
  implements PHPTAL_Php_TalesChainReader
  {
      public function before(PHPTAL_Php_CodeWriter $codewriter)
      {
          $expression = $this->extractEchoType($this->expression);
  
          $code = $codewriter->evaluateExpression($expression);
  
          if (is_array($code)) {
              return $this->generateChainedContent($codewriter, $code);
          }
  
          if ($code == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) {
              return;
          }
  
          if ($code == PHPTAL_Php_TalesInternal::DEFAULT_KEYWORD) {
              return $this->generateDefault($codewriter);
          }
  
          $this->doEchoAttribute($codewriter, $code);
      }
  
      public function after(PHPTAL_Php_CodeWriter $codewriter)
      {
      }
  
      private function generateDefault(PHPTAL_Php_CodeWriter $codewriter)
      {
          $this->phpelement->generateContent($codewriter,true);
      }
  
      private function generateChainedContent(PHPTAL_Php_CodeWriter $codewriter, $code)
      {
          $executor = new PHPTAL_Php_TalesChainExecutor($codewriter, $code, $this);
      }
  
      public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
      {
          if (!$islast) {
              $var = $executor->getCodeWriter()->createTempVariable();
              $executor->doIf('!phptal_isempty('.$var.' = '.$exp.')');
              $this->doEchoAttribute($executor->getCodeWriter(), $var);
              $executor->getCodeWriter()->recycleTempVariable($var);
          } else {
              $executor->doElse();
              $this->doEchoAttribute($executor->getCodeWriter(), $exp);
          }
      }
  
      public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
      {
          $executor->breakChain();
      }
  
      public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
      {
          $executor->doElse();
          $this->generateDefault($executor->getCodeWriter());
          $executor->breakChain();
      }
  }