/** * Execute the console command. * * @return void */ public function fire() { // Set directories $inputPath = base_path('resources/views'); $outputPath = storage_path('gettext'); // Create $outputPath or empty it if already exists if (File::isDirectory($outputPath)) { File::cleanDirectory($outputPath); } else { File::makeDirectory($outputPath); } // Configure BladeCompiler to use our own custom storage subfolder $compiler = new BladeCompiler(new Filesystem(), $outputPath); $compiled = 0; // Get all view files $allFiles = File::allFiles($inputPath); foreach ($allFiles as $f) { // Skip not blade templates $file = $f->getPathName(); if ('.blade.php' !== substr($file, -10)) { continue; } // Compile the view $compiler->compile($file); $compiled++; // Rename to human friendly $human = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($f->getRelativePathname(), DIRECTORY_SEPARATOR)); File::move($outputPath . DIRECTORY_SEPARATOR . sha1($file) . '.php', $outputPath . DIRECTORY_SEPARATOR . $human); } if ($compiled) { $this->info("{$compiled} files compiled."); } else { $this->error('No .blade.php files found in ' . $inputPath); } }
public function compile($path = null) { if (str_contains($path, 'vendor/')) { preg_match('~/vendor/\\w+/([^/]+)~', $path, $matches); preg_match('~/([^/]+)$~', $path, $matches2); $name = $matches[1] . '::' . $matches2[1]; } elseif (str_contains($path, 'resources/views/')) { $name = explode('resources/views/', $path)[1]; } else { $name = explode('/views/', $path)[1]; } $record = CoverageRecord::RecordEntry('View', '', $name); parent::compile($path); }
public function fire() { $app = app(); $cache = $app['path.storage'] . '/views'; $compiler = new BladeCompiler($app['files'], $cache); // delete compiled $files = new \GlobIterator(TEMP_PATH . '/views/*'); foreach ($files as $file) { if ($file->getExtension() !== '.gitignore') { unlink($file); } } // generate new ones $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(VIEWS_PATH), \RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { if ($file->getExtension() === 'blade') { $compiler->compile($file->getPathname()); } } }
/** * Compile the view at the given path. * * @param string $path * @return void * @static */ public static function compile($path = null) { \Illuminate\View\Compilers\BladeCompiler::compile($path); }