Exemplo n.º 1
0
 /**
  * @inherit()
  */
 public function parse($resource)
 {
     $this->environment->setSourceFile($resource);
     $loader = new \Twig_Loader_Filesystem(array($this->environment->getSourceDirectory()));
     $resource = str_replace($this->environment->getSourceDirectory(), '', $resource);
     $twig = new TwigEnvironment($loader);
     $twig->addExtension(new Extension($this->environment));
     $content = $twig->render($resource, array('app' => $this->environment));
     return $content;
 }
Exemplo n.º 2
0
 /**
  * Will parse a given file, and will write it to output directory
  *
  * @param string $resource filename of source file
  * @param string $output directory of destination
  * @throws \Exception
  */
 public function parse($resource, $output)
 {
     printf('file %s' . PHP_EOL, $resource);
     $pathinfo = pathinfo($resource);
     $extension = $pathinfo['extension'];
     $this->environment->setSourceFile($resource);
     $parser = $this->configuration->getParserForFileExtension($extension);
     if (!$parser instanceof ParserInterface) {
         throw new \Exception('No parser found. Have you initialized any plugins?');
     }
     if ($parser instanceof HasEnvironmentInterface) {
         $parser->setEnvironment($this->environment);
     }
     $content = $parser->parse($resource);
     $output = $parser->getOutputFilename($output);
     file_put_contents($output, $content);
 }
Exemplo n.º 3
0
 /**
  * @inherit()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $compilerInput = realpath($input->getArgument('source'));
     $compilerOutput = realpath($input->getArgument('destination'));
     $output->writeln(sprintf('input:  %s', $compilerInput));
     $output->writeln(sprintf('output  %s', $compilerOutput));
     $output->writeln('');
     $environment = new Environment();
     $environment->setSourceDirectory($compilerInput);
     $environment->setTargetDirectory($compilerOutput);
     // @todo: it would be better, to have a configurable class here...
     $configuration = new Core();
     $configuration->initializePlugins();
     $compiler = new Compiler($environment, $configuration);
     $compiler->run();
     $output->writeln('');
     $output->writeln('');
 }
Exemplo n.º 4
0
 /**
  * will return current parsed page
  * @return string
  */
 public function getCurrentPage()
 {
     $givenRelativeFile = str_replace($this->environment->getSourceDirectory(), '', $this->environment->getSourceFile());
     return str_replace('.twig', '', $givenRelativeFile);
 }