PHamlP no sangra la salida
Frecuentes
Visto 309 equipos
2
He instalado haml-y-sass para Yii y todo funciona muy bien, excepto un detalle: la salida no está identificada.
Por ejemplo (tenga en cuenta que la sangría es tab
)
!!!
%html(xmlns="http://www.w3.org/1999/xhtml",xml:lang="en",lang="en")
%head
%title="title"
/head
%body
#main
#banner
banner
/banner
#menu
menu
/menu
#content
content
/content
#footer
footer
/footer
/body
/html
Salidas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
title
</title></head><!--head -->
<body>
<div id="main">
<div id="banner">
banner
</div><!--banner -->
<div id="menu">
menu
</div><!--menu -->
<div id="content">
content
</div><!--content -->
<div id="footer">
footer
</div><!--footer -->
</div></body><!--body -->
</html><!--html -->
La configuración de PHamlP establece que ugly=false
'viewRenderer'=>array(
'class'=>'ext.phamlp.Haml',
// delete options below in production
'ugly' => false,
'style' => 'nested',
'debug' => 0,
'cache' => false,
),
He visto eso otros usuarios También tengo este problema, pero no hay soluciones en ninguna parte.
1 Respuestas
3
En el archivo HamlNestedRenderer.php necesitas cambiar esto
private function getIndent($node) {
return str_repeat(' ', 2 * $node->line['indentLevel']);
}
a este
private function getIndent($node) {
return str_repeat(' ', 2 * $node->level);
}
Después de eso cambié un poco el código, porque todavía me parecía feo. Así que aquí está mi HamlNestedRenderer. Las líneas comentadas eran para probar, podrías borrarlas.
class HamlNestedRenderer extends HamlRenderer {
/**
* Renders the opening tag of an element
*/
public function renderOpeningTag($node) {
// set default
$rot = '<!--default -->';
// check whitespaceControl outer
if($node->whitespaceControl['outer'] == true){
if (stripos(parent::renderOpeningTag($node), "html") !== false) {
$rot = '';
}else{
$rot = "\n";
}
}else{
$rot = $this->getIndent($node);
};
// add indent
$rot .= $this->getIndent($node) ;
$rot .= parent::renderOpeningTag($node) ;
// check whitespaceControl inner
if($node->whitespaceControl['inner'] == true){
// $rot .= '<!-- ROT 1.3 -->';
}else{
// check if isSelfClosing
if($node->isSelfClosing == true && $node->whitespaceControl['outer'] == true){
// $rot .= '<!-- ROT 1.4 -->';
}else{
// $rot .= '<!-- ROT 1.5 -->';
}
};
// return var
return $rot;
}
/**
* Renders the closing tag of an element
*/
public function renderClosingTag($node) {
$rct = '<!-- default rct -->';
if($node->isSelfClosing){
$rct = '';
}else{
if($node->whitespaceControl['inner']){
$rct = '';
}else{
// $rct = '<!-- RCT 1.3 -->';
$rct = parent::renderClosingTag($node) ;
if($node->whitespaceControl['outer']){
$rct .= "\n" . substr($this->getIndent($node), 0, -2);
}else{
$rct .= "\n" ;
}
}
};
return $rct;
}
/**
* Renders content.
* @param HamlNode the node being rendered
* @return string the rendered content
*/
public function renderContent($node) {
return parent::renderContent($node);
}
/**
* Renders the opening of a comment
*/
public function renderOpenComment($node) {
return parent::renderOpenComment($node) . (empty($node->content) ? "\n" : '');
}
/**
* Renders the closing of a comment
*/
public function renderCloseComment($node) {
return parent::renderCloseComment($node) . "\n";
}
/**
* Renders the start of a code block
*/
public function renderStartCodeBlock($node) {
return $this->getIndent($node) . parent::renderStartCodeBlock($node) . "\n";
}
/**
* Renders the end of a code block
*/
public function renderEndCodeBlock($node) {
return $this->getIndent($node) . parent::renderEndCodeBlock($node) . "\n";
}
private function getIndent($node) {
return str_repeat(' ', 2 * $node->level);
}
}
Respondido el 23 de diciembre de 12 a las 15:12
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php web-applications yii haml yii-extensions or haz tu propia pregunta.
Personalmente no recomiendo esta extensión, la parte SASS funciona bien. aún así es mejor usar simplemente 'sass watch', el problema realmente está en la parte HAML, usa algunas expresiones regulares que no coincidirán con todos los casos reales, es un puerto incompleto. si quieres un motor de plantillas php, puedo recomendar twig: ramita.sensiolabs.org solo MHO - Asgaroth
Es posible que el módulo en sí no funcione, por lo que, a menos que corrija el código central, no hay nada que cambiar en las variables: random