class HamlRenderer in Sassy 7
HamlRenderer class. Provides the most common version of each method. Child classs override methods to provide style specific rendering. @package PHamlP @subpackage Haml.renderers
Hierarchy
- class \HamlRenderer
Expanded class hierarchy of HamlRenderer
File
- phamlp/
haml/ renderers/ HamlRenderer.php, line 24
View source
class HamlRenderer {
/**#@+
* Output Styles
*/
const STYLE_COMPRESSED = 'compressed';
const STYLE_COMPACT = 'compact';
const STYLE_EXPANDED = 'expanded';
const STYLE_NESTED = 'nested';
/**#@-*/
const INDENT = ' ';
private $format;
private $attrWrapper;
private $minimizedAttributes;
/**
* Returns the renderer for the required render style.
* @param string render style
* @return HamlRenderer
*/
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);
}
// switch
}
public function __construct($options) {
foreach ($options as $name => $value) {
$this->{$name} = $value;
}
// foreach
}
/**
* Renders element attributes
*/
private function renderAttributes($attributes) {
$output = '';
foreach ($attributes as $name => $value) {
if (is_integer($name)) {
// attribute function
$output .= " {$value}";
}
elseif ($name == $value && in_array($name, $this->minimizedAttributes) && ($this->format === 'html4' || $this->format === 'html5')) {
$output .= " {$name}";
}
elseif (in_array($name, $this->minimizedAttributes)) {
// $value is a variable, isset is called to make sure E_NOTICE is not thrown
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;
}
/**
* Renders the opening tag of an element
*/
public function renderOpeningTag($node) {
$output = "<{$node->content}";
$output .= $this
->renderAttributes($node->attributes);
$output .= ($node->isSelfClosing ? ' /' : '') . '>';
return $output;
}
/**
* Renders the closing tag of an element
*/
public function renderClosingTag($node) {
return $node->isSelfClosing ? '' : "</{$node->content}>";
}
/**
* Renders the opening of a comment
*/
public function renderOpenComment($node) {
return ($node->isConditional ? "\n\n" : '') . "<!--{$node->content}" . ($node->isConditional ? ">\n" : ' ');
}
/**
* Renders the closing of a comment
*/
public function renderCloseComment($node) {
return ($node->isConditional ? "\n<![endif]" : ' ') . '-->' . ($node->isConditional ? "\n" : '');
}
/**
* Renders the start of a code block
*/
public function renderStartCodeBlock($node) {
return $this
->renderContent($node);
}
/**
* Renders the end of a code block
*/
public function renderEndCodeBlock($node) {
return '<?php }' . (!empty($node->doWhile) ? " {$node->doWhile}" : '') . ' ?>';
}
/**
* Renders content.
* @param HamlNode the node being rendered
* @return string the rendered content
*/
public function renderContent($node) {
return $node->content;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HamlRenderer:: |
private | property | ||
HamlRenderer:: |
private | property | ||
HamlRenderer:: |
private | property | ||
HamlRenderer:: |
public static | function | * Returns the renderer for the required render style. * | |
HamlRenderer:: |
constant | |||
HamlRenderer:: |
private | function | * Renders element attributes | |
HamlRenderer:: |
public | function | * Renders the closing of a comment | 2 |
HamlRenderer:: |
public | function | * Renders the closing tag of an element | 4 |
HamlRenderer:: |
public | function | * Renders content. * | 2 |
HamlRenderer:: |
public | function | * Renders the end of a code block | 2 |
HamlRenderer:: |
public | function | * Renders the opening of a comment | 2 |
HamlRenderer:: |
public | function | * Renders the opening tag of an element | 4 |
HamlRenderer:: |
public | function | * Renders the start of a code block | 2 |
HamlRenderer:: |
constant | |||
HamlRenderer:: |
constant | |||
HamlRenderer:: |
constant | |||
HamlRenderer:: |
constant | |||
HamlRenderer:: |
public | function |