Scaffolder v2.0.0
  • Namespace
  • Class

Namespaces

  • Scaffolder
    • Commands
    • Compilers
      • Core
        • Api
      • Layout
      • View

Classes

  • Scaffolder\Commands\BaseCommand
  • Scaffolder\Commands\ClearCacheCommand
  • Scaffolder\Commands\GeneratorCommand
  • Scaffolder\Commands\InitializeApiCommand
  • Scaffolder\Compilers\AbstractCompiler
  • Scaffolder\Compilers\AbstractCoreCompiler
  • Scaffolder\Compilers\AbstractViewCompiler
  • Scaffolder\Compilers\Core\Api\ApiControllerCompiler
  • Scaffolder\Compilers\Core\Api\ApiModelCompiler
  • Scaffolder\Compilers\Core\Api\ApiRouteCompiler
  • Scaffolder\Compilers\Core\ControllerCompiler
  • Scaffolder\Compilers\Core\MigrationCompiler
  • Scaffolder\Compilers\Core\ModelCompiler
  • Scaffolder\Compilers\Core\RouteCompiler
  • Scaffolder\Compilers\Layout\CreateLayoutCompiler
  • Scaffolder\Compilers\Layout\EditLayoutCompiler
  • Scaffolder\Compilers\Layout\PageLayoutCompiler
  • Scaffolder\Compilers\View\CreateViewCompiler
  • Scaffolder\Compilers\View\DashboardViewCompiler
  • Scaffolder\Compilers\View\EditViewCompiler
  • Scaffolder\Compilers\View\IndexViewCompiler
  • Scaffolder\Compilers\View\LoginViewCompiler
  • Scaffolder\Compilers\View\WelcomeViewCompiler
  • Scaffolder\ScaffolderServiceProvider
  1 <?php
  2 
  3 namespace Scaffolder\Compilers\Layout;
  4 
  5 use Illuminate\Support\Facades\File;
  6 use Scaffolder\Compilers\AbstractViewCompiler;
  7 use Scaffolder\Support\Contracts\ScaffolderThemeExtensionInterface;
  8 use Scaffolder\Support\FileToCompile;
  9 use Scaffolder\Support\PathParser;
 10 use stdClass;
 11 
 12 class PageLayoutCompiler extends AbstractViewCompiler
 13 {
 14     /**
 15      * Compiles the page layout.
 16      *
 17      * @param $stub
 18      * @param $modelName
 19      * @param $modelData
 20      * @param \stdClass $scaffolderConfig
 21      * @param $hash
 22      * @param \Scaffolder\Support\Contracts\ScaffolderThemeExtensionInterface $themeExtension
 23      * @param \Scaffolder\Support\Contracts\ScaffolderExtensionInterface[] $extensions
 24      * @param null $extra
 25      *
 26      * @return string
 27      */
 28     public function compile($stub, $modelName, $modelData, stdClass $scaffolderConfig, $hash, ScaffolderThemeExtensionInterface $themeExtension, array $extensions, $extra = null)
 29     {
 30         $this->stub = $stub;
 31 
 32         return $this->setPageTitle($scaffolderConfig)
 33             ->setAppName($scaffolderConfig)
 34             ->setLinks($extra['links'], $scaffolderConfig)
 35             ->replaceRoutePrefix($scaffolderConfig->routing->prefix)
 36             ->store($modelName, $scaffolderConfig, $themeExtension->runAfterPageLayoutIsCompiled($this->stub, $scaffolderConfig), new FileToCompile(null, null));
 37     }
 38 
 39     /**
 40      * Store the compiled stub.
 41      *
 42      * @param $modelName
 43      * @param \stdClass $scaffolderConfig
 44      * @param $compiled
 45      * @param \Scaffolder\Support\FileToCompile $fileToCompile
 46      *
 47      * @return string
 48      */
 49     protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
 50     {
 51         $path = PathParser::parse($scaffolderConfig->paths->views) . 'layouts/page.blade.php';
 52 
 53         File::put($path, $compiled);
 54 
 55         return $path;
 56     }
 57 
 58     /**
 59      * Replace the page title.
 60      *
 61      * @param \stdClass $scaffolderConfig
 62      *
 63      * @return $this
 64      */
 65     private function setPageTitle(stdClass $scaffolderConfig)
 66     {
 67         $this->stub = str_replace('{{page_title}}', $scaffolderConfig->userInterface->pageTitle, $this->stub);
 68 
 69         return $this;
 70     }
 71 
 72     /**
 73      * Replace the app name.
 74      *
 75      * @param \stdClass $scaffolderConfig
 76      *
 77      * @return $this
 78      */
 79     private function setAppName(stdClass $scaffolderConfig)
 80     {
 81         $this->stub = str_replace('{{app_name}}', $scaffolderConfig->name, $this->stub);
 82 
 83         return $this;
 84     }
 85 
 86     /**
 87      * Add links to the nav.
 88      *
 89      * @param $links
 90      * @param \stdClass $scaffolderConfig
 91      *
 92      * @return $this
 93      */
 94     private function setLinks($links, stdClass $scaffolderConfig)
 95     {
 96         $navLinks = '';
 97 
 98         foreach ($links as $link)
 99         {
100             $navLinks .= sprintf("
101             <li>
102                 <a href='/%s' class='waves-effect'>
103                     %s
104                 </a>
105             </li>", $scaffolderConfig->routing->prefix . '/' . strtolower($link['modelName']), $link['modelLabel']);
106         }
107 
108         $this->stub = str_replace('{{links}}', $navLinks, $this->stub);
109 
110         return $this;
111     }
112 
113     /**
114      * Replace the route prefix.
115      *
116      * @param $prefix
117      *
118      * @return $this
119      */
120     private function replaceRoutePrefix($prefix)
121     {
122         $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub);
123 
124         return $this;
125     }
126 }
127 
Scaffolder v2.0.0 API documentation generated by ApiGen