Show
Ignore:
Timestamp:
12/20/05 15:32:14 (3 years ago)
Author:
jlz
Message:

Reference handling fixes and support for <(template)> syntax.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/sandbox/mrfc0022/midgard_style_backend_test.php

    r9071 r9075  
    3232 
    3333    function setUp() { 
    34         $this->backend = new simple_midgard_style_backend(); 
    35         $this->context = new midgard_style_backend_context($this->backend); 
     34        $this->backend =& new simple_midgard_style_backend(); 
     35        $this->context =& new midgard_style_backend_context($this->backend); 
    3636    } 
    3737 
  • trunk/src/sandbox/mrfc0022/midgard_style_context_test.php

    r9071 r9075  
    5757 
    5858        function setUp() { 
    59         $this->context = new chained_midgard_style_context(); 
     59        $this->context =& new chained_midgard_style_context(); 
    6060        $this->context->add_context( 
    6161                new simple_midgard_style_context(array("foo" => "123"))); 
  • trunk/src/sandbox/mrfc0022/midgard_style_engine.php

    r9071 r9075  
    5050 
    5151function _standard_midgard_style_engine_render($name) { 
    52         $context = $_MIDGARD["midgard_style_context"]; 
    53         $engine = $_MIDGARD["midgard_style_engine"]; 
     52        global $_standard_midgard_style_engine; 
     53        $engine =& $_standard_midgard_style_engine["midgard_style_engine"]; 
     54        $context =& $_standard_midgard_style_engine["midgard_style_context"]; 
    5455        $template = $context->get_element($name); 
    5556        $engine->render($template); 
     
    6566 
    6667    function phpize($element) { 
    67         // TODO: Simple matcher for the midgard template codes 
    68         // $element = preg_replace( 
    69                 //      "/<\\(([a-zA-Z0-9 _-]+)\\)>/", 
    70         //    "<?php _standard_midgard_style_engine_render(\"\\1\"); ?>", 
    71         //    $element); 
     68        $parts = preg_split( 
     69                        "/<\\(([a-zA-Z0-9 _-]+)\\)>/", $element, 
     70                        -1, PREG_SPLIT_DELIM_CAPTURE); 
     71                $element = ""; 
     72                for ($i = 0; $i < count($parts); $i += 2) { 
     73                        if ($parts[$i]) { 
     74                                $element .= "echo \"" . addslashes($parts[$i]) . "\";"; 
     75                        } 
     76                        if ($i + 1 < count($parts) && $parts[$i+1]) { 
     77                                $element .= "_standard_midgard_style_engine_render(\"" . $parts[$i+1] . "\");"; 
     78                        } 
     79                } 
    7280        return $element; 
    7381    } 
     
    98106 
    99107    function interpret($element) { 
    100         print "$element\n"; 
    101         eval("?>$element<?php"); 
     108        eval($element); 
    102109    } 
    103110 
    104111    function render($element) { 
    105112        global $_MIDGARD; 
    106         $old_engine = $_MIDGARD["midgard_style_engine"]; 
    107         $old_context = $_MIDGARD["midgard_style_context"]; 
    108         $_MIDGARD["midgard_style_engine"] = $this; 
    109         $_MIDGARD["midgard_style_context"] = $this->context; 
     113        global $_standard_midgard_style_engine; 
     114        $old_engine =& $_MIDGARD["midgard_style_engine"]; 
     115        $old_context =& $_MIDGARD["midgard_style_context"]; 
     116        $_MIDGARD["midgard_style_engine"] =& $this; 
     117        $_MIDGARD["midgard_style_context"] =& $this->context; 
     118        $_standard_midgard_style_engine["midgard_style_engine"] =& $this; 
     119        $_standard_midgard_style_engine["midgard_style_context"] =& $this->context; 
    110120        $this->interpret($this->compile($element)); 
    111         $_MIDGARD["midgard_style_engine"] = $old_engine; 
    112         $_MIDGARD["midgard_style_context"] = $old_context; 
     121        $_MIDGARD["midgard_style_engine"] =& $old_engine; 
     122        $_MIDGARD["midgard_style_context"] =& $old_context; 
     123        return; 
    113124    } 
    114125 
  • trunk/src/sandbox/mrfc0022/midgard_style_engine_test.php

    r9071 r9075  
    3232    function setUp() { 
    3333        $elements = array("foo" => "abc<(bar)>def", "bar" => "123"); 
    34         $context = new simple_midgard_style_context($elements); 
    35         $this->engine = new standard_midgard_style_engine($this->context); 
     34        $context =& new simple_midgard_style_context($elements); 
     35        $this->engine =& new standard_midgard_style_engine($context); 
    3636    } 
    3737 
     
    4141 
    4242    function test_phpize() { 
    43                 $this->assertEquals("abc", $this->engine->phpize("abc")); 
     43                $this->assertEquals("echo \"abc\";", $this->engine->phpize("abc")); 
    4444                $this->assertEquals( 
    45                         "<?php _standard_midgard_style_engine_render(\"foo\"); ?>", 
     45                        "_standard_midgard_style_engine_render(\"foo\");", 
    4646                        $this->engine->phpize("<(foo)>")); 
    4747                $this->assertEquals( 
    48                         "123<?php _standard_midgard_style_engine_render(\"foo\"); ?>321", 
     48                        "echo \"123\";_standard_midgard_style_engine_render(\"foo\");echo \"321\";", 
    4949                        $this->engine->phpize("123<(foo)>321")); 
    5050                $this->assertEquals( 
    51                         "<?php echo 1; ?>", 
     51                        "echo \"<?php echo 1; ?>\";", 
    5252                        $this->engine->phpize("<?php echo 1; ?>")); 
    5353                $this->assertEquals( 
    54                         "<?php echo \"<?php _standard_midgard_style_engine_render(\"foo\"); ?>\"; ?>", 
     54                        "echo \"<?php echo \\\"\";_standard_midgard_style_engine_render(\"foo\");echo \"\\\"; ?>\";", 
    5555                        $this->engine->phpize("<?php echo \"<(foo)>\"; ?>")); 
    5656    } 
    5757 
    5858        function test_compile() { 
    59                 $this->assertEquals("abc", $this->engine->compile("abc")); 
     59                $this->assertEquals("echo \"abc\";", $this->engine->compile("abc")); 
    6060                $this->assertEquals( 
    61                         "<?php _standard_midgard_style_engine_render(\"foo\"); ?>", 
     61                        "_standard_midgard_style_engine_render(\"foo\");", 
    6262                        $this->engine->compile("<(foo)>")); 
    6363                $this->assertEquals( 
    64                         "123<?php _standard_midgard_style_engine_render(\"foo\"); ?>321", 
     64                        "echo \"123\";_standard_midgard_style_engine_render(\"foo\");echo \"321\";", 
    6565                        $this->engine->compile("123<(foo)>321")); 
    6666                $this->assertEquals( 
    67                         "<?php echo 1; ?>", 
     67                        "echo 1; ", 
    6868                        $this->engine->compile("<?php echo 1; ?>")); 
    6969                $this->assertEquals( 
    70                         "<?php echo \"<(foo)>\"; ?>", 
     70                        "echo \"<(foo)>\"; ", 
    7171                        $this->engine->compile("<?php echo \"<(foo)>\"; ?>")); 
    7272        } 
     
    7474    function try_render($element) { 
    7575        ob_start(); 
    76       $this->engine->render($element); 
     76              $this->engine->render($element); 
    7777        return ob_get_clean(); 
    7878    }