Exemple #1
0
 /**
  * Returns compiled filename
  * @param  string  $type
  * @return boolean
  */
 public static function getCompiledName($type)
 {
     $compiler = new Assets\Compiler(self::$collections[$type], $type, self::$cache_path);
     return $compiler->getCompiledName();
 }
Exemple #2
0
 /**
  * Includes given stylesheet in page, compiles less if neccessary
  *
  * @param String $filename Name of the stylesheet (css or less) to include
  *                         (relative to plugin directory)
  */
 protected function addStylesheet($filename)
 {
     if (substr($filename, -5) !== '.less') {
         $url = $this->getPluginURL() . '/' . $filename;
         PageLayout::addStylesheet($url);
         return;
     }
     // Create absolute path to less file
     $less_file = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . $this->getPluginPath() . '/' . $filename;
     // Fail if file does not exist
     if (!file_exists($less_file)) {
         throw new Exception('Could not locate LESS file "' . $filename . '"');
     }
     // Get plugin version from metadata
     $metadata = $this->getMetadata();
     $plugin_version = $metadata['version'];
     // Get plugin id (or parent plugin id if any)
     $plugin_id = $this->plugin_info['depends'] ?: $this->getPluginId();
     // Get asset file from storage
     $asset = Assets\Storage::getFactory()->createCSSFile($less_file, array('plugin_id' => $this->plugin_info['depends'] ?: $this->getPluginId(), 'plugin_version' => $metadata['version']));
     // Compile asset if neccessary
     if ($asset->isNew()) {
         $less = file_get_contents($less_file);
         $css = Assets\Compiler::compileLESS($less, array('plugin-path' => $this->getPluginURL()));
         $asset->setContent($css);
     }
     // Include asset in page by reference or directly
     $download_uri = $asset->getDownloadLink();
     if ($download_uri === false) {
         PageLayout::addStyle($asset->getContent());
     } else {
         PageLayout::addHeadElement('link', ['rel' => 'stylesheet', 'href' => $download_uri, 'type' => 'text/css']);
     }
 }