我为Yii安装了haml-and-sass,除了一个细节之外,一切都很好:输出没有被认可。
例如(请注意缩进为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
输出
<!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 -->
PHamlP的配置指出ugly=false
'viewRenderer'=>array(
'class'=>'ext.phamlp.Haml',
// delete options below in production
'ugly' => false,
'style' => 'nested',
'debug' => 0,
'cache' => false,
),
我已经看到other users也遇到了这个问题但在任何地方都没有解决方案。
答案 0 :(得分:3)
在文件HamlNestedRenderer.php中,您需要更改此
private function getIndent($node) {
return str_repeat(' ', 2 * $node->line['indentLevel']);
}
到这个
private function getIndent($node) {
return str_repeat(' ', 2 * $node->level);
}
之后我改变了一下代码,因为我仍觉得它很难看。所以这是我的HamlNestedRenderer。评论的行用于测试,你可以删除它们。
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);
}
}