]> _ Git - cubeextranet.git/commitdiff
Adapt VideoJS module to work with new server side LESS compilation. WIP #897 @2.5
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 2 Jun 2017 15:57:19 +0000 (15:57 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 2 Jun 2017 15:57:19 +0000 (15:57 +0000)
inc/ws/Util/html5/html5video/class.ws.html5.compiler.php
inc/ws/Util/html5/html5video/class.ws.html5.links.php

index da2dd286de5c7082be06a4a3b0f166437a8d4ae5..a7ac6e21572a8c9a7027bee520e22f0576c30aa5 100644 (file)
@@ -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;
                        }
                }
        }
index 5a88bf41e130b8b5ac33683ed6b2db5fc1a92630..d87aaa6ac1864d5ecd93ff60d586faee94c86bc3 100644 (file)
@@ -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() {