+ Moved variables resolution in the compiler Parser. (Temp. solution until the new...
[haanga.git] / lib / Haanga / Extension / Tag / Templatetag.php
blobcd0ebbcbcd12916a2a44563fea7ca8cbff7d20c5
1 <?php
3 class Haanga_Extension_Tag_Templatetag
5 static function generator($compiler, $args)
7 if (count($args) != 1) {
8 $compiler->Error("templatetag only needs one parameter");
11 if (Haanga_AST::is_var($args[0])) {
12 $type = $args[0]['var'];
13 if (!is_string($type)) {
14 $compiler->Error("Invalid parameter");
16 } else if (Haanga_AST::is_str($args[0])) {
17 $type = $args[0]['string'];
20 switch ($type)
22 case 'openblock':
23 $str = '{%';
24 break;
25 case 'closeblock':
26 $str = '%}';
27 break;
28 case 'openbrace':
29 $str = '{';
30 break;
31 case 'closebrace':
32 $str = '}';
33 break;
34 case 'openvariable':
35 $str = '{{';
36 break;
37 case 'closevariable':
38 $str = '}}';
39 break;
40 case 'opencomment':
41 $str = '{#';
42 break;
43 case 'closecomment':
44 $str = '#}';
45 break;
46 default:
47 $compiler->Error("Invalid parameter");
48 break;
51 $code = hcode();
52 $compiler->do_print($code, Haanga_AST::str($str));
54 return $code;