Theme Assets

Here we define the loaded assets from our previously defined
"dist" directory. Assets sources are located under the root "assets"
directory and are then compiled, thanks to Laravel Mix, to the "dist"
folder.

@see https://laravel-mix.com/
760236
public function register()
    {
        /** @var ThemeManager $theme */
        $theme = $this->app->make('wp.theme');

        Asset::add('theme_styles', 'css/theme.css', [], $theme->getHeader('version'))->to('front');
        Asset::add('theme_woo', 'css/woocommerce.css', ['theme_styles'], $theme->getHeader('version'))->to('front');
        Asset::add('theme_js', 'js/theme.min.js', [], $theme->getHeader('version'))->to('front');
    }
914543
protected function loadAssets()
    {
        $assets = $this->assetsObjectBackend->loadObject();
        if (!is_array($assets)) {
            $assets = array();
        }
        
        $this->assets = $assets;
    }
1269597
public function assetsinfoAllActivity():Renderer
    {
        /**
         * 0 : AppName
         * 1 : Have assets (1 ==> contains assets, 0 ==> not exist,  2 ==> Empty)
         * 3 : Perms on Dev
         * 4 : Perms on Prod
         * 5 : Status dev (0==> "Need to publish (redColor)", 1==> "OK (Green Color)")
         * 6 : Status prod (0==> "Need to publish (redColor)", 1==> "OK (Green Color)")
         * 7 : Action (Modal with url clear prod and dev , url publish prod and dev)
         */

        $appm = $this->getMaster("Apps");
        $apps = $appm->getAllApps();
        $diff = new Diff();
        $assetsapp = array();
        foreach ($apps as $app => $val) {
            $appname = $val->name;
            $app_assets = FEnv::get("framework.root") . "apps/" . ($appname) . "/Front/Resources/";
            $app_webassets_dev = FEnv::get("framework.root") . "public/components/apps/dev/" . strtolower($appname);
            $app_webassets_prod = FEnv::get("framework.root") . "public/components/apps/prod/" . strtolower($appname);

            $hassets = 0;
            $prod_hassets = 0;
            $dev_hassets = 0;

            if (is_dir($app_assets)) {
                $hassets++;
            }
            if (is_dir($app_webassets_dev)) {
                $dev_hassets++;
            }
            if (is_dir($app_webassets_prod)) {
                $prod_hassets++;
            }
            if ($hassets == 1 && $this->dirIsEmpty($app_assets)) {
                $hassets = 2;
            }


            $perm_dev =
                ($dev_hassets == 1)? substr(sprintf('%o', fileperms($app_webassets_dev)), -4) : 0000;
            $perm_prod =
                ($prod_hassets == 1)? substr(sprintf('%o', fileperms($app_webassets_prod)), -4) : 0000;

            $clear_dev = $this->generateRoute(
                "iumio_manager_assets_manager_clear",
                array("appname" => $appname, "env" => "dev"),
                null,
                true
            );
            $publish_dev = $this->generateRoute(
                "iumio_manager_assets_manager_publish",
                array("appname" => $appname, "env" => "dev"),
                null,
                true
            );
            ;
            $clear_prod = $this->generateRoute(
                "iumio_manager_assets_manager_clear",
                array("appname" => $appname, "env" => "prod"),
                null,
                true
            );
            ;
            $publish_prod = $this->generateRoute(
                "iumio_manager_assets_manager_publish",
                array("appname" => $appname, "env" => "prod"),
                null,
                true
            );

            $clear_all = $this->generateRoute(
                "iumio_manager_assets_manager_clear",
                array("appname" => $appname, "env" => "all"),
                null,
                true
            );
            ;
            $publish_all = $this->generateRoute(
                "iumio_manager_assets_manager_publish",
                array("appname" => $appname, "env" => "all"),
                null,
                true
            );

            $status_dev = 1;
            $status_prod = 1;


            if ($hassets == 1) {
                $webapp = ($this->recursiveScandir($app_assets));

                foreach ($webapp as $key => $value) {
                    $webapp[$key] = str_replace(FEnv::get("framework.root") . "apps/" . ($appname) .
                        "/Front/Resources/", "", $value);
                }
            }

            //// DEV ///

            if ($dev_hassets == 1 && $hassets == 1) {
                $webdev = ($this->recursiveScandir($app_webassets_dev));

                foreach ($webdev as $key => $value) {
                    $webdev[$key] = str_replace(FEnv::get("framework.root") . "public/components/apps/dev/" .
                        strtolower($appname), "", $value);
                }

                if (count(array_diff($webapp, $webdev)) > 0) {
                    $status_dev = 0;
                }

                if ($dev_hassets == 1 && $status_dev == 1 && $hassets == 1) {
                    for ($i = 0; $i < count($webapp); $i++) {
                        if (!file_exists(FEnv::get("framework.root") .
                            "public/components/apps/dev/" . strtolower($appname) .
                            "/" . $webdev[$i])) {
                            $status_dev = 0;
                            break;
                        }
                        $def = $diff::compareFiles(FEnv::get("framework.root") .
                            "public/components/apps/dev/" . strtolower($appname) .
                            "/" . $webdev[$i], FEnv::get("framework.root") .
                            "apps/" . ($appname) . "/Front/Resources/" . $webapp[$i]);
                        for ($u = 0; $u < count($def); $u++) {
                            if ($def[$u][1] > 0) {
                                $status_dev = 0;
                                break;
                            }
                        }
                        if ($status_dev == 0) {
                            break;
                        }
                    }
                }
            } else {
                $status_dev = 0;
            }

            /// END ///


            //// PROD ///

            if ($prod_hassets == 1 &&  $hassets == 1) {
                $webprod = ($this->recursiveScandir($app_webassets_prod));

                foreach ($webprod as $key => $value) {
                    $webprod[$key] = str_replace(FEnv::get("framework.root") .
                        "public/components/apps/prod/" . strtolower($appname), "", $value);
                }

                if (count(array_diff($webapp, $webprod)) > 0) {
                    $status_prod = 0;
                }

                if ($prod_hassets == 1 && $status_prod == 1) {
                    for ($i = 0; $i < count($webapp); $i++) {
                        if (!file_exists(FEnv::get("framework.root") . "public/components/apps/prod/" .
                            strtolower($appname) . "/" . $webprod[$i])) {
                            $status_dev = 0;
                            break;
                        }
                        $def = $diff::compareFiles(FEnv::get("framework.root") .
                            "public/components/apps/prod/" . strtolower($appname) .
                            "/" . $webprod[$i], FEnv::get("framework.root") . "apps/" .
                            ($appname) . "/Front/Resources/" . $webprod[$i]);
                        for ($u = 0; $u < count($def); $u++) {
                            if ($def[$u][1] > 0) {
                                $status_prod = 0;
                                break;
                            }
                        }
                        if ($status_prod == 0) {
                            break;
                        }
                    }
                }
            } else {
                $status_prod = 0;
            }

            /// END ///
            ///
            array_push(
                $assetsapp,
                array("name" => $appname,
                    "haveassets" => $hassets,
                    "dev_perms" => $perm_dev,
                    "prod_perms" => $perm_prod,
                    "status_dev" => $status_dev,
                    "status_prod" => $status_prod,
                    "clear" => array("dev" => $clear_dev, "prod" => $clear_prod, "all" => $clear_all),
                    "publish" => array("dev" => $publish_dev, "prod" => $publish_prod, "all" => $publish_all)
                )
            );
        }

        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK", "results" => $assetsapp)));
    }
