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; } } }
/** * 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); }
public function testNestedNamed() { $hs = new Text('$($[prev] > next)', Text::TOKEN_CONTROL); $html = $hs->toHTML(); $php = $hs->toPHP(); $this->assertEquals("Hamle\\Scope::getName('prev')->hamleRel(1,array('next'=>array()),array(),0,0,0)", $php); }
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 . ' ?>'; }