Changeset 9075 for trunk/src/sandbox
- Timestamp:
- 12/20/05 15:32:14 (3 years ago)
- Files:
-
- trunk/src/sandbox/mrfc0022/midgard_style_backend_test.php (modified) (1 diff)
- trunk/src/sandbox/mrfc0022/midgard_style_context_test.php (modified) (1 diff)
- trunk/src/sandbox/mrfc0022/midgard_style_engine.php (modified) (3 diffs)
- trunk/src/sandbox/mrfc0022/midgard_style_engine_test.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/sandbox/mrfc0022/midgard_style_backend_test.php
r9071 r9075 32 32 33 33 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); 36 36 } 37 37 trunk/src/sandbox/mrfc0022/midgard_style_context_test.php
r9071 r9075 57 57 58 58 function setUp() { 59 $this->context = new chained_midgard_style_context();59 $this->context =& new chained_midgard_style_context(); 60 60 $this->context->add_context( 61 61 new simple_midgard_style_context(array("foo" => "123"))); trunk/src/sandbox/mrfc0022/midgard_style_engine.php
r9071 r9075 50 50 51 51 function _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"]; 54 55 $template = $context->get_element($name); 55 56 $engine->render($template); … … 65 66 66 67 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 } 72 80 return $element; 73 81 } … … 98 106 99 107 function interpret($element) { 100 print "$element\n"; 101 eval("?>$element<?php"); 108 eval($element); 102 109 } 103 110 104 111 function render($element) { 105 112 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; 110 120 $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; 113 124 } 114 125 trunk/src/sandbox/mrfc0022/midgard_style_engine_test.php
r9071 r9075 32 32 function setUp() { 33 33 $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); 36 36 } 37 37 … … 41 41 42 42 function test_phpize() { 43 $this->assertEquals(" abc", $this->engine->phpize("abc"));43 $this->assertEquals("echo \"abc\";", $this->engine->phpize("abc")); 44 44 $this->assertEquals( 45 " <?php _standard_midgard_style_engine_render(\"foo\"); ?>",45 "_standard_midgard_style_engine_render(\"foo\");", 46 46 $this->engine->phpize("<(foo)>")); 47 47 $this->assertEquals( 48 " 123<?php _standard_midgard_style_engine_render(\"foo\"); ?>321",48 "echo \"123\";_standard_midgard_style_engine_render(\"foo\");echo \"321\";", 49 49 $this->engine->phpize("123<(foo)>321")); 50 50 $this->assertEquals( 51 " <?php echo 1; ?>",51 "echo \"<?php echo 1; ?>\";", 52 52 $this->engine->phpize("<?php echo 1; ?>")); 53 53 $this->assertEquals( 54 " <?php echo \"<?php _standard_midgard_style_engine_render(\"foo\"); ?>\"; ?>",54 "echo \"<?php echo \\\"\";_standard_midgard_style_engine_render(\"foo\");echo \"\\\"; ?>\";", 55 55 $this->engine->phpize("<?php echo \"<(foo)>\"; ?>")); 56 56 } 57 57 58 58 function test_compile() { 59 $this->assertEquals(" abc", $this->engine->compile("abc"));59 $this->assertEquals("echo \"abc\";", $this->engine->compile("abc")); 60 60 $this->assertEquals( 61 " <?php _standard_midgard_style_engine_render(\"foo\"); ?>",61 "_standard_midgard_style_engine_render(\"foo\");", 62 62 $this->engine->compile("<(foo)>")); 63 63 $this->assertEquals( 64 " 123<?php _standard_midgard_style_engine_render(\"foo\"); ?>321",64 "echo \"123\";_standard_midgard_style_engine_render(\"foo\");echo \"321\";", 65 65 $this->engine->compile("123<(foo)>321")); 66 66 $this->assertEquals( 67 " <?php echo 1; ?>",67 "echo 1; ", 68 68 $this->engine->compile("<?php echo 1; ?>")); 69 69 $this->assertEquals( 70 " <?php echo \"<(foo)>\"; ?>",70 "echo \"<(foo)>\"; ", 71 71 $this->engine->compile("<?php echo \"<(foo)>\"; ?>")); 72 72 } … … 74 74 function try_render($element) { 75 75 ob_start(); 76 $this->engine->render($element);76 $this->engine->render($element); 77 77 return ob_get_clean(); 78 78 }