28706
protected function _loadAssets()
    {
        $this->_View->Html->css('System./font-panel/fontpanel.css', ['block' => true]);
        $this->_View->Html->script('System./font-panel/fontpanel.js', ['block' => true]);
        $this->_View->Html->script('System./font-panel/font-panel-init.js', ['block' => true]);
    }
780471
public function getAssetDirectory()
    {
        $mergedFileDirectory = StaticContainer::get('path.tmp') . '/assets';

        if (!is_dir($mergedFileDirectory)) {
            Filesystem::mkdir($mergedFileDirectory);
        }

        if (!is_writable($mergedFileDirectory)) {
            throw new Exception("Directory " . $mergedFileDirectory . " has to be writable.");
        }

        return $mergedFileDirectory;
    }
386203
protected function _includeComponents(): void
    {
        // for now, we just include all components
        $appComponentFolder = WWW_ROOT . 'js/app/components/';
        $folder = new Folder($appComponentFolder);
        $files = $folder->find('.*\.js');
        if (!empty($files)) {
            foreach ($files as $file) {
                $this->_dependencies[] = 'app/components/' . $file;
            }
        }

        // Add Plugin Components
        foreach (Plugin::loaded() as $pluginName) {
            $pluginJsComponentsFolder = Plugin::path($pluginName) . '/webroot/js/app/components/';
            if (is_dir($pluginJsComponentsFolder)) {
                $folder = new Folder($pluginJsComponentsFolder);
                $files = $folder->find('.*\.js');
                foreach ($files as $file) {
                    $this->_dependencies[] = '/' . Inflector::underscore($pluginName) . '/js/app/components/' . $file;
                }
            }
        }
    }
