diff --git a/Lexer.php b/Lexer.php
index a4f581a..7bb5db6 100644
--- a/Lexer.php
+++ b/Lexer.php
@@ -864,33 +864,35 @@ protected function scanIndent()
$tabs = $this->strpos($indent, "\t") !== false;
$mixed = $spaces && $tabs;
- //Don't allow mixed indentation, this will just confuse the lexer
- if ($mixed || ($this->_indentStyle === self::INDENT_SPACE && $tabs)) {
-
- //Well, let's try a conversion if were using spaces and have an indentWidth already
- if ($this->_indentStyle === self::INDENT_SPACE && $this->_indentWidth !== null) {
-
- //We replace all tabs (\t) by indentWidth * spaces
- $spaces = str_replace("\t", str_repeat(self::INDENT_SPACE, $this->_indentWidth), $spaces);
- $tabs = false;
- $mixed = false;
- } else {
-
- $this->throwException(
- "Mixed indentation style encountered. "
- ."Dont mix tabs and spaces. Stick to one of both."
- );
+ if ($mixed) {
+
+ switch ($this->_indentStyle) {
+ case self::INDENT_SPACE:
+ default:
+
+ //Convert tabs to spaces based on indentWidth
+ $spaces = str_replace(self::INDENT_TAB, str_repeat(
+ self::INDENT_SPACE,
+ $this->_indentWidth ? $this->_indentWidth : 4
+ ), $spaces);
+ $tabs = false;
+ $mixed = false;
+ break;
+ case self::INDENT_TAB:
+
+ //Convert spaces to tabs
+ $spaces = str_replace(self::INDENT_SPACE, str_repeat(
+ self::INDENT_TAB,
+ $this->_indentWidth ? $this->_indentWidth : 1
+ ), $spaces);
+ $spaces = false;
+ $mixed = false;
+ break;
}
}
//Validate the indentation style
- $indentStyle = $tabs ? self::INDENT_TAB : self::INDENT_SPACE;
- if ($this->_indentStyle && $this->_indentStyle !== $indentStyle)
- $this->throwException(
- "Mixed indentation style encountered. "
- ."You used another indentation style in this line than in "
- ."previous lines. Dont do that."
- );
+ $this->_indentStyle = $tabs ? self::INDENT_TAB : self::INDENT_SPACE;
//Validate the indentation width
if (!$this->_indentWidth)
diff --git a/Test/IssueTest.php b/Test/IssueTest.php
index b408bb0..75bf90a 100644
--- a/Test/IssueTest.php
+++ b/Test/IssueTest.php
@@ -76,6 +76,22 @@ public function testIssue44()
doctype html
JADE;
+
+ $renderer = new Renderer([
+ 'adapterOptions' => [
+ 'path' => __DIR__.'/cache/issues'
+ ],
+ 'pretty' => false,
+ 'paths' => [__DIR__.'/views/issues']
+ ]);
+
+ $this->assertEquals('', $renderer->compile($jade));
+ $this->assertEquals('
=$view->Html->charset()?> ', $renderer->compileFile('issue-44'));
+
+ $this->assertEquals('- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
menu', $this->_renderer->compileFile('issue-44/for_members.ctp.1'));
+ $this->assertEquals('- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
menu', $this->_renderer->compileFile('issue-44/for_members.ctp.2'));
+
+
$renderer = new Renderer([
'adapterOptions' => [
'path' => __DIR__.'/cache/issues'
@@ -89,6 +105,9 @@ public function testIssue44()
]);
$this->assertEquals('', $renderer->compile($jade));
- $this->assertEquals('', $renderer->compileFile('issue-44'));
+ $this->assertEquals(' =$view->Html->charset()?> ', $renderer->compileFile('issue-44'));
+
+ $this->assertEquals('- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
menu', $this->_renderer->compileFile('issue-44/for_members.ctp.1'));
+ $this->assertEquals('- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
- =$view->Html->link(__(\'Dashboard\'), [\'controller\' => \'Users\', \'action\' => \'index\'])?>
- =$view->Html->link(__(\'Log Out\'), [\'controller\' => \'Users\', \'action\' => \'logout\'])?>
menu', $this->_renderer->compileFile('issue-44/for_members.ctp.2'));
}
}
\ No newline at end of file
diff --git a/Test/views/issues/issue-44.jade b/Test/views/issues/issue-44.jade
index 9430eaf..70e8197 100644
--- a/Test/views/issues/issue-44.jade
+++ b/Test/views/issues/issue-44.jade
@@ -4,4 +4,11 @@
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*/
-doctype html
\ No newline at end of file
+doctype html
+
+
+doctype html
+
+
+ != $view->Html->charset()
+
\ No newline at end of file
diff --git a/Test/views/issues/issue-44/default.ctp.jade b/Test/views/issues/issue-44/default.ctp.jade
new file mode 100644
index 0000000..733cc90
--- /dev/null
+++ b/Test/views/issues/issue-44/default.ctp.jade
@@ -0,0 +1,3 @@
+
+block nav-wrapper-content
+block next-to-header
\ No newline at end of file
diff --git a/Test/views/issues/issue-44/for_members.ctp.1.jade b/Test/views/issues/issue-44/for_members.ctp.1.jade
new file mode 100644
index 0000000..784c6e2
--- /dev/null
+++ b/Test/views/issues/issue-44/for_members.ctp.1.jade
@@ -0,0 +1,15 @@
+extends default.ctp.jade
+
+block nav-wrapper-content
+ ul.right.hide-on-med-and-down
+ li!= $view->Html->link(__('Dashboard'), ['controller' => 'Users', 'action' => 'index'])
+ li!= $view->Html->link(__('Log Out'), ['controller' => 'Users', 'action' => 'logout'])
+
+ ul#nav-mobile.side-nav
+ li!= $view->Html->link(__('Dashboard'), ['controller' => 'Users', 'action' => 'index'])
+ li!= $view->Html->link(__('Log Out'), ['controller' => 'Users', 'action' => 'logout'])
+ a.button-collapse(href="#" data-activates="nav-mobile"): i.material-icons menu
+
+block next-to-header
+ .progress(class='-main')
+ .indeterminate
\ No newline at end of file
diff --git a/Test/views/issues/issue-44/for_members.ctp.2.jade b/Test/views/issues/issue-44/for_members.ctp.2.jade
new file mode 100644
index 0000000..c84eb81
--- /dev/null
+++ b/Test/views/issues/issue-44/for_members.ctp.2.jade
@@ -0,0 +1,15 @@
+extends default.ctp.jade
+
+block nav-wrapper-content
+ ul.right.hide-on-med-and-down
+ li!= $view->Html->link(__('Dashboard'), ['controller' => 'Users', 'action' => 'index'])
+ li!= $view->Html->link(__('Log Out'), ['controller' => 'Users', 'action' => 'logout'])
+
+ ul#nav-mobile.side-nav
+ li!= $view->Html->link(__('Dashboard'), ['controller' => 'Users', 'action' => 'index'])
+ li!= $view->Html->link(__('Log Out'), ['controller' => 'Users', 'action' => 'logout'])
+ a.button-collapse(href="#" data-activates="nav-mobile"): i.material-icons menu
+
+block next-to-header
+ .progress(class='-main')
+ .indeterminate
\ No newline at end of file