We need a modular approach for the compiler to provide an easy way to add different compilers.
Path-resolving should be removed from the compiler, it should work with a simple node-tree and a Path-Resolver instance.
Maybe we should even split XML, XHTML and HTML into three compilers. Need input on that.
Something along these lines:
interface Tale\Jade\FileResolverInterface
{
public function getPaths();
public function pushPath($path);
public function popPath();
public function resolve($path, array $extensions);
}
interface Tale\Jade\FormatterInterface
{
public function getLevel();
public function getNewLine();
public function getIndentation();
public function createShortCode();
//etc.
}
//Maybe a writer?
interface Tale\Jade\WriterInterface
{
public function getFormatter();
public function writeNewLine();
public function writeIndentation();
public function writeShortCode();
//etc.
public function __toString();
}
interface Tale\Jade\CompilerInterface
{
public function getParser();
public function getFileResolver(),
public function getFormatter();
public function compile($input, $path = null);
public function compileFile($path);
public function compileNode(Tale\Jade\Parser\NodeInterface $node);
}
abstract class Tale\Jade\CompilerBase implements Tale\ConfigurableInterface
{
use Tale\ConfigurableTrait;
public function __construct(array $options, Tale\Jade\Parser $parser, Tale\Jade\FileResolverInterface $resolver, Tale\Jade\FormatterInterface $formatter [or] Tale\Jade\WriterInterface $writer (containing the Formatter))
}
# Repository: talesoft/tale-jade
class Tale\Jade\Compiler\Xml extends Tale\Jade\CompilerBase {}
class Tale\Jade\Compiler\Xhtml extends Tale\Jade\Compiler\XmlCompiler {}
class Tale\Jade\Compiler\Html extends Tale\Jade\Compiler\XhtmlCompiler {}
# Repository: talesoft/tale-jade-twig-compiler
class Tale\Jade\Compiler\TwigCompiler
We need a modular approach for the compiler to provide an easy way to add different compilers. Path-resolving should be removed from the compiler, it should work with a simple node-tree and a Path-Resolver instance.
Maybe we should even split XML, XHTML and HTML into three compilers. Need input on that.
Something along these lines: