HamlRenderer.php in Sassy 7
File
phamlp/haml/renderers/HamlRenderer.php
View source
<?php
require_once 'HamlCompressedRenderer.php';
require_once 'HamlCompactRenderer.php';
require_once 'HamlExpandedRenderer.php';
require_once 'HamlNestedRenderer.php';
class HamlRenderer {
const STYLE_COMPRESSED = 'compressed';
const STYLE_COMPACT = 'compact';
const STYLE_EXPANDED = 'expanded';
const STYLE_NESTED = 'nested';
const INDENT = ' ';
private $format;
private $attrWrapper;
private $minimizedAttributes;
public static function getRenderer($style, $options) {
switch ($style) {
case self::STYLE_COMPACT:
return new HamlCompactRenderer($options);
case self::STYLE_COMPRESSED:
return new HamlCompressedRenderer($options);
case self::STYLE_EXPANDED:
return new HamlExpandedRenderer($options);
case self::STYLE_NESTED:
return new HamlNestedRenderer($options);
}
}
public function __construct($options) {
foreach ($options as $name => $value) {
$this->{$name} = $value;
}
}
private function renderAttributes($attributes) {
$output = '';
foreach ($attributes as $name => $value) {
if (is_integer($name)) {
$output .= " {$value}";
}
elseif ($name == $value && in_array($name, $this->minimizedAttributes) && ($this->format === 'html4' || $this->format === 'html5')) {
$output .= " {$name}";
}
elseif (in_array($name, $this->minimizedAttributes)) {
if (preg_match("", trim($value))) {
$output .= "<" . "?php if(isset({$value}) && !empty({$value})): ?" . "> {$name}={$this->attrWrapper}<" . "?php echo {$value}; ?" . ">{$this->attrWrapper};<" . "?php endif; ?" . ">";
}
else {
$output .= "<" . "?php if({$value}): ?" . "> {$name}={$this->attrWrapper}<" . "?php echo {$value}; ?" . ">{$this->attrWrapper};<" . "?php endif; ?" . ">";
}
}
else {
$output .= " {$name}={$this->attrWrapper}{$value}{$this->attrWrapper}";
}
}
return $output;
}
public function renderOpeningTag($node) {
$output = "<{$node->content}";
$output .= $this
->renderAttributes($node->attributes);
$output .= ($node->isSelfClosing ? ' /' : '') . '>';
return $output;
}
public function renderClosingTag($node) {
return $node->isSelfClosing ? '' : "</{$node->content}>";
}
public function renderOpenComment($node) {
return ($node->isConditional ? "\n\n" : '') . "<!--{$node->content}" . ($node->isConditional ? ">\n" : ' ');
}
public function renderCloseComment($node) {
return ($node->isConditional ? "\n<![endif]" : ' ') . '-->' . ($node->isConditional ? "\n" : '');
}
public function renderStartCodeBlock($node) {
return $this
->renderContent($node);
}
public function renderEndCodeBlock($node) {
return '<?php }' . (!empty($node->doWhile) ? " {$node->doWhile}" : '') . ' ?>';
}
public function renderContent($node) {
return $node->content;
}
}
Classes
Name |
Description |
HamlRenderer |
HamlRenderer class.
Provides the most common version of each method. Child classs override
methods to provide style specific rendering.
@package PHamlP
@subpackage Haml.renderers |