コード例 #1
0
ファイル: TemplateRenderer.php プロジェクト: garbetjie/tiny
 /**
  * Template constructor.
  *
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     $settings = $container->get('settings');
     $compiledPath = $settings['storagePath'] . DIRECTORY_SEPARATOR . 'views';
     $resolver = new EngineResolver();
     $resolver->register('blade', function () use($compiledPath, &$settings) {
         $bladeCompiler = new BladeCompiler(new Filesystem(), $compiledPath);
         // Add the @webroot directive.
         $bladeCompiler->directive('webroot', function ($expression) use(&$settings) {
             $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
             $path = rtrim($settings['webrootBasePath'], '/') . '/' . ltrim($segments[0], '/');
             $path = str_replace("'", "\\'", $path);
             return "<?= e('{$path}') ?>";
         });
         // Add the @route directive.
         $bladeCompiler->directive('route', function ($expression) use(&$settings) {
             $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
             $path = rtrim($settings['routeBasePath'], '/') . '/' . ltrim($segments[0], '/');
             $path = str_replace("'", "\\'", $path);
             return "<?= e('{$path}') ?>";
         });
         return new CompilerEngine($bladeCompiler);
     });
     $finder = new FileViewFinder(new Filesystem(), [$settings['templatePath']]);
     $factory = new ViewFactory($resolver, $finder, new Dispatcher());
     $this->factory = $factory;
     $this->container = $container;
 }
コード例 #2
0
ファイル: Blade.php プロジェクト: quenti77/easyhq
 /**
  * Add extra directives to the blade templating compiler.
  *
  * @param BladeCompiler $blade The compiler to extend
  *
  * @return void
  */
 public static function registerDirectives(BladeCompiler $blade)
 {
     $keywords = ["namespace", "use"];
     foreach ($keywords as $keyword) {
         $blade->directive($keyword, function ($parameter) use($keyword) {
             $parameter = trim($parameter, "()");
             return "<?php {$keyword} {$parameter} ?>";
         });
     }
     $assetify = function ($file, $type) {
         $file = trim($file, "()");
         if (in_array(substr($file, 0, 1), ["'", '"'], true)) {
             $file = trim($file, "'\"");
         } else {
             return "{{ {$file} }}";
         }
         if (substr($file, 0, 1) !== "/") {
             $file = "/{$type}/{$file}";
         }
         if (substr($file, (strlen($type) + 1) * -1) !== ".{$type}") {
             $file .= ".{$type}";
         }
         return $file;
     };
     $blade->directive("css", function ($parameter) use($assetify) {
         $file = $assetify($parameter, "css");
         return "<link rel='stylesheet' type='text/css' href='{$file}'>";
     });
     $blade->directive("js", function ($parameter) use($assetify) {
         $file = $assetify($parameter, "js");
         return "<script type='text/javascript' src='{$file}'></script>";
     });
 }
コード例 #3
0
ファイル: Loop.php プロジェクト: kenvunz/lucent
 public function extendTo(BladeCompiler $blade)
 {
     $blade->directive('wploop', $this->start());
     $blade->directive('wpempty', $this->ifempty());
     $blade->directive('endwploop', $this->end());
     $blade->directive('wpthe', $this->the());
 }
コード例 #4
0
ファイル: BladeExtension.php プロジェクト: windqyoung/utils
 public function register()
 {
     $this->app->instance(__CLASS__, $this);
     $this->app->alias(__CLASS__, $this->containerName);
     $this->blade->directive('include_layout', function ($expr) {
         return "<?php echo app('{$this->containerName}')->renderLayout{$expr} ?>";
     });
 }
コード例 #5
0
    /**
     * Add basic syntax highlighting.
     *
     * This just adds markup that is picked up by a javascript highlighting library.
     *
     * @param BladeCompiler $compiler
     */
    protected function allowHighlightTag(BladeCompiler $compiler)
    {
        $compiler->directive('highlight', function ($expression) {
            if (is_null($expression)) {
                $expression = "('php')";
            }
            return "<?php \$__env->startSection{$expression}; ?>";
        });
        $compiler->directive('endhighlight', function () {
            return <<<'HTML'
<?php $last = $__env->stopSection(); echo '<pre><code class="language-', $last, '">', trim($__env->yieldContent($last)), '</code></pre>'; ?>
HTML;
        });
    }
コード例 #6
0
 /**
  * Register.
  *
  * @param \Illuminate\View\Compilers\BladeCompiler $compiler
  *
  * @return void
  */
 public static function register(BladeCompiler $compiler)
 {
     $compiler->directive('money', function ($expression) {
         if (Str::startsWith($expression, '(')) {
             $expression = substr($expression, 1, -1);
         }
         return "<?php echo money({$expression}); ?>";
     });
     $compiler->directive('currency', function ($expression) {
         if (Str::startsWith($expression, '(')) {
             $expression = substr($expression, 1, -1);
         }
         return "<?php echo currency({$expression}); ?>";
     });
 }
