Exemple #1
0
 function addContent($s, $strtype = H\Text::TOKEN_HTML)
 {
     if (trim($s)) {
         if ($this->escape) {
             $parse = new H\Text($s, $strtype);
             $this->content[] = $parse->toHTML();
         } else {
             $this->content[] = $s;
         }
     }
 }
Exemple #2
0
 function render($indent = 0, $doIndent = true)
 {
     $data = H\Text::varToCode(array("base" => $this->baseType, "type" => $this->type, "opt" => $this->opt, "source" => $this->source, "content" => $this->content));
     $out = "<?php " . $this->varname . "={$data}; echo Hamle\\Tag\\DynHtml::toStTag(" . $this->varname . ",\$form).";
     $out .= "implode(\"\\n\"," . $this->varname . "['content']).";
     $out .= "Hamle\\Tag\\DynHtml::toEnTag(" . $this->varname . ",\$form)?>\n";
     return $out;
 }
Exemple #3
0
 function toPHP()
 {
     if (is_numeric($this->scope)) {
         return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")";
     } else {
         return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")";
     }
 }
Exemple #4
0
 function renderStTag()
 {
     $out = "<" . "?php ";
     $scopeName = "";
     if (preg_match('/ as ([a-zA-Z]+)$/', $this->var, $m)) {
         $scopeName = $m[1];
         $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0]));
         $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL);
     } else {
         $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL);
     }
     switch ($this->type) {
         case "each":
             if ($this->var) {
                 $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n";
             } else {
                 $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n";
             }
             $out .= "Hamle\\Scope::add({$this->o}); ";
             break;
         case "if":
             $hsvcomp = new H\Text\Comparison($this->var);
             $out .= "if(" . $hsvcomp->toPHP() . ") {";
             break;
         case "with":
             if ($scopeName) {
                 $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"{$scopeName}\");\n;";
             } else {
                 $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . "{$this->o}->valid()) {\n";
                 $out .= "Hamle\\Scope::add({$this->o});\n;";
             }
             break;
         case "else":
             $out .= "/* else */";
             break;
         case "include":
             $file = $hsv->toHTML();
             if ($file[0] == "#") {
                 $out .= "echo Hamle\\Run::includeFragment(" . $hsv->toPHP() . ");";
             } else {
                 $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");";
             }
             break;
     }
     return $out . ' ?>';
 }
Exemple #5
0
 /**
  * Return as PHP Code
  * @return string
  */
 function toPHP()
 {
     $limit = Hamle\Text::varToCode($this->sortlimit['sort']) . "," . $this->sortlimit['limit'] . "," . $this->sortlimit['offset'] . "," . $this->grouptype['grouptype'];
     $sub = $this->sub ? "->" . $this->sub->toPHP() : "";
     return "hamleRel(" . $this->dir . "," . Hamle\Text::varToCode($this->filt['tag']) . ",{$limit}){$sub}";
 }
Exemple #6
0
 /**
  * Used to convert urlencoded string into html attributes
  *
  * @return string HTML Attributes
  */
 function optToTags()
 {
     $out = array();
     foreach ($this->opt as $k => $v) {
         if ($k == "class" && !$v) {
             continue;
         }
         if (is_array($v)) {
             $v = implode(" ", $v);
         }
         if (!$v instanceof H\Text) {
             $v = new H\Text($v);
         }
         $k = new H\Text($k);
         $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\"";
     }
     return implode("", $out);
 }
Exemple #7
0
 public function testDollarFuncVar1()
 {
     $hs = new Text('$(product.{$tags})', Text::TOKEN_CONTROL);
     $php = $hs->toPHP();
     $this->assertEquals("Hamle\\Run::modelTypeTags(array('product'=>array(0=>Hamle\\Scope::get()->hamleGet('tags'))),array(),0,0)", $php);
 }
Exemple #8
0
 function toPHPVar()
 {
     return "Hamle\\Scope::get()->hamleGet(" . Text::varToCode($this->var) . ")";
 }
Exemple #9
0
 function toPHP()
 {
     return '$form->getField(' . Text::varToCode($this->var) . ')->getValue()';
 }
Exemple #10
0
 /**
  * @return string PHP Code
  */
 function toPHP()
 {
     $sub = $this->sub ? "->" . $this->sub->toPHP() : "";
     if ($this->scope instanceof Scope) {
         return $this->scope->toPHP() . $sub;
     } elseif ($this->scope === true) {
         return "Hamle\\Scope::get(0){$sub}";
     }
     $limit = Text::varToCode($this->sortlimit['sort']) . "," . $this->sortlimit['limit'] . "," . $this->sortlimit['offset'];
     if (count($this->filt['tag'])) {
         return "Hamle\\Run::modelTypeTags(" . Text::varToCode($this->filt['tag']) . ",{$limit}){$sub}";
     }
     if (count($this->filt['id'])) {
         if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) {
             return "Hamle\\Run::modelId(" . Text::varToCode(current($this->filt['id']['*'])) . ",{$limit}){$sub}";
         } else {
             return "Hamle\\Run::modelTypeId(" . Text::varToCode($this->filt['id']) . ",{$limit}){$sub}";
         }
     }
     return "";
 }