Arbit - project tracking

Dwoo

History

Diff

5fc482 e3eb1b a/CHANGELOG
5 5 {if $foo}> {$foo}{$bar}{/} - This also allow block operations such as:
6 6 {a http://url.com; "Text" /} which equals to {a http://url.com}Text{/}
7 7 + Syntax: Block plugins that you want to call without content can be
8 - self-closed just like XML tags (e.g. {a "http://url.com" /} )
8 + self-closed just like XML tags (e.g. {a "http://url.com" /} ). Be careful not
9 + to close a non-block plugin like that however, since it will close it's
10 + parent block
9 11 + Plugins: Added the {a} block plugin to generate <a> tags
10 12 + API: Added Dwoo_Plugin::paramsToAttributes() utility function to help
11 13 with the creation of compilable xml/html-related plugins
14 ++ Syntax: Static methods can be called using {Class::method()}
12 15 * Syntax: Math expressions in strings are now only allowed when the entire
13 16 expression is delimited, e.g. {"/$foo/$bar"} evaluates as just that while
14 17 {"/`$foo/$bar`"} will result in "/".($foo/$bar), therefore processing the /
5fc482 e3eb1b a/UPGRADE_NOTES
2 2 -----------------------------------------------------------------------------
3 --- 0.9.2
3 +-- Upgrading to Dwoo v0.9.2
4 4 -----------------------------------------------------------------------------
5 5
6 6 1. Block plugins
5fc482 e3eb1b a/lib/Dwoo/Compiler.php
1106 1106 } elseif ($first==='"' || $first==="'") {
1107 1107 // string
1108 1108 $out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer);
1109 - } elseif (preg_match('/^[a-z][a-z0-9_]*('.(is_array($parsingParams)||$curBlock!='root'?'':'\s+[^(]|').'\s*\(|\s*'.$this->rdr.'|\s*;)/i', $substr)) {
1109 + } elseif (preg_match('/^[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?('.(is_array($parsingParams)||$curBlock!='root'?'':'\s+[^(]|').'\s*\(|\s*'.$this->rdr.'|\s*;)/i', $substr)) {
1110 1110 // func
1111 1111 $out = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer);
1112 1112 } elseif ($first === ';') {
1179 1179 protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null)
1180 1180 {
1181 1181 $cmdstr = substr($in, $from, $to-$from);
1182 - preg_match('/^([a-z][a-z0-9_]*)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match);
1182 + preg_match('/^([a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match);
1183 +
1184 + if (empty($match[1])) {
1185 + throw new Dwoo_Compilation_Exception($this, 'Parse error, invalid function name');
1186 + }
1187 +
1188 + $func = $match[1];
1183 1189
1184 1190 if (!empty($match[2])) {
1185 1191 $cmdstr = $match[1];
1186 1192 }
1187 1193
1188 - if ($this->debug) echo 'FUNC FOUND<br />';
1194 + if ($this->debug) echo 'FUNC FOUND ('.$func.')<br />';
1189 1195
1190 1196 $paramsep = '';
1191 1197
1211 1217 $state = 0;
1212 1218
1213 1219 if ($paramspos === false) {
1214 - if (strpos($cmdstr, ' ')) {
1215 - $func = substr($cmdstr, 0, strpos($cmdstr, ' '));
1216 - } else {
1217 - $func = $cmdstr;
1218 - }
1219 1220 $params = array();
1220 1221
1221 1222 if ($curBlock !== 'root') {
1222 1223 return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1223 1224 }
1224 1225 } else {
1225 - $func = rtrim(substr($cmdstr, 0, $paramspos));
1226 1226 $whitespace = strlen(substr($cmdstr, strlen($func), $paramspos-strlen($func)));
1227 1227 $paramstr = substr($cmdstr, $paramspos+1);
1228 1228 if (substr($paramstr, -1, 1) === $paramsep) {
1301 1301 if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>';
1302 1302 }
1303 1303
1304 - if ($curBlock === 'method' || $func === 'do') {
1304 + if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) {
1305 1305 $pluginType = Dwoo::NATIVE_PLUGIN;
1306 1306 } else {
1307 1307 $pluginType = $this->getPluginType($func);
5fc482 e3eb1b a/tests/CompilerTests.php
528 528
529 529 $this->assertEquals('a <?php echo "foo"; ?>', $this->dwoo->get($tpl, array('foo'=>'a <?php echo "foo"; ?>'), $this->compiler));
530 530 }
531 +
532 + public function testStaticMethodCall()
533 + {
534 + $tpl = new Dwoo_Template_String('{upper MethodCallsHelper::staticFoo(bar "baz")}');
535 + $tpl->forceCompilation();
536 +
537 + $this->assertEquals('-BAZBAR-', $this->dwoo->get($tpl, array(), $this->compiler));
538 + }
531 539 }
532 540
533 541 class MethodCallsHelper {
552 560 return ($int+5).$str;
553 561 }
554 562 public function __toString() { return 'obj'; }
563 +
564 + public static function staticFoo($bar, $baz) {
565 + return "-$baz$bar-";
566 + }
555 567 }