Changeset 393

Show
Ignore:
Timestamp:
10/09/07 22:18:17 (1 year ago)
Author:
bermiferrer
Message:

Implementing support for Sintags assignments and basic blocks

The following things are not possible when using Sintags in your views

<% keys {|key| echo $key} %>
<% keys, values {|key| ++$key } %>
<% incremented = keys {|key| ++$key} %>
<% simple_var = 'value' %>
<% simple_var = var-foo %>
<%= var = var.foo %>
<% url = url_for(:controller => 'page') %>
<% url = {:controller => 'page'} %>
<% url = :controller => 'page' %>

Support for key pairs on blocks and iterating overs methods and Active Records are not implemented yet.

Fixing notice on the plugin manager.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AkActionView/TemplateEngines/AkSintags/AkSintagsLexer.php

    r347 r393  
    2121    var $_SINTAGS_REMOVE_PHP_SILENTLY = AK_SINTAGS_REMOVE_PHP_SILENTLY; 
    2222    var $_SINTAGS_HIDDEN_COMMENTS_TAG = AK_SINTAGS_HIDDEN_COMMENTS_TAG; 
    23      
     23 
    2424    var $_SINTAGS_OPEN_HELPER_TAG = AK_SINTAGS_OPEN_HELPER_TAG; 
    2525    var $_SINTAGS_CLOSE_HELPER_TAG = AK_SINTAGS_CLOSE_HELPER_TAG; 
    26      
     26 
    2727    var $_modes = array( 
    2828    'Xml', 
    2929    'Php', 
    3030    'Comment', 
     31    'Block', 
    3132    'Helper', 
    3233    'EscapedText', 
     
    5758        $this->addSpecialPattern('<\?xml','Text','XmlOpening'); 
    5859    } 
    59      
     60 
    6061    function _addPhpTokens() 
    6162    { 
     
    8384        $this->addSpecialPattern('\x5C_(?={)','Text','EscapedText'); 
    8485    } 
    85      
     86 
    8687    function _addTranslationTokens() 
    8788    { 
     
    121122        $this->addSpecialPattern('{else}','Text','ElseTag'); 
    122123    } 
    123      
     124 
    124125    function _addLoopTokens() 
    125126    { 
    126127        $this->addSpecialPattern('{loop[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]*\??}','Text','Loop'); 
    127128    } 
    128      
     129 
    129130    function _addLoopAsTokens() 
    130131    { 
    131132        $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'); 
    132133    } 
    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 
    134153    function _addHelperTokens() 
    135154    { 
    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]*'. 
    137156        '(?=.*'.$this->_SINTAGS_CLOSE_HELPER_TAG.')','Text','Helper'); 
    138157        $this->addExitPattern('\x29?[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'Helper'); 
     
    150169    } 
    151170 
     171 
    152172    function _addInlineHelperTokens() 
    153173    { 
     
    188208 
    189209 
    190  
    191210        $this->addSpecialPattern('\x5B',$scope,'Struct'); 
    192211        $this->addSpecialPattern('\x5D',$scope,'Struct'); 
  • trunk/lib/AkActionView/TemplateEngines/AkSintags/AkSintagsParser.php

    r360 r393  
    3030    var $_matches; 
    3131    var $_current_match; 
     32    var $_block_vars = array(); 
    3233    var $output; 
    3334    var $escape_chars = array( 
     
    349350        switch ($state){ 
    350351            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                } 
    351357                $method_name = trim($match,' =('.$this->_SINTAGS_OPEN_HELPER_TAG); 
    352358                if($helper = $this->_getHelperNameForMethod($method_name)){ 
     
    543549        return true; 
    544550    } 
     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 
    545637 
    546638    function raiseError($error, $type = E_USER_NOTICE) 
  • trunk/lib/AkPlugin/AkPluginManager.php

    r392 r393  
    212212    { 
    213213        if($this->canUseSvn()){ 
    214             if($options['externals'] && $this->_shouldUseSvnExternals()){ 
     214            if(!empty($options['externals']) && $this->_shouldUseSvnExternals()){ 
    215215                return 'externals'; 
    216             }elseif($options['checkout'] && $this->_shouldUseSvnCheckout()){ 
     216            }elseif(!empty($options['checkout']) && $this->_shouldUseSvnCheckout()){ 
    217217                return 'checkout'; 
    218218            } 
  • trunk/test/unit/lib/AkActionView/TemplateEngines/AkSintags.php

    r347 r393  
    99class Test_of_AkSintags extends  UnitTestCase 
    1010{ 
    11  
    1211    function test_sintags() 
    1312    { 
     
    1817        $this->_run_from_file('sintags_helpers_data.txt'); 
    1918    } 
    20  
     19     
     20    function test_sintags_blocks() 
     21    { 
     22        $this->_run_from_file('sintags_blocks_data.txt'); 
     23    } 
     24     
    2125    function _run_from_file($file_name, $all_in_one_test = true) 
    2226    {