Esempio n. 1
0
 protected function setPropVal($props, $ch)
 {
     $token = Token::create($ch);
     foreach ($props as $prop => $value) {
         $token->setProp($prop, $value);
     }
     $res = $token->dump();
     return $res;
 }
Esempio n. 2
0
 protected function addToken($source)
 {
     $this->res[] = Token::create($source);
 }
Esempio n. 3
0
 protected function templateToEach(Token $token)
 {
     $children = $token->getChildren();
     $has_items = false;
     foreach ($children as $child) {
         if ($child->name == 'item') {
             $has_items = true;
             break;
         }
     }
     if (!$has_items) {
         return;
     }
     $with_each_token = new Token('with_each', 'double', array('select' => '$.items'));
     $with_each_token->setChildren($children);
     $token->clearChildren();
     $token->addChild($with_each_token);
 }
Esempio n. 4
0
 protected function makeCode(Token $tree, $class_name)
 {
     // Name of the class/template group
     $this->template_set_name = $tree->getProp('name');
     $this->is_aliased = $tree->getProp('is_aliased') == 'true';
     $this->collectTemplates($tree);
     //ob_start();
     $code = '';
     $code .= "<?php\n";
     $code .= 'class ' . $class_name . " extends \\Floxim\\Floxim\\Template\\Template {\n";
     $template_source_dirs = array();
     $registry = array();
     foreach ($this->templates as $meta) {
         if (isset($meta['file'])) {
             $template_source_dirs[] = dirname($meta['file']);
         }
         $code .= $this->makeTemplateCode($meta, $registry);
     }
     $template_source_dirs = array_unique($template_source_dirs);
     $action_map = array();
     $overrides = array();
     foreach ($registry as $t) {
         $id = $t['id'];
         if (!isset($action_map[$id])) {
             $action_map[$id] = $t['method'];
         } else {
             if (!is_array($action_map[$id])) {
                 $action_map[$id] = array($action_map[$id]);
             }
             $action_map[$id][] = $t['method'];
         }
         if (isset($t['overrides']) && !isset($overrides[$t['overrides']])) {
             $overrides[$t['overrides']] = array($t['id'], isset($t['is_variant']) && $t['is_variant'], isset($t['priority']) ? $t['priority'] : 0.5);
         }
     }
     $code .= 'protected static $templates = ' . var_export($registry, 1) . ";\n";
     $code .= 'protected static $action_map = ' . var_export($action_map, 1) . ";\n";
     $code .= 'protected static $template_source_dirs = ' . var_export($template_source_dirs, 1) . ";\n";
     if (isset($this->config_entries) && is_array($this->config_entries)) {
         $code .= 'protected static $template_config_entries = ' . var_export($this->config_entries, 1) . ";\n";
     }
     $code .= "public static function init() {\n";
     if (count($overrides) > 0) {
         $code .= "fx::listen('loadTemplate', function(\$e) {\n";
         $code .= "switch (\$e['full_name']) {\n";
         foreach ($overrides as $remote => $local_info) {
             list($local, $is_variant, $priority) = $local_info;
             $code .= "case '" . $remote . "':\n";
             if ($is_variant) {
                 $code .= "if ( (\$solved = " . $class_name . "::solve_" . $local . "(\$e['context'], \$e['tags']) ) ) {\n";
                 $code .= "\$e->pushResult(\$solved + array(2 => '" . $class_name . "'));\n";
                 $code .= "return;\n";
                 $code .= "}\n";
             } else {
                 $code .= "\$e->pushResult(array('tpl_" . $local . "', " . $priority . ", '" . $class_name . "'));\n";
                 $code .= "return;\n";
             }
             $code .= "break;\n";
         }
         $code .= "}\n";
         $code .= "});\n";
     }
     $code .= "}\n";
     $code .= "}";
     return $code;
 }