From ee6af0dda5f54d1fdc4dcaf7ecff3ce156659e07 Mon Sep 17 00:00:00 2001 From: "stephen@cubedesigners.com" Date: Fri, 2 Jun 2017 15:57:19 +0000 Subject: [PATCH] Adapt VideoJS module to work with new server side LESS compilation. WIP #897 @2.5 --- .../html5video/class.ws.html5.compiler.php | 58 ++++++++++++++----- .../html5/html5video/class.ws.html5.links.php | 2 +- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/inc/ws/Util/html5/html5video/class.ws.html5.compiler.php b/inc/ws/Util/html5/html5video/class.ws.html5.compiler.php index da2dd286d..a7ac6e215 100644 --- a/inc/ws/Util/html5/html5video/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/html5video/class.ws.html5.compiler.php @@ -87,6 +87,12 @@ class wsHTML5Compiler { 'js/libs/jquery/jquery.transit.js', 'js/widget.js' ); + + // Collection of LESS files to be compiled + // Filename with no extension, relative to the /style directory in the player build folder + public $lessFiles = ['fluidbook']; + public $lessFilesExtras = []; // Extra files that will be copied when compiling LESS (eg. used to allow video-js-core.css to be copied) + public $specialCSS = array(); public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'), 'android' => array('webintent')); @@ -442,14 +448,18 @@ class wsHTML5Compiler { } /** - * Helper function to add a unique stylesheet entry to the CSS stack + * Helper function to add a unique stylesheet entry to the LESS stack for compilation * Duplicate paths are ignored. - * @param $path + * @param $path The path of the file relative to the /style folder, without any extension + * @param $extra_files Optional array of extra files that should be copied across for use during LESS compilation */ - public function addCSS($path) { - if (!in_array($path, $this->pluginCSS)) { - $this->pluginCSS[] = $path; + public function addLess($path, $extra_files = []) { + if (!in_array($path, $this->lessFiles)) { + $this->lessFiles[] = $path; } + + // Make sure no duplicates are added here either + $this->lessFilesExtras = array_unique(array_merge($this->lessFilesExtras, $extra_files)); } protected function writeIndex($numCSS) { @@ -1318,12 +1328,11 @@ class wsHTML5Compiler { } protected function _writeLess($variables) { - $lessFiles = array('fluidbook'); if ($this->widget) { - $lessFiles[] = 'widget'; + $this->lessFiles[] = 'widget'; } foreach ($this->specialCSS as $s) { - $lessFiles[] = 'special/' . $s; + $this->lessFiles[] = 'special/' . $s; } $tmp = CubeIT_Files::tmpdir(); @@ -1335,15 +1344,38 @@ class wsHTML5Compiler { $bookVariables[] = '@' . $k . ':' . $v . ';'; } file_put_contents($tmp . '/book-variables.less', implode("\n", $bookVariables)); - foreach ($lessFiles as $f) { - copy($this->assets . '/style/' . $f . '.less', $tmp . '/' . $f . '.less'); + + // Also copy any "extra" files that might be needed by LESS compilation + // (eg. video-js-core.css is needed by videojs.less) + foreach ($this->lessFilesExtras as $extra) { + $destination_extra = $tmp . '/' . $extra; + if (!is_dir(dirname($destination_extra))) mkdir(dirname($destination_extra)); + copy($this->assets . '/style/' . $extra, $destination_extra); + } + + foreach ($this->lessFiles as $f) { + + $source_less = $this->assets . '/style/' . $f . '.less'; + $destination_less = $tmp . '/' . $f . '.less'; + $destination_css = 'style/' . $f . '.css'; + + if (!file_exists($source_less)) continue; + + // LESS file might be in a subfolder, so create if it doesn't exist + if (!is_dir(dirname($destination_less))) mkdir(dirname($destination_less)); + // Generated CSS file might be in a subfolder, so create if it doesn't exist + if (!is_dir(dirname($this->vdir . '/' . $f . '.css'))) mkdir(dirname($this->vdir . '/' . $f . '.css')); + + // Less files must be copied to temporary directory so they'll + // have access to the variables generated in book-variables.less + copy($source_less, $destination_less); $less = new CubeIT_CommandLine('lessc'); $less->setArg('plugin', 'less-plugin-clean-css'); - $less->setArg(null, $tmp . '/' . $f . '.less'); - $less->setArg(null, $this->vdir . '/style/' . $f . '.css'); + $less->setArg(null, $destination_less); + $less->setArg(null, $this->vdir . '/' . $destination_css); $less->execute(); if ($f != 'widget') { - $this->stylesheets[] = 'style/' . $f . '.css'; + $this->stylesheets[] = $destination_css; } } } diff --git a/inc/ws/Util/html5/html5video/class.ws.html5.links.php b/inc/ws/Util/html5/html5video/class.ws.html5.links.php index 5a88bf41e..d87aaa6ac 100644 --- a/inc/ws/Util/html5/html5video/class.ws.html5.links.php +++ b/inc/ws/Util/html5/html5video/class.ws.html5.links.php @@ -509,7 +509,7 @@ class videoLink extends wsHTML5Link { public static function addVideoJS($compiler) { $compiler->addJs('js/libs/videojs/video.js'); - $compiler->addCSS('style/videojs/videojs.css'); + $compiler->addLess('videojs/videojs', ['videojs/video-js-core.css']); } public function getClasses() { -- 2.39.5