245938
protected function registerAssetDispatcher()
    {
        $this->app->singleton('assets.dispatcher', function ($app)
        {
            $dispatcher = new AssetDispatcher($app);

            // Register the route for assets from main assets folder.
            $dispatcher->route('assets/(.*)', function (Request $request, $path) use ($dispatcher)
            {
                $basePath = $this->app['config']->get('routing.assets.path', base_path('assets'));

                $path = $basePath .DS .str_replace('/', DS, $path);

                return $dispatcher->serve($path, $request);
            });

            // Register the route for assets from Packages, Modules and Themes.
            $dispatcher->route('packages/([^/]+)/([^/]+)/(.*)', function (Request $request, $vendor, $package, $path) use ($dispatcher)
            {
                $namespace = $vendor .'/' .$package;

                if (is_null($packagePath = $dispatcher->getPackagePath($namespace))) {
                    return new Response('File Not Found', 404);
                }

                $path = $packagePath .str_replace('/', DS, $path);

                return $dispatcher->serve($path, $request);
            });

            // Register the route for assets from Vendor.
            $dispatcher->route('vendor/(.*)', function (Request $request, $path) use ($dispatcher)
            {
                $paths = $dispatcher->getVendorPaths();

                if (! Str::startsWith($path, $paths)) {
                    return new Response('File Not Found', 404);
                }

                $path = BASEPATH .'vendor' .DS .str_replace('/', DS, $path);

                return $dispatcher->serve($path, $request);
            });

            return $dispatcher;
        });
    }
1233411
protected function setupAssets()
    {
        $this->mergeConfigFrom($config = __DIR__ . '/config/datatables.php', 'datatables');

        if ($this->app->runningInConsole()) {
            $this->publishes([$config => config_path('datatables.php')], 'datatables');
        }
    }
196020
public function copyAssets()
    {
        // copy ASSETS
        //$source = $this->basePath . "resources" . $this->ds . "assets";
        //$this->copyFilesFromSource($source, resource_path("assets"));

        // copy WEBPACK.js
        $base = $source = $this->basePath . "resources" . $this->ds . "assets_setup" . $this->ds;
        $source = [
            $base . "webpack.mix.js",
            $base . "package.json",
            $base . "package-lock.json",
        ];
        $this->copyFilesFromSource($source, base_path(), false);
    }
175769
protected function _loadAssets()
    {
        if (Configure::read('CrudView.useAssetCompress')) {
            $this->AssetCompress->css('CrudView.crudview', ['block' => true]);
            $this->AssetCompress->script('CrudView.crudview_head', ['block' => 'headjs']);
            $this->AssetCompress->script('CrudView.crudview', ['block' => true]);

            return;
        }

        $config = Configure::read('CrudView');
        if (!$config) {
            return;
        }

        if (!empty($config['css'])) {
            $this->Html->css($config['css'], ['block' => true]);
        }

        if (!empty($config['js'])) {
            foreach ($config['js'] as $block => $scripts) {
                $this->Html->script($scripts, ['block' => $block]);
            }
        }
    }
