Changeset 393
- Timestamp:
- 10/09/07 22:18:17 (1 year ago)
- Files:
-
- trunk/lib/AkActionView/TemplateEngines/AkSintags/AkSintagsLexer.php (modified) (6 diffs)
- trunk/lib/AkActionView/TemplateEngines/AkSintags/AkSintagsParser.php (modified) (3 diffs)
- trunk/lib/AkPlugin/AkPluginManager.php (modified) (1 diff)
- trunk/test/fixtures/data/sintags_blocks_data.txt (added)
- trunk/test/unit/lib/AkActionView/TemplateEngines/AkSintags.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AkActionView/TemplateEngines/AkSintags/AkSintagsLexer.php
r347 r393 21 21 var $_SINTAGS_REMOVE_PHP_SILENTLY = AK_SINTAGS_REMOVE_PHP_SILENTLY; 22 22 var $_SINTAGS_HIDDEN_COMMENTS_TAG = AK_SINTAGS_HIDDEN_COMMENTS_TAG; 23 23 24 24 var $_SINTAGS_OPEN_HELPER_TAG = AK_SINTAGS_OPEN_HELPER_TAG; 25 25 var $_SINTAGS_CLOSE_HELPER_TAG = AK_SINTAGS_CLOSE_HELPER_TAG; 26 26 27 27 var $_modes = array( 28 28 'Xml', 29 29 'Php', 30 30 'Comment', 31 'Block', 31 32 'Helper', 32 33 'EscapedText', … … 57 58 $this->addSpecialPattern('<\?xml','Text','XmlOpening'); 58 59 } 59 60 60 61 function _addPhpTokens() 61 62 { … … 83 84 $this->addSpecialPattern('\x5C_(?={)','Text','EscapedText'); 84 85 } 85 86 86 87 function _addTranslationTokens() 87 88 { … … 121 122 $this->addSpecialPattern('{else}','Text','ElseTag'); 122 123 } 123 124 124 125 function _addLoopTokens() 125 126 { 126 127 $this->addSpecialPattern('{loop[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]*\??}','Text','Loop'); 127 128 } 128 129 129 130 function _addLoopAsTokens() 130 131 { 131 132 $this->addSpecialPattern('{loop[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]+[ \n\t]+as[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]*\??}','Text','Loop'); 132 133 } 133 134 135 function _addBlockTokens() 136 { 137 if(!$this->_SINTAGS_REMOVE_PHP_SILENTLY){ 138 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'[ \n\t]*[A-Za-z][\.A-Za-z0-9_ ,=-]*[ \n\t]*\x7B[ \n\t]*\x7c','Text', 'Block'); 139 $this->addPattern('[A-Za-z0-9_, \n\t\x7c]+[ \n\t]*\x7c','Block'); 140 $this->addExitPattern('\x7D[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'Block'); 141 }else{ 142 $this->mapHandler('php', 'ignore'); 143 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'[ \n\t]*[A-Za-z][\.A-Za-z0-9_ ,=-]*[ \n\t]*\x7B[ \n\t]*\x7c','Text', 'ignore'); 144 $this->addPattern('[A-Za-z0-9_, \n\t\x7c]+[ \n\t]*\x7c','ignore'); 145 $this->addExitPattern('\x7D[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'ignore'); 146 } 147 148 149 150 151 } 152 134 153 function _addHelperTokens() 135 154 { 136 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'\x3D?[ \n\t]*[A-Za-z0-9_]+[ \n\t ]*\x28?[ \n\t]*'.155 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'\x3D?[ \n\t]*[A-Za-z0-9_]+[ \n\t\x3D]*\x28?[ \n\t]*'. 137 156 '(?=.*'.$this->_SINTAGS_CLOSE_HELPER_TAG.')','Text','Helper'); 138 157 $this->addExitPattern('\x29?[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'Helper'); … … 150 169 } 151 170 171 152 172 function _addInlineHelperTokens() 153 173 { … … 188 208 189 209 190 191 210 $this->addSpecialPattern('\x5B',$scope,'Struct'); 192 211 $this->addSpecialPattern('\x5D',$scope,'Struct'); trunk/lib/AkActionView/TemplateEngines/AkSintags/AkSintagsParser.php
r360 r393 30 30 var $_matches; 31 31 var $_current_match; 32 var $_block_vars = array(); 32 33 var $output; 33 34 var $escape_chars = array( … … 349 350 switch ($state){ 350 351 case AK_LEXER_ENTER: 352 if(preg_match('/=+$/', trim($match))){ 353 $this->avoid_php_tags = $this->_current_function_opening = false; 354 $this->output .= '<?php '.$this->_convertSintagsVarToPhp(trim($match,' =('.$this->_SINTAGS_OPEN_HELPER_TAG)).' = ('; 355 return true; 356 } 351 357 $method_name = trim($match,' =('.$this->_SINTAGS_OPEN_HELPER_TAG); 352 358 if($helper = $this->_getHelperNameForMethod($method_name)){ … … 543 549 return true; 544 550 } 551 552 553 //----------------------------------------- 554 // SINTAGS BLOCKS 555 //----------------------------------------- 556 function Block($match, $state) 557 { 558 switch ($state){ 559 case AK_LEXER_ENTER: 560 $this->_block = ''; 561 $this->_block_params = array(); 562 $this->_block_data = array(); 563 if(strstr($match, '=')){ 564 list($parameters, $match) = explode('=', $match); 565 $parameters = array_diff(array_map('trim', Ak::toArray(trim($parameters,' (){|'.$this->_SINTAGS_OPEN_HELPER_TAG))), array('')); 566 foreach ($parameters as $parameter){ 567 if($parameter = $this->_convertSintagsVarToPhp($parameter)){ 568 $this->_block_params[] = $parameter; 569 }else{ 570 return false; 571 } 572 } 573 } 574 $method_or_var_names = array_diff(array_map('trim', Ak::toArray(trim($match,' (){|'.$this->_SINTAGS_OPEN_HELPER_TAG))), array('')); 575 foreach ($method_or_var_names as $method_or_var_name){ 576 if($helper = $this->_getHelperNameForMethod($method_or_var_name)){ 577 if(!strpos($helper, 'helper')){ 578 $method_or_var_name = AkInflector::variablize($method_or_var_name); 579 } 580 $this->_block_data[] = "\${$helper}->$method_or_var_name()"; 581 return true; 582 }elseif(!strstr($match,'(') && $php_variable = $this->_convertSintagsVarToPhp($method_or_var_name)){ 583 $this->_block_data[] = $php_variable; 584 }else{ 585 $this->raiseError(Ak::t('Could not find a helper to handle the method "%method" you called in your view', array('%method'=>$method_or_var_name)), E_USER_NOTICE); 586 } 587 } 588 589 break; 590 case AK_LEXER_MATCHED: 591 $this->_block_keys = array(); 592 $parameters = Ak::toArray($match); 593 foreach ($parameters as $parameter){ 594 if($parameter = $this->_convertSintagsVarToPhp($parameter)){ 595 $this->_block_keys[] = $parameter; 596 }else{ 597 return false; 598 } 599 } 600 break; 601 case AK_LEXER_UNMATCHED: 602 $this->_block .= $match; 603 break; 604 case AK_LEXER_EXIT: 605 606 $this->output .= "<?php \n"; 607 foreach ($this->_block_data as $k=>$block_data){ 608 if(strstr($block_data,'->')){ 609 /** 610 * @todo Implement helper calls on blocks 611 */ 612 }else{ 613 $this->output .= "if(!empty($block_data)){\n"; 614 if(!empty($this->_block_params[$k])){ 615 $this->output .= " {$this->_block_params[$k]} = array();\n"; 616 } 617 $this->output .= " foreach (array_keys((array)$block_data) as \$ak_sintags_key){\n"; 618 if(count($this->_block_keys) == 1){ 619 $this->output .= " {$this->_block_keys[0]} =& {$block_data}[\$ak_sintags_key];\n"; 620 } 621 $this->output .= " $this->_block;\n"; 622 if(!empty($this->_block_params[$k])){ 623 $this->output .= " {$this->_block_params[$k]}[\$ak_sintags_key] = {$block_data}[\$ak_sintags_key];\n"; 624 } 625 $this->output .= " }\n"; 626 $this->output .= "}"; 627 } 628 } 629 $this->output .= "?>"; 630 631 return true; 632 } 633 634 return true; 635 } 636 545 637 546 638 function raiseError($error, $type = E_USER_NOTICE) trunk/lib/AkPlugin/AkPluginManager.php
r392 r393 212 212 { 213 213 if($this->canUseSvn()){ 214 if( $options['externals']&& $this->_shouldUseSvnExternals()){214 if(!empty($options['externals']) && $this->_shouldUseSvnExternals()){ 215 215 return 'externals'; 216 }elseif( $options['checkout']&& $this->_shouldUseSvnCheckout()){216 }elseif(!empty($options['checkout']) && $this->_shouldUseSvnCheckout()){ 217 217 return 'checkout'; 218 218 } trunk/test/unit/lib/AkActionView/TemplateEngines/AkSintags.php
r347 r393 9 9 class Test_of_AkSintags extends UnitTestCase 10 10 { 11 12 11 function test_sintags() 13 12 { … … 18 17 $this->_run_from_file('sintags_helpers_data.txt'); 19 18 } 20 19 20 function test_sintags_blocks() 21 { 22 $this->_run_from_file('sintags_blocks_data.txt'); 23 } 24 21 25 function _run_from_file($file_name, $all_in_one_test = true) 22 26 {
