/** * If configuration is disabled, template helpers will not be available. * Note: The service provider should not be register before that test. */ public function testShouldNotCompileDefenderTemplateHelpers() { $this->app['config']->set('defender.template_helpers', false); $this->app->register('Artesaos\\Defender\\Providers\\DefenderServiceProvider'); $view = $this->stubsPath('views/defender.blade.txt'); $expected = $this->stubsPath('views/defender.blade.output.txt'); $compiled = Blade::compileString(file_get_contents($view)); $this->assertNotEmpty($compiled); $this->assertContains('@can', $compiled); $this->assertContains('@is', $compiled); $this->assertContains('@endcan', $compiled); $this->assertContains('@endis', $compiled); $this->assertStringNotEqualsFile($expected, $compiled); }
/** * @param $value * @param array $args * @return string * @throws Exception */ public function compile($value, array $args = []) { $generated = Blade::compileString($value); ob_start() and extract($args, EXTR_SKIP); // We'll include the view contents for parsing within a catcher // so we can avoid any WSOD errors. If an exception occurs we // will throw it out to the exception handler. try { eval('?>' . $generated); } catch (Exception $e) { ob_get_clean(); throw $e; } $content = ob_get_clean(); return $content; }
/** * Shortcut to include a partial view. * * @return string */ public function partial() { Blade::directive('partial', function ($expression) { return Blade::compileString("@include(partials.{$expression})"); }); }