public function testCompassMixin() { $asset = new FileAsset(__DIR__ . '/fixtures/compass/compass.sass'); $asset->load(); $filter = new CompassFilter($_SERVER['COMPASS_BIN']); $filter->filterLoad($asset); $this->assertContains('text-decoration', $asset->getContent()); }
public function setFilters() { if (get_option('am_use_compass', 0) != 0) { //Defines compass filter instance and sprite images paths $compassInstance = new CompassFilter(get_option('am_compass_path', '/usr/bin/compass')); $compassInstance->setImagesDir(get_theme_root() . "/" . get_template() . "/images"); $compassInstance->setGeneratedImagesPath($this->manager->cache->getPath()); $compassInstance->setHttpGeneratedImagesPath(site_url() . str_replace(getcwd(), '', $this->manager->cache->getPath())); $this->setFilter('Compass', $compassInstance); $filter = 'Compass'; } else { $this->setFilter('Scssphp', new ScssphpFilter()); $filter = 'Scssphp'; } $this->setFilter('CssRewrite', new CssRewriteFilter()); }
/** * Takes all the SASS stylesheets and manages their queue to asseticize them */ public function generateSass() { if (empty($this->sass)) { return false; } $mtime = md5(implode('&', $this->mTimesSass) . implode('&', $this->sass)); //If SASS stylesheets have been updated -> compass compile if (!$this->cache->has("sass-{$mtime}.css")) { if (get_option('am_use_compass', 0) != 0) { //Defines compass filter instance and sprite images paths $compassInstance = new CompassFilter(get_option('am_compass_path', '/usr/bin/compass')); $compassInstance->setImagesDir(get_theme_root() . "/" . get_template() . "/images"); $compassInstance->setGeneratedImagesPath($this->assetsPath); $compassInstance->setHttpGeneratedImagesPath(site_url() . str_replace(getcwd(), '', $this->assetsPath)); $this->css->getFilterManager()->set('Compass', $compassInstance); $filter = 'Compass'; } else { $this->css->getFilterManager()->set('Scssphp', new ScssphpFilter()); $filter = 'Scssphp'; } //Saves the asseticized stylesheets $this->cache->set("sass-{$mtime}.css", $this->css->createAsset($this->sass, array($filter, 'CssRewrite'))->dump()); } //Adds SASS compiled stylesheet to normal css queue $this->styles['sass-am-generated'] = $this->assetsPath . "sass-{$mtime}.css"; $this->mTimesStyles['sass-am-generated'] = filemtime($this->styles['sass-am-generated']); }
protected function getFilterCompass() { $assetPath = $this->assetPath(); $cachePath = $this->cachePath(); $compass = new CompassFilter('/usr/local/bin/compass'); $compass->setHttpPath('/assets/'); $compass->setImagesDir($assetPath . '/img'); $compass->setHttpGeneratedImagesPath('img'); $compass->setGeneratedImagesPath($cachePath . '/img'); $compass->setJavascriptsDir($assetPath . '/js'); $compass->setHttpJavascriptsPath('assets/js'); $compass->setNoCache(true); $compass->setScss(true); return $compass; }
public function register(Application $app) { $app['assetic.options'] = []; /** * Asset Factory configuration happens here */ $app['assetic'] = $app->share(function () use($app) { $app['assetic.options'] = array_replace(array('debug' => false, 'formulae_cache_dir' => $app['paths.cache'] . '/assetic'), $app['assetic.options']); return $app['assetic.factory']; }); $app['paths.cache_assets'] = $app['paths.cache'] . '/assets'; /** * Asset manager * * @return \Assetic\AssetManager */ $app['assetic.asset_manager'] = $app->share(function () { return new AssetManager(); }); $app['assetic.filters.uglifyjs2'] = $app->share(function () { return new UglifyJs2Filter(); }); $app['assetic.filters.uglifycss'] = $app->share(function () { return new UglifyCssFilter(); }); $app['assetic.filters.compass'] = $app->share(function () use($app) { $filter = new CompassFilter(); $filter->setCacheLocation($app['paths.cache'] . '/compass'); $filter->addLoadPath($app['paths.sentient'] . '/Resource/scss'); return $filter; }); /** * Filter manager * * @return \Assetic\FilterManager */ $app['assetic.filter_manager'] = $app->share(function () use($app) { $manager = new FilterManager(); $manager->set('uglifyjs', $app['assetic.filters.uglifyjs2']); $manager->set('uglifycss', $app['assetic.filters.uglifycss']); $manager->set('compass', $app['assetic.filters.compass']); return $manager; }); /** * Asset writer, writes to the 'assetic.path_to_web' folder * * @return \Assetic\AssetWriter */ $app['assetic.asset_writer'] = $app->share(function () use($app) { return new AssetWriter($app['paths.cache_assets']); }); /** * Factory * * @return \Assetic\Factory\AssetFactory */ $app['assetic.factory'] = $app->share(function () use($app) { $factory = new AssetFactory($app['paths.resources'], false); $factory->setAssetManager($app['assetic.asset_manager']); $factory->setFilterManager($app['assetic.filter_manager']); $factory->addPath('sentient', $app['paths.templates'] . '/sentient'); $factory->addPath('sentient', $app['paths.sentient'] . '/Resource'); foreach ($app->getPluginNames() as $name) { $factory->addPath($name, $app['paths.resources'] . '/plugin/' . $name); $factory->addPath($name, $app->getPlugin($name)->getPath() . '/Resource'); } return $factory; }); /** * Asset controllers */ $app['assets.controllers'] = $app->share(function () use($app) { $controllers = $app['controllers_factory']; $controllers->match('/{filename}', function (Request $request) use($app) { return new AssetResponse($request->get('asset'), $app['assetic.asset_writer'], $app['paths.cache_assets']); })->assert('filename', '.+')->beforeMatch(function (array $attrs) use($app) { // @todo: A better way than looping through all loaded assets foreach ($app['assetic.asset_manager']->getNames() as $name) { $asset = $app['assetic.asset_manager']->get($name); if ($asset->getTargetPath() === $attrs['filename']) { $attrs['asset'] = $asset; return $attrs; } } return false; })->bind('asset'); return $controllers; }); $app['assets.register_js'] = $app->protect(function ($name, $scripts) use($app) { $asset = $app['assetic.factory']->createAsset((array) $scripts, ['uglifyjs'], ['output' => 'js/' . $name . '.js']); $app['assetic.asset_manager']->set('js_' . str_replace('/', '_', $name), $asset); return $asset; }); $app['assets.register_scss'] = $app->protect(function ($name, $stylesheets) use($app) { $asset = $app['assetic.factory']->createAsset((array) $stylesheets, ['compass', 'uglifycss'], ['output' => 'css/' . $name . '.css']); $app['assetic.asset_manager']->set('css_' . str_replace('/', '_', $name), $asset); return $asset; }); $app['asset_helper'] = $app->share(function () use($app) { return new AssetHelper($app['assetic.asset_manager'], $app['url_generator']); }); $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) use($app) { $twig->addExtension(new TwigAssetExtension($app['asset_helper'])); return $twig; })); $app['filesystem_controllers_factory'] = $app->protect(function ($basePath, $routeName = null) use($app) { $controllers = $app['controllers_factory']; $route = $controllers->match('/{filename}', function (Request $request) { $file = new FilesystemFile($request->get('path')); return new FileResponse($file); })->beforeMatch(function (array $attrs) use($basePath) { if (false !== strpos($attrs['filename'], '..')) { return false; } $attrs['path'] = $basePath . '/' . $attrs['filename']; if (!is_file($attrs['path'])) { return false; } return $attrs; })->assert('filename', '.+'); if ($routeName !== null) { $route->bind($routeName); } return $controllers; }); $app->mount('/assets', $app['assets.controllers']); }
/** * 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['compass'] = $app->share(function () use($app) { $filter = new CompassFilter($app['assetic.filter.compass.bin'], $app['assetic.ruby.bin']); $filter->setScss($app['assetic.filter.compass.scss']); $filter->setUnixNewlines($app['assetic.filter.compass.unix_newlines']); $filter->setNoCache($app['assetic.filter.compass.no_cache']); $filter->setForce($app['assetic.filter.compass.force']); $filter->setQuiet($app['assetic.filter.compass.quiet']); $filter->setTimeout($app['assetic.filter.compass.timeout']); $filter->setDebugInfo($app['assetic.filter.compass.debug']); $filter->setBoring($app['assetic.filter.compass.boring']); $filter->setNoLineComments($app['assetic.filter.compass.no_line_comments']); $filter->setStyle($app['assetic.filter.compass.style']); $filter->setImagesDir($app['assetic.filter.compass.images_dir']); $filter->setFontsDir($app['assetic.filter.compass.fonts_dir']); $filter->setRelativeAssets($app['assetic.filter.compass.relative_assets']); $filter->setJavascriptsDir($app['assetic.filter.compass.javascripts_dir']); $filter->setHttpPath($app['assetic.filter.compass.http_path']); $filter->setHttpImagesPath($app['assetic.filter.compass.http_images_path']); $filter->setHttpFontsPath($app['assetic.filter.compass.http_fonts_path']); $filter->setHttpGeneratedImagesPath($app['assetic.filter.compass.http_generated_images_path']); $filter->setGeneratedImagesPath($app['assetic.filter.compass.generated_images_path']); $filter->setHttpJavascriptsPath($app['assetic.filter.compass.http_javascripts_path']); $filter->setPlugins($app['assetic.filter.compass.plugins']); $filter->setLoadPaths($app['assetic.filter.compass.load_paths']); $filter->setHomeEnv($app['assetic.filter.compass.home_env']); $filter->setCacheLocation($app['assetic.filter.compass.cache_location']); return $filter; }); return $filters; })); }