コード例 #1
0
 private function getFilter($compass = false)
 {
     $filter = new ScssphpFilter();
     if ($compass) {
         $filter->enableCompass();
     }
     return $filter;
 }
コード例 #2
0
 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  *
  * @param  Application $app
  * @throws \InvalidArgumentException
  */
 public function boot(Application $app)
 {
     $app['assetic.filters'] = $app->share($app->extend('assetic.filters', function ($filters) use($app) {
         $filters['scssphp'] = $app->share(function () use($app) {
             $filter = new ScssphpFilter();
             $filter->enableCompass($app['assetic.filter.scssphp.compass']);
             $filter->setImportPaths($app['assetic.filter.scssphp.import_paths']);
             $filter->setVariables($app['assetic.filter.scssphp.variables']);
             $filter->setFormatter($app['assetic.filter.scssphp.formatter']);
             return $filter;
         });
         return $filters;
     }));
 }
コード例 #3
0
 /**
  * Register the Assetic provider
  */
 private function registerAssetic()
 {
     $this->register(new SilexAssetic\AsseticServiceProvider(), array('assetic.options' => array('debug' => $this['debug'], 'auto_dump_assets' => $this['debug'])));
     $this['assetic.path_to_source'] = $this['root_dir'] . '/integration/public';
     $this['assetic.path_to_web'] = $this['root_dir'] . '/web';
     $this['assetic.filter_manager'] = $this->share($this->extend('assetic.filter_manager', function ($fm, $app) {
         $f = new Assetic\Filter\ScssphpFilter();
         $f->enableCompass();
         $fm->set('scssphp', $f);
         $fm->set('cssrewrite', new Assetic\Filter\CssRewriteFilter());
         $fm->set('lessphp', new Assetic\Filter\LessphpFilter());
         $fm->set('coffeephp', new CoffeephpFilter());
         return $fm;
     }));
 }
コード例 #4
0
ファイル: File.php プロジェクト: lalop/aphet
 /**
  * @param $path String target path
  * @return \Assetic\Filter\FileAsset
  */
 public function asset($opts = array())
 {
     $asset = new FileAsset($this->real_path);
     $ext = strtolower(substr($this->real_path, strrpos($this->real_path, '.')));
     if (in_array($ext, array('.css', '.scss'))) {
         //il faut rajouter la méthode asset-url
         $scss = new ScssphpFilter();
         if (isset($opts['compass']) && $opts['compass']) {
             $scss->enableCompass(true);
         }
         $scss->registerFunction('aphet_url', function ($args, $scss) {
             if ($args[0][0] === 'string') {
                 $url = is_array($args[0][2][0]) ? $args[0][2][0][2][0] : $args[0][2][0];
             } else {
                 throw new \Exception('je ne sais pas quoi faire là');
             }
             if (strpos($url, '?') !== false) {
                 list($url, $query) = explode('?', $url);
             } else {
                 $query = null;
             }
             if (strpos($url, '#') !== false) {
                 list($url, $hash) = explode('#', $url);
             } else {
                 $hash = null;
             }
             return 'url(' . aphet_url($url) . ($query ? "?{$query}" : '') . ($hash ? "?{$hash}" : '') . ')';
         });
         $asset->ensureFilter($scss);
     } elseif ($ext === '.js') {
         $filter = new \Assetic\Filter\CallablesFilter(function ($asset) {
             $asset->setContent(preg_replace_callback('/aphet_url\\((.*)\\)/', function ($match) {
                 return '\'' . aphet_url(json_decode($match[1])) . '\'';
             }, $asset->getContent()));
         });
         $asset->ensureFilter($filter);
     }
     return $asset;
 }