PRE; $t = new \ebi\Template(); $t->vars("abc", array(array(array("A", "B")), array(array("C", "D")))); $t->vars("xyz", array(1, 2)); eq($result, $t->get($src)); #nest_table $src = '<table rt:param="object_list" rt:var="obj"><tr><td><table rt:param="obj" rt:var="o"><tr><td>{$o}</td></tr></table></td></tr></table>'; $t = new \ebi\Template(); $t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3"))); eq('<table><tr><td><table><tr><td>A1</td></tr><tr><td>A2</td></tr><tr><td>A3</td></tr></table></td></tr><tr><td><table><tr><td>B1</td></tr><tr><td>B2</td></tr><tr><td>B3</td></tr></table></td></tr></table>', $t->get($src)); #nest_ul $src = '<ul rt:param="object_list" rt:var="obj"><li><ul rt:param="obj" rt:var="o"><li>{$o}</li></ul></li></ul>'; $t = new \ebi\Template(); $t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3"))); eq('<ul><li><ul><li>A1</li><li>A2</li><li>A3</li></ul></li><li><ul><li>B1</li><li>B2</li><li>B3</li></ul></li></ul>', $t->get($src)); #nest_ol $src = '<ol rt:param="object_list" rt:var="obj"><li><ol rt:param="obj" rt:var="o"><li>{$o}</li></ol></li></ol>'; $t = new \ebi\Template(); $t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3"))); eq('<ol><li><ol><li>A1</li><li>A2</li><li>A3</li></ol></li><li><ol><li>B1</li><li>B2</li><li>B3</li></ol></li></ol>', $t->get($src)); #nest_olul $src = '<ol rt:param="object_list" rt:var="obj"><li><ul rt:param="obj" rt:var="o"><li>{$o}</li></ul></li></ol>'; $t = new \ebi\Template(); $t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3"))); eq('<ol><li><ul><li>A1</li><li>A2</li><li>A3</li></ul></li><li><ul><li>B1</li><li>B2</li><li>B3</li></ul></li></ol>', $t->get($src)); #nest_tableul $src = '<table rt:param="object_list" rt:var="obj"><tr><td><ul rt:param="obj" rt:var="o"><li>{$o}</li></ul></td></tr></table>'; $t = new \ebi\Template(); $t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3"))); eq('<table><tr><td><ul><li>A1</li><li>A2</li><li>A3</li></ul></td></tr><tr><td><ul><li>B1</li><li>B2</li><li>B3</li></ul></td></tr></table>', $t->get($src));
<?php $t = new \ebi\Template(); $src = <<<'TEXT' <rt:loop param="abc" counter="loop_counter" key="loop_key" var="loop_var"> {$loop_counter}: {$loop_key} => {$loop_var} </rt:loop> hoge TEXT; $result = <<<'TEXT' 1: A => 456 2: B => 789 3: C => 010 4: D => 999 hoge TEXT; $t = new \ebi\Template(); $t->vars("abc", array("A" => "456", "B" => "789", "C" => "010", "D" => "999")); eq($result, $t->get($src));
$t->vars("abc", array(1)); eq($result, $t->get($src)); $src = '<rt:if param="abc">aa<rt:else />bb</rt:if>'; $result = 'bb'; $t = new \ebi\Template(); $t->vars("abc", []); eq($result, $t->get($src)); $src = '<rt:if param="abc">aa<rt:else />bb</rt:if>'; $result = 'aa'; $t = new \ebi\Template(); $t->vars("abc", true); eq($result, $t->get($src)); $src = '<rt:if param="abc">aa<rt:else />bb</rt:if>'; $result = 'bb'; $t = new \ebi\Template(); $t->vars("abc", false); eq($result, $t->get($src)); $src = '<rt:if param="abc">aa<rt:else />bb</rt:if>'; $result = 'aa'; $t = new \ebi\Template(); $t->vars("abc", "a"); eq($result, $t->get($src)); $src = '<rt:if param="abc">aa<rt:else />bb</rt:if>'; $result = 'bb'; $t = new \ebi\Template(); $t->vars("abc", ""); eq($result, $t->get($src)); $src = '<rt:if param="abc">aa<rt:else />bb</rt:if>'; $result = 'bb'; $t = new \ebi\Template(); eq($result, $t->get($src));
<input type="checkbox" name="bbb[]" value="hoge" checked="checked" />hoge <input type="checkbox" name="bbb[]" value="fuga" />fuga <input type="checkbox" name="eee[]" value="true" checked="checked" />foo <input type="checkbox" name="fff[]" value="false" checked="checked" />foo <input type="submit" /> <textarea name="aaa">hogehoge</textarea> <select name="ddd[]" size="5" multiple="multiple"> <option value="123">123</option> <option value="456" selected="selected">456</option> <option value="789" selected="selected">789</option> </select> <select name="XYZ"><option value="A">456</option><option value="B" selected="selected">789</option><option value="C">010</option></select> </form> PRE; $t = new \ebi\Template(); $t->vars("aaa_name", "aaa"); $t->vars("bbb_name", "bbb"); $t->vars("XYZ_name", "XYZ"); $t->vars("xyz_name", "xyz"); $t->vars("ddd_name", "ddd"); $t->vars("eee_name", "eee"); $t->vars("fff_name", "fff"); $t->vars("aaa", "hogehoge"); $t->vars("bbb", "hoge"); $t->vars("XYZ", "B"); $t->vars("xyz", array("A" => "456", "B" => "789", "C" => "010")); $t->vars("ddd", array("456", "789")); $t->vars("eee", true); $t->vars("fff", false); eq($result, $t->get($src));
<html> <body> \t<a href="{$link('abc/def.html')}">link</a> \t<img src="{$link('media/xyz.jpg')}" /> </body> </html> PRE; $result = <<<PRE <html> <body> \t<a href="http://localhost/resources/abc/def.html">link</a> \t<img src="http://localhost/resources/media/xyz.jpg" /> </body> </html> PRE; $t = new \ebi\Template(); $t->vars('link', $link); eq($result, $t->get($src)); $result_secure = <<<PRE <html> <body> \t<a href="http://localhost/resources/abc/def.html">link</a> \t<img src="http://localhost/resources/media/xyz.jpg" /> </body> </html> PRE; $t = new \ebi\Template(); $t->secure(true); $t->vars('link', $link); eq($result_secure, $t->get($src)); // httpsにはならない
<?php $t = new \ebi\Template(); $src = '<rt:loop param="abc" var="a"><rt:loop param="abc" var="b">{$a}{$b}</rt:loop>-</rt:loop>'; $result = '1112-2122-'; $t->vars('abc', array(1, 2)); eq($result, $t->get($src));
<?php $src = 'abc {$abc} def {$def} ghi {$ghi}'; $result = 'abc 123 def 456 ghi 789'; $t = new \ebi\Template(); $t->vars("abc", 123); $t->vars("def", 456); $t->vars("ghi", 789); eq($result, $t->get($src));
<form> <input type="search" name="search" value="hoge" /> <input type="tel" name="tel" value="000-000-0000" /> <input type="url" name="url" value="http://tokushimakazutaka.com" /> <input type="email" name="email" value="*****@*****.**" /> <input type="datetime" name="datetime" value="1970-01-01T00:00:00.0Z" /> <input type="datetime-local" name="datetime_local" value="1970-01-01T00:00:00.0Z" /> <input type="date" name="date" value="1970-01-01" /> <input type="month" name="month" value="1970-01" /> <input type="week" name="week" value="1970-W15" /> <input type="time" name="time" value="12:30" /> <input type="number" name="number" value="1234" /> <input type="range" name="range" value="7" /> <input type="color" name="color" value="#ff0000" /> </form> PRE; $t = new \ebi\Template(); $t->vars("search", "hoge"); $t->vars("tel", "000-000-0000"); $t->vars("url", "http://tokushimakazutaka.com"); $t->vars("email", "*****@*****.**"); $t->vars("datetime", "1970-01-01T00:00:00.0Z"); $t->vars("datetime_local", "1970-01-01T00:00:00.0Z"); $t->vars("date", "1970-01-01"); $t->vars("month", "1970-01"); $t->vars("week", "1970-W15"); $t->vars("time", "12:30"); $t->vars("number", "1234"); $t->vars("range", "7"); $t->vars("color", "#ff0000"); eq($rslt, $t->get($src));
<?php $t = new \ebi\Template('http://localhost/hoge/media'); $src = <<<'PRE' <script src="abc.js"></script> <script language="javascript"> var i = "{$abc}"; var img = "<img src='hoge.jpg' />"; </script> <img src='hoge.jpg' /> PRE; $result = <<<'PRE' <script src="http://localhost/hoge/media/abc.js"></script> <script language="javascript"> var i = "123"; var img = "<img src='hoge.jpg' />"; </script> <img src='http://localhost/hoge/media/hoge.jpg' /> PRE; $t->vars("abc", 123); eq($result, $t->get($src));
<select name="ddd" rt:param="abc"> </select> </form> PRE; $result = <<<'PRE' <form> <select name="ddd"><option value="123">123</option><option value="456" selected="selected">456</option><option value="789">789</option></select> </form> PRE; $t = new \ebi\Template(); $t->vars("abc", array(123 => 123, 456 => 456, 789 => 789)); $t->vars("ddd", "456"); eq($result, $t->get($src)); $src = <<<'PRE' <form rt:ref="true"> <rt:loop param="abc" var="v"> <input type="checkbox" name="ddd" value="{$v}" /> </rt:loop> </form> PRE; $result = <<<'PRE' <form> <input type="checkbox" name="ddd[]" value="123" /> <input type="checkbox" name="ddd[]" value="456" checked="checked" /> <input type="checkbox" name="ddd[]" value="789" /> </form> PRE; $t = new \ebi\Template(); $t->vars("abc", array(123 => 123, 456 => 456, 789 => 789)); $t->vars("ddd", "456"); eq($result, $t->get($src));