1085554
public function setup_assets() {
		$suffix = $this->get_assets_suffix();

		if ( ! is_admin() ) {
			if ( ! empty( $this->jquery_uri ) ) {
				$this->update_jquery();
			}
			$remove_emoji_exists = array_key_exists( 'remove_emoji', $this->options );
			if ( ! $remove_emoji_exists ||
				( $remove_emoji_exists && $this->options['remove_emoji'] )
			) {
				$this->remove_emoji();
			}
		}

		// Load the JS files.
		if ( apply_filters( self::HOOK_PREFIX . 'include_js', true ) ) {
			$handle = sprintf( '%s-%s', $this->environment, 'js' );
			wp_register_script( $handle, str_replace( '.js', $suffix, $this->js_uri ) . '.js', [], $this->js_version, true );
			$localize_script = apply_filters( self::HOOK_PREFIX . 'localize_script', 'lean_localize_js' );
			$localize_data = apply_filters( self::HOOK_PREFIX . 'localize_data', [] );
			wp_localize_script( $handle, $localize_script, $localize_data );
			wp_enqueue_script( $handle );
		}

		// Load the CSS files.
		if ( apply_filters( self::HOOK_PREFIX . 'include_css', true ) ) {
			wp_enqueue_style(
				sprintf( '%s-%s', $this->environment, 'style' ),
				str_replace( '.css', $suffix, $this->css_uri ) . '.css',
				array(),
				$this->css_version,
				'all'
			);
		}

		if ( $this->load_comments ) {
			$this->load_comments_assets();
		}
	}
69234
public static function process($assets)
    {
        if ($directory = self::getOutputDirectory()) {
            $relativeDirectory = self::getRelativeOutputDirectory();
            $filename = '';
            $sourceFiles = array();
            for ($i = 0; $i < count($assets); ++$i) {
                $asset = $assets[$i];
                $filename .= $asset->getAssetHashKey();
                $sourceFiles[] = $asset->getAssetURL();
            }
            $filename = sha1($filename);
            $cacheFile = $directory.'/'.$filename.'.js';
            if (!file_exists($cacheFile)) {
                $js = '';
                foreach ($assets as $asset) {
                    $contents = $asset->getAssetContents();
                    if (isset($contents)) {
                        if ($asset->assetSupportsMinification()) {
                            $contents = \JShrink\Minifier::minify($contents);
                        }
                        $js .= $contents.";\n\n";
                    }
                }
                @file_put_contents($cacheFile, $js);
            }

            $asset = new self();
            $asset->setAssetURL($relativeDirectory.'/'.$filename.'.js');
            $asset->setAssetPath($directory.'/'.$filename.'.js');
            $asset->setCombinedAssetSourceFiles($sourceFiles);

            return array($asset);
        }

        return $assets;
    }
146217
private function addAssets(): void
    {
        $GLOBALS['TL_CSS'][] = Debug::uncompressedFile('bundles/codefogtags/selectize.min.css');
        $GLOBALS['TL_CSS'][] = Debug::uncompressedFile('bundles/codefogtags/backend.min.css');

        if (!\in_array('assets/jquery/js/jquery.min.js', (array) $GLOBALS['TL_JAVASCRIPT'], true)
            && !\in_array('assets/jquery/js/jquery.js', (array) $GLOBALS['TL_JAVASCRIPT'], true)
        ) {
            $GLOBALS['TL_JAVASCRIPT'][] = Debug::uncompressedFile('assets/jquery/js/jquery.min.js');
        }

        $GLOBALS['TL_JAVASCRIPT'][] = Debug::uncompressedFile('bundles/codefogtags/selectize.min.js');
        $GLOBALS['TL_JAVASCRIPT'][] = Debug::uncompressedFile('bundles/codefogtags/widget.min.js');
        $GLOBALS['TL_JAVASCRIPT'][] = Debug::uncompressedFile('bundles/codefogtags/backend.min.js');
    }
132691
public function publishScssFiles()
    {
        $from = base_path('Modules/'.$this->module.'/resources/scss/public');
        $to = resource_path('scss/public');
        $this->publishDirectory($from, $to);
    }
472786
public static function assets($innerPath = '')
    {
        $path = 'assets';

        if (!empty($innerPath)) {
            $innerPath = untrailingslashit($innerPath);
            $path .= '/' . $innerPath;
        }

        return apply_filters('baobab/paths/assets', self::theme($path), $innerPath);
    }
360519
def in_theme_dir(*paths)
      return nil unless theme

      paths.reduce(theme.root) do |base, path|
        Jekyll.sanitized_path(base, path)
      end
    end
971875
public function getDestinationPath()
    {
        if ($this->repository->config('merge.published-assets')) {
            return $this->repository->assetPath('');
        }

        return $this->repository->assetPath($this->component->getLowerName());
    }