Beispiel #1
0
 protected function compile($less_fname, $css_fname)
 {
     self::load();
     $options = self::option('options');
     // generate source map
     if (self::option('sourse_map')) {
         $map_file = str_replace('styles/', '', $css_fname);
         $map_file = trim(str_replace('.less.css', '.map', $map_file), '/.');
         $map_dir = './styles/less-maps/';
         $map_path = "{$map_dir}{$map_file}";
         IO_FS::mkdir(dirname($map_path));
         $options = array_merge($options, array('sourceMap' => true, 'sourceMapWriteTo' => $map_path, 'sourceMapURL' => trim($map_path, '.')));
         // if is out of docroot
         if ($less_fname[0] == '/' || Core_Strings::starts_with($less_fname, '..') || Core_Strings::starts_with($less_fname, './..')) {
             $less_fname = "file://{$less_fname}";
             $less_fname = '.' . Templates_HTML::extern_filepath($less_fname);
         }
     }
     $options['import_dirs'] = self::option('less_import_dirs');
     $dir = dirname($css_fname);
     $url = 'http://' . WS::env()->request->host . '/';
     $args = array(array($less_fname => $url), $options);
     $css_file_name = Core::invoke(self::option('less_callback'), $args);
     $cached_file = rtrim($options['cache_dir'], '/') . '/' . $css_file_name;
     if (is_file($cached_file) && !(WS::env()->request['less_compile'] && self::option('debug'))) {
         $less_ftime = filemtime($cached_file);
         $css_ftime = false;
         if (IO_FS::exists($css_fname)) {
             $css_ftime = filemtime($css_fname);
         }
         if ($css_ftime && $css_ftime >= $less_ftime) {
             return false;
         }
     }
     $css = file_get_contents($cached_file);
     IO_FS::File($css_fname)->update($css);
 }
Beispiel #2
0
 /**
  * Возвращает URL для скачивания статического файла из каталога текущего компонента
  *
  */
 static function static_url($file, $component = false)
 {
     $path = self::component_static_path($file, $component);
     $url = Templates_HTML::extern_filepath($path);
     return $url;
     // OLD
     // if (!$component) $component = self::$current_component_name;
     // $path = self::component_dir($component)."/$file";
     // $m = IO_FS::exists($path)? filemtime($path) : "0";
     // return "/component-static/$component/$file/$m/";
 }