twigView = new TwigView(); } /** * Set TwigView. * * @param TwigView $twigView TwigView instance. * * @return void */ public function setTwigview(TwigView $twigView) { $this->twigView = $twigView; } /** * Compile all templates. * * @return void */ // @codingStandardsIgnoreStart public function all() { $this->out('Compiling all templates'); foreach(Scanner::all() as $section => $templates) { $this->out('Compiling ' . $section . '\'s templates'); $this->walkIterator($templates); } } // @codingStandardsIgnoreEnd /** * Compile only this plugin. * * @param string $plugin Plugin name. * * @return void */ public function plugin($plugin) { $this->out('Compiling one ' . $plugin . '\'s templates'); $this->walkIterator(Scanner::plugin($plugin)); } /** * Only compile one file. * * @param string $fileName File to compile. * * @return void */ public function file($fileName) { $this->out('Compiling one template'); $this->compileTemplate($fileName); } /** * Walk over $iterator and compile all templates in it. * * @param mixed $iterator Iterator to walk over. * * @return void */ protected function walkIterator($iterator) { foreach ($iterator as $template) { $this->compileTemplate($template); } } /** * Compile a template. * * @param string $fileName Template to compile. * * @return void */ protected function compileTemplate($fileName) { try { $this-> twigView-> getTwig()-> loadTemplate($fileName); $this->out('' . $fileName . ''); } catch (\Exception $exception) { $this->out('' . $fileName . ''); $this->out('' . $exception->getMessage() . ''); } } /** * Set options for this console. * * @return \Cake\Console\ConsoleOptionParser */ // @codingStandardsIgnoreStart public function getOptionParser() { // @codingStandardsIgnoreEnd return parent::getOptionParser()->addSubcommand( 'all', [ 'short' => 'a', // @codingStandardsIgnoreStart 'help' => __('Searches and precompiles all twig templates it finds.') // @codingStandardsIgnoreEnd ] )->addSubcommand( 'plugin', [ 'short' => 'p', // @codingStandardsIgnoreStart 'help' => __('Searches and precompiles all twig templates for a specific plugin.') // @codingStandardsIgnoreEnd ] )->addSubcommand( 'file', [ 'short' => 'f', // @codingStandardsIgnoreStart 'help' => __('Precompile a specific file.') // @codingStandardsIgnoreEnd ] // @codingStandardsIgnoreStart )->setDescription(__('TwigView templates precompiler')); // @codingStandardsIgnoreEnd } }