コード例 #7
0
 /**
  * Register the custom Blade directive
  *
  * @param \Illuminate\View\Compilers\BladeCompiler $compiler
  */
 private function registerBladeDirective($compiler)
 {
     $compiler->directive('notifications', function () {
         $expression = 'Gloudemans\\Notify\\Notifications\\Notification';
         return "<?php echo app('{$expression}')->render(); ?>";
     });
 }
コード例 #8
0
ファイル: BladeExtending.php プロジェクト: im286er/windwalker
 /**
  * extend
  *
  * @param   BladeCompiler $blade
  * @param   string        $name
  * @param   callable      $closure
  *
  * @return  void
  */
 public static function extend(BladeCompiler $blade, $name, $closure)
 {
     // For 5.0 after
     if (is_callable(array($blade, 'directive'))) {
         $blade->directive($name, $closure);
         return;
     }
     // For 4.x before
     $blade->extend(function ($view, BladeCompiler $compiler) use($name, $closure) {
         $pattern = $compiler->createMatcher($name);
         return preg_replace_callback($pattern, function ($matches) use($closure) {
             if (empty($matches[2])) {
                 return $matches[0];
             }
             return $matches[1] . $closure($matches[2]);
         }, $view);
     });
     return;
 }
コード例 #9
0
ファイル: _ide_helper.php プロジェクト: satriashp/tour
 /**
  * Register a handler for custom directives.
  *
  * @param string $name
  * @param callable $handler
  * @return void 
  * @static 
  */
 public static function directive($name, $handler)
 {
     \Illuminate\View\Compilers\BladeCompiler::directive($name, $handler);
 }
コード例 #10
0
 /**
  * @shortcode
  *
  * @param BladeCompiler $compiler The blade compiler to extend
  */
 private function registerDoShortcode($compiler)
 {
     $compiler->directive('shortcode', function ($expression) {
         return "<?php do_shortcode(with{$expression}); ?>";
     });
 }
コード例 #11
0
ファイル: Plugins.php プロジェクト: caffeinated/plugins
 /**
  * Register Blade syntax for a specific plugin.
  *
  * @param   string  $method
  * @return  void
  */
 protected function registerTag($method)
 {
     $this->blade->directive($method, function ($expression) use($method) {
         return "Plugin::{$method}{$expression}";
     });
 }
コード例 #12
0
 /**
  * @wpend
  *
  * @param BladeCompiler $compiler The blade compiler to extend
  */
 private function registerEndLoop($compiler)
 {
     $compiler->directive('endwpquery', function ($expression) {
         return "<?php endif; wp_reset_postdata(); ?>";
     });
 }
コード例 #13
0
ファイル: Components.php プロジェクト: Dalvej/triweb
 /**
  * Register Blade syntax for a specific component.
  *
  * @param  string $method
  * @param  string $namespace
  * @return void
  */
 protected function registerTag($method, $namespace = '')
 {
     $this->blade->directive('component_' . $method, function ($view) use($method, $namespace) {
         return '<?php echo ' . $namespace . $method . "{$view}; ?>";
     });
 }
コード例 #14
0
ファイル: BladeUtils.php プロジェクト: krisawzm/critical-css
 /**
  * Register the `@criticalCss($uri)` Blade directive.
  *
  * @return void
  */
 public static function registerBladeDirective(BladeCompiler $blade)
 {
     $blade->directive('criticalCss', [static::class, 'parseBladeDirective']);
 }
コード例 #15
0
ファイル: bootstrap.php プロジェクト: garbetjie/tiny
}, 'template' => function (Container $container) {
    return new TemplateRenderer($container);
}, 'validator' => function (Container $container) {
    return new ValidationFactory($container['translator']);
}, 'translator' => function (Container $container) {
    return new Translator($container['settings']['locale']);
}, 'viewFactory' => function (Container $container) {
    $settings = $container->get('settings');
    $compiledPath = $settings['storagePath'] . DIRECTORY_SEPARATOR . 'views';
    $resolver = new EngineResolver();
    $resolver->register('blade', function () use($compiledPath, &$settings) {
        $bladeCompiler = new BladeCompiler(new Filesystem(), $compiledPath);
        // Add the @webroot directive.
        $bladeCompiler->directive('webroot', function ($expression) use(&$settings) {
            $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
            $path = rtrim($settings['webrootBasePath'], '/') . '/' . ltrim($segments[0], '/');
            $path = str_replace("'", "\\'", $path);
            return "<?= e('{$path}') ?>";
        });
        // Add the @route directive.
        $bladeCompiler->directive('route', function ($expression) use(&$settings) {
            $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
            $path = rtrim($settings['routeBasePath'], '/') . '/' . ltrim($segments[0], '/');
            $path = str_replace("'", "\\'", $path);
            return "<?= e('{$path}') ?>";
        });
        return new CompilerEngine($bladeCompiler);
    });
    $finder = new FileViewFinder(new Filesystem(), [$settings['templatePath']]);
    return new ViewFactory($resolver, $finder, new Dispatcher());
}];