Example #1
0
 /**
  * Retrieve layout file from all module but just in current theme
  *
  * @return mixed
  */
 public function scanLayout()
 {
     $key = $this->getKey(['scan', 'all-layout', 'in', 'all-modules', 'but', 'only', 'in', 'current-theme']);
     if (is_null($this->getData($key))) {
         $pathModules = $this->module->getPath();
         $moduleDirectories = scandir($pathModules);
         foreach ($moduleDirectories as $moduleDir) {
             if (!in_array($moduleDir, [".", ".."])) {
                 /*Layouts path  của module hiện tại*/
                 $currentFolderLayoutsPathInModule = $pathModules . '/' . $moduleDir . '/themes/' . $this->izTheme->getCurrentThemeName() . '/layouts';
                 /*Check layouts path file exist*/
                 if (!file_exists($currentFolderLayoutsPathInModule)) {
                     continue;
                 }
                 $layoutFiles = scandir($currentFolderLayoutsPathInModule);
                 foreach ($layoutFiles as $layoutFile) {
                     if (!in_array($layoutFile, [".", ".."])) {
                         if (pathinfo($layoutFile, PATHINFO_EXTENSION) !== 'php') {
                             continue;
                         }
                         $layoutFileNameWithoutExt = preg_replace('/(\\.blade\\.php)$/', '', $layoutFile);
                         $this->_layouts[] = $layoutFileNameWithoutExt;
                     }
                 }
             }
         }
         $this->setData($key, $this->_layouts);
     }
     return $this->getData($key);
 }
 /**
  * Inject view and asset from another modules
  *
  * @return \Illuminate\Http\Response
  * @throws \Exception
  *
  */
 public function renderHtml()
 {
     $path = str_replace("/", "_", $this->request->path());
     // get addition assets from another modules
     $this->izAsset->setTheme($this->theme)->setCurrentPath($path)->initAssets($this->theme);
     // merger view data from another modules
     $this->izView->setLayout($this->theme->getLayoutName())->initAdditionViews($this->_viewData, $path);
     // merge theme data from another modules
     $this->izTheme->initViewData($this->theme, $path);
     // get view name
     if (is_null($this->getViewFile())) {
         $viewFile = debug_backtrace()[1]['function'];
         $this->setViewFile(str_replace('/', '.', $this->request->path()) . '.' . $viewFile);
     }
     return $this->theme->scopeWithLayout($this->getViewFile(), $this->_viewData)->render();
 }
Example #3
0
 /**
  * Chuyển tất cả các assets về dạng node để resolve dependency
  *
  * @return $this
  * @throws \Exception
  */
 protected function processModuleAssetsToNode()
 {
     //init note
     foreach ($this->izTheme->getAssetsTree() as $assetName => $assetInfo) {
         $this->nodes[$assetName] = new Node($assetName);
     }
     //init dependency
     foreach ($this->izTheme->getAssetsTree() as $assetName => $assetInfo) {
         if (isset($assetInfo['dependency']) && is_array($assetInfo['dependency']) && count($assetInfo['dependency']) > 0) {
             foreach ($assetInfo['dependency'] as $dep) {
                 if (isset($this->nodes[$dep])) {
                     $this->nodes[$assetName]->addEdge($this->nodes[$dep]);
                 } else {
                     throw new \Exception("Not found dependency: " . $dep);
                 }
             }
         }
     }
     return $this;
 }
Example #4
0
 /**
  * Return collections view by current theme
  *
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public function getViewsCollectionByCurrentThemes()
 {
     $currentThemeName = $this->izTheme->getCurrentThemeName();
     return $this->viewModel->query()->where('theme_name', $currentThemeName)->get();
 }
Example #5
0
 /**
  * Call when render layout.
  * Merger additions assets, 'all' assets, current assets
  * Resolve dependency assets
  *
  * @param \Teepluss\Theme\Theme $theme
  *
  * @param null                  $currentPath
  *
  * @return $this
  * @throws \Exception
  */
 public function initAssets(Theme $theme = null, $currentPath = null)
 {
     if (is_null($theme)) {
         $theme = $this->getTheme();
     }
     if (is_null($currentPath)) {
         if ($this->currentPath) {
             $currentPath = $this->currentPath;
         } else {
             throw new \Exception("Not found current path");
         }
     }
     // Lấy thêm assets từ các modules khác
     $this->initAdditionAssets($currentPath);
     $assets = isset($this->assets[$currentPath]) ? $this->assets[$currentPath] : [];
     // Merge global asset
     $assets = $this->mergeGlobalAssets($assets);
     //Get All assets in modules, not just current assets in path because they are interdependent
     $moduleAssets = $this->izTheme->getAssetsTree();
     /*
      * TODO: Trả về thứ tự cài đặt của assets theo dependency
      */
     $assets = $this->izAssetDependency->processDependency($assets);
     /*
      * Add bower_components asset to theme
      */
     foreach ($assets as $asset) {
         if (isset($moduleAssets[$asset])) {
             if (isset($moduleAssets[$asset]['sources']['scripts'])) {
                 /*add script*/
                 foreach ($moduleAssets[$asset]['sources']['scripts'] as $k => $script) {
                     $theme->asset()->container('footer')->usePath($moduleAssets[$asset]['theme_name'])->add('script-' . $asset . '-' . $k, $script, []);
                 }
             }
             if (isset($moduleAssets[$asset]['sources']['styles'])) {
                 /*add style*/
                 foreach ($moduleAssets[$asset]['sources']['styles'] as $k => $style) {
                     $theme->asset()->usePath($moduleAssets[$asset]['theme_name'])->add('style-' . $asset . '-' . $k, $style, []);
                 }
             }
         } else {
             throw new \Exception('Not found asset: ' . $asset);
         }
     }
     // * --------------------------- Add custom asset to theme ---------------------------
     // From Provider
     if (isset($this->customAssets[$currentPath])) {
         foreach ($this->customAssets[$currentPath] as $customAssetName => $customAsset) {
             $theme->asset()->container('custom-assets')->usePath(isset($customAsset['theme_name']) ? $customAsset['theme_name'] : $this->theme->getThemeName())->add($customAssetName, $customAsset['source'], isset($customAsset['dependency']) ? $customAsset['dependency'] : []);
         }
     }
     // From XML
     $xml = $this->izXml->getXmlByPath($this->theme->getLayoutName());
     if (isset($xml['custom_assets'])) {
         foreach ($xml['custom_assets'] as $customAsset) {
             $theme->asset()->container('custom-assets')->usePath(isset($customAsset['theme_name']) ? $customAsset['theme_name'] : $this->theme->getThemeName())->add($customAsset['name'], $customAsset['source'], isset($customAsset['dependency']) ? explode(',', $customAsset['dependency']) : []);
         }
     }
     $xml = $this->izXml->getXmlByPath('all');
     if (isset($xml['custom_assets'])) {
         foreach ($xml['custom_assets'] as $customAsset) {
             $theme->asset()->container('custom-assets')->usePath(isset($customAsset['theme_name']) ? $customAsset['theme_name'] : $this->theme->getThemeName())->add($customAsset['name'], $customAsset['source'], isset($customAsset['dependency']) ? explode(',', $customAsset['dependency']) : []);
         }
     }
     return $this;
 }