Skip to content

Commit

Permalink
Merge pull request #49 from Talesoft/dev-master
Browse files Browse the repository at this point in the history
Fixed a major bug in imports and reworked configuration
  • Loading branch information
TorbenKoehn committed Jan 16, 2016
2 parents 80e1768 + 5be2418 commit 77dc417
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 129 deletions.
34 changes: 13 additions & 21 deletions Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Compiler.html
* @since File available since Release 1.0
*/
Expand All @@ -32,16 +32,16 @@
use Tale\Jade\Parser\Node;

/**
* Compiles an AST got from the parser to valid PHTML, HTML or XML.
* Compiles an AST got from the parser to valid P/X/HTML or P/XML
*
* You can control the output-style via the options
* passed to the constructor.
*
* Different output types are possible (Currently, XML and HTML)
* Different output types are possible (Currently, XML ,HTML and XHTML)
*
* The main entry point is the `compile` method
*
* The generated PHTML should be evaluated, the best method
* The generated PHTML/PXML should be evaluated, the best method
* is a simple include of a generated file
*
* Usage example:
Expand Down Expand Up @@ -91,12 +91,13 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Compiler.html
* @since File available since Release 1.0
*/
class Compiler
{
use Util\ConfigurableTrait;

/**
* The Mode for HTML.
Expand Down Expand Up @@ -125,13 +126,6 @@ class Compiler
*/
const MODE_XHTML = 2;

/**
* An array of options.
*
* @var array
*/
private $_options;

/**
* The lexer that is given to the parser.
*
Expand Down Expand Up @@ -263,7 +257,7 @@ class Compiler
public function __construct(array $options = null, Parser $parser = null, Lexer $lexer = null)
{

$this->_options = array_replace_recursive([
$this->defineOptions([
'pretty' => false,
'indentStyle' => Lexer::INDENT_SPACE,
'indentWidth' => 2,
Expand Down Expand Up @@ -336,7 +330,7 @@ public function __construct(array $options = null, Parser $parser = null, Lexer
'extensions' => ['.jd', '.jade'],
'parserOptions' => [],
'lexerOptions' => []
], $options ? $options : []);
], $options);

$this->_lexer = $lexer ? $lexer : new Lexer($this->_options['lexerOptions']);
$this->_parser = $parser ? $parser : new Parser($this->_options['parserOptions'], $this->_lexer);
Expand Down Expand Up @@ -531,7 +525,10 @@ public function compileFile($path)

if (!$fullPath)
throw new \Exception(
"File $path wasnt found in ".implode(', ', $this->_options['paths']).", Include path: ".get_include_path()
"File $path wasnt found in ".
implode(', ', $this->_options['paths']).
", Extensions: ".implode(', ', $this->_options['extensions']).
", Include path: ".get_include_path()
);

return $this->compile(file_get_contents($fullPath), $fullPath);
Expand Down Expand Up @@ -1003,7 +1000,7 @@ protected function handleImport(Node $node)
$ext = array_search($node->filter, $this->_options['filterMap']);
}

if (!empty($ext) && (!in_array($ext, $this->_options['extensions']) || $node->filter)) {
if (!empty($ext) && (!in_array(".$ext", $this->_options['extensions']) || $node->filter)) {

if (!$node->filter && isset($this->_options['filterMap'][$ext]))
$node->filter = $this->_options['filterMap'][$ext];
Expand Down Expand Up @@ -1213,11 +1210,6 @@ protected function handleMixins(Node $node)
protected function handleMixin(Node $node)
{

//Find the absolute document root
$root = $node;
while ($root->parent)
$root = $root->parent;

//Detach
$node->parent->remove($node);

Expand Down
4 changes: 2 additions & 2 deletions Compiler/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Compiler.Exception.html
* @since File available since Release 1.0
*/
Expand All @@ -35,7 +35,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Compiler.Exception.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Filter.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -53,7 +53,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Filter.html
* @since File available since Release 1.0
*/
Expand Down
9 changes: 5 additions & 4 deletions Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Lexer.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -60,12 +60,13 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Lexer.html
* @since File available since Release 1.0
*/
class Lexer
{
use Util\ConfigurableTrait;

/**
* Tab Indentation (\t)
Expand Down Expand Up @@ -182,7 +183,7 @@ class Lexer
public function __construct(array $options = null)
{

$this->_options = array_replace([
$this->defineOptions([
'indentStyle' => null,
'indentWidth' => null,
'encoding' => mb_internal_encoding(),
Expand All @@ -203,7 +204,7 @@ public function __construct(array $options = null)
'textLine',
'text'
]
], $options ? $options : []);
], $options);

//Validate options
if (!in_array($this->_options['indentStyle'], [null, self::INDENT_TAB, self::INDENT_SPACE]))
Expand Down
4 changes: 2 additions & 2 deletions Lexer/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Lexer.Exception.html
* @since File available since Release 1.0
*/
Expand All @@ -34,7 +34,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Lexer.Exception.html
* @since File available since Release 1.0
*/
Expand Down
17 changes: 5 additions & 12 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Parser.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -57,19 +57,13 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Parser.html
* @since File available since Release 1.0
*/
class Parser
{

/**
* The options array used for this parser instance.
*
* @var array
*/
private $_options;
use Util\ConfigurableTrait;

/**
* The lexer used in this parser instance.
Expand Down Expand Up @@ -178,9 +172,8 @@ class Parser
public function __construct(array $options = null, Lexer $lexer = null)
{

$this->_options = array_replace([
'lexerOptions' => []
], $options ? $options : []);
$this->defineOptions(['lexerOptions' => $options], $options);

$this->_lexer = $lexer ? $lexer : new Lexer($this->_options['lexerOptions']);
}

Expand Down
4 changes: 2 additions & 2 deletions Parser/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Parser.Exception.html
* @since File available since Release 1.0
*/
Expand All @@ -34,7 +34,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Parser.Exception.html
* @since File available since Release 1.0
*/
Expand Down
6 changes: 3 additions & 3 deletions Parser/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Parser.Node.html
* @since File available since Release 1.0
*/
Expand All @@ -40,7 +40,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Parser.Node.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -462,7 +462,7 @@ public function dump($level = 0)
foreach ($this->children as $child)
$str .= $child->dump($level + 1);

return $str;
return trim($str);
}

/**
Expand Down
53 changes: 18 additions & 35 deletions Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/files/Renderer.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -51,19 +51,13 @@
* @author Talesoft <info@talesoft.io>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.4
* @version 1.3.5
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Renderer.html
* @since File available since Release 1.0
*/
class Renderer
{

/**
* The options-array for the renderer instance.
*
* @var array
*/
private $_options;
use Util\ConfigurableTrait;

/**
* The compiler that is used in this renderer instance.
Expand Down Expand Up @@ -125,46 +119,35 @@ public function __construct(
)
{

$this->_options = array_replace_recursive([
$this->defineOptions([
'adapter' => 'file',
'adapterOptions' => [],
'compilerOptions' => [],
'parserOptions' => [],
'lexerOptions' => [],

//Abstracted settings
'pretty' => false,
'paths' => [],
'standAlone' => false
], $options ? $options : []);
], $options);

//Quick Options.
//These get passed to the actual option arrays of the related objects
if (!isset($this->_options['compilerOptions']['paths']))
$this->_options['compilerOptions']['paths'] = $this->_options['paths'];

if (!isset($this->_options['compilerOptions']['pretty']))
$this->_options['compilerOptions']['pretty'] = $this->_options['pretty'];

if (!isset($this->_options['compilerOptions']['standAlone']))
$this->_options['compilerOptions']['standAlone'] = $this->_options['standAlone'];
$this->forwardOption('lifeTime', 'adapterOptions');
$this->forwardOption('cachePath', 'adapterOptions', 'path');

$this->forwardOption('paths', 'compilerOptions');
$this->forwardOption('pretty', 'compilerOptions');
$this->forwardOption('indentStyle', 'compilerOptions');
$this->forwardOption('indentWidth', 'compilerOptions');
$this->forwardOption('standAlone', 'compilerOptions');
$this->forwardOption('extensions', 'compilerOptions');
$this->forwardOption('mode', 'compilerOptions');
$this->forwardOption('doctypes', 'compilerOptions');
$this->forwardOption('filters', 'compilerOptions');
$this->forwardOption('filterMap', 'compilerOptions');

$this->_lexer = $lexer ? $lexer : new Lexer($this->_options['lexerOptions']);
$this->_parser = $parser ? $parser : new Parser($this->_options['parserOptions'], $lexer);
$this->_compiler = $compiler ? $compiler : new Compiler($this->_options['compilerOptions'], $parser);
}

/**
* Returns the current option-array used in this renderer instance.
*
* @return array
*/
public function getOptions()
{

return $this->_options;
}

/**
* Return the compiler instance used in this renderer instance.
*
Expand Down
Loading

0 comments on commit 77dc417

Please sign in to comment.