/** * {@inheritDoc} */ public function resolve($name) { if (!isset($this->collections[$name])) { return null; } if (!is_array($this->collections[$name])) { throw new \RuntimeException("Collection with name {$name} is not an array."); } $collection = new AssetCollection(); $mimeType = 'application/javascript'; $collection->setTargetPath($name); foreach ($this->collections[$name] as $asset) { if (!is_string($asset)) { throw new \RuntimeException('Asset should be of type string. got ' . gettype($asset)); } if (null === ($content = $this->riotTag->__invoke($asset))) { throw new \RuntimeException("Riot tag '{$asset}' could not be found."); } $res = new StringAsset($content); $res->mimetype = $mimeType; $asset .= ".js"; $this->getAssetFilterManager()->setFilters($asset, $res); $collection->add($res); } $collection->mimetype = $mimeType; return $collection; }
/** * Adds support for pipeline assets. * * {@inheritdoc} */ protected function parseInput($input, array $options = array()) { if (is_string($input) && '|' == $input[0]) { switch (pathinfo($options['output'], PATHINFO_EXTENSION)) { case 'js': $type = 'js'; break; case 'css': $type = 'css'; break; default: throw new \RuntimeException('Unsupported pipeline asset type provided: ' . $input); } $assets = new AssetCollection(); foreach ($this->locator->locatePipelinedAssets(substr($input, 1), $type) as $formula) { $filters = array(); if ($formula['filter']) { $filters[] = $this->getFilter($formula['filter']); } $asset = new FileAsset($formula['root'] . '/' . $formula['file'], $filters, $options['root'][0], $formula['file']); $asset->setTargetPath($formula['file']); $assets->add($asset); } return $assets; } return parent::parseInput($input, $options); }
protected function generateContent($templatePath, $contentType) { // We build these into a single string so that we can deploy this resume as a // single file. $assetPath = join(DIRECTORY_SEPARATOR, array($templatePath, $contentType)); if (!file_exists($assetPath)) { return ''; } $assets = array(); // Our PHAR deployment can't handle the GlobAsset typically used here foreach (new \DirectoryIterator($assetPath) as $fileInfo) { if ($fileInfo->isDot() || !$fileInfo->isFile()) { continue; } array_push($assets, new FileAsset($fileInfo->getPathname())); } usort($assets, function (FileAsset $a, FileAsset $b) { return strcmp($a->getSourcePath(), $b->getSourcePath()); }); $collection = new AssetCollection($assets); switch ($contentType) { case 'css': $collection->ensureFilter(new Filter\LessphpFilter()); break; } return $collection->dump(); }
public function runResolve(framework\Request $request) { $theme = isset($request['theme_name']) ? $request['theme_name'] : framework\Settings::getThemeName(); if ($request->hasParameter('css')) { $this->getResponse()->setContentType('text/css'); if (!$request->hasParameter('theme_name')) { $basepath = THEBUGGENIE_PATH . 'public' . DS . 'css'; $asset = THEBUGGENIE_PATH . 'public' . DS . 'css' . DS . $request->getParameter('css'); } else { $basepath = THEBUGGENIE_PATH . 'themes'; $asset = THEBUGGENIE_PATH . 'themes' . DS . $theme . DS . 'css' . DS . $request->getParameter('css'); } } elseif ($request->hasParameter('js')) { $this->getResponse()->setContentType('text/javascript'); if ($request->hasParameter('theme_name')) { $basepath = THEBUGGENIE_PATH . 'themes'; $asset = THEBUGGENIE_PATH . 'themes' . DS . $theme . DS . 'js' . DS . $request->getParameter('js'); } elseif ($request->hasParameter('module_name') && framework\Context::isModuleLoaded($request['module_name'])) { $module_path = framework\Context::isInternalModule($request['module_name']) ? THEBUGGENIE_INTERNAL_MODULES_PATH : THEBUGGENIE_MODULES_PATH; $basepath = $module_path . $request['module_name'] . DS . 'public' . DS . 'js'; $asset = $module_path . $request['module_name'] . DS . 'public' . DS . 'js' . DS . $request->getParameter('js'); } else { $basepath = THEBUGGENIE_PATH . 'public' . DS . 'js'; $asset = THEBUGGENIE_PATH . 'public' . DS . 'js' . DS . $request->getParameter('js'); } } else { throw new \Exception('The expected theme Asset type is not supported.'); } $fileAsset = new AssetCollection(array(new FileAsset($asset, array(), $basepath))); $fileAsset->load(); // Do not decorate the asset with the theme's header/footer $this->getResponse()->setDecoration(framework\Response::DECORATE_NONE); return $this->renderText($fileAsset->dump()); }
/** * Create a new AssetCollection instance for the given group. * * @param string $name * @param bool $overwrite force writing * @return \Assetic\Asset\AssetCollection */ public function createGroup($name, $overwrite = false) { if (isset($this->groups[$name])) { return $this->groups[$name]; } $assets = $this->createAssetArray($name); $filters = $this->createFilterArray($name); $coll = new AssetCollection($assets, $filters); if ($output = $this->getConfig($name, 'output')) { $coll->setTargetPath($output); } // check output cache $write_output = true; if (!$overwrite) { if (file_exists($output = public_path($coll->getTargetPath()))) { $output_mtime = filemtime($output); $asset_mtime = $coll->getLastModified(); if ($asset_mtime && $output_mtime >= $asset_mtime) { $write_output = false; } } } // store assets if ($overwrite || $write_output) { $writer = new AssetWriter(public_path()); $writer->writeAsset($coll); } return $this->groups[$name] = $coll; }
public function filterDump(AssetInterface $asset) { $content = ""; $files = array(); $extraFiles = array(); $absolutePath = $asset->getSourceRoot() . '/' . $asset->getSourcePath(); $this->parser->mime = $this->parser->mimeType($absolutePath); if ($this->parser->mime === 'javascripts') { $extraFiles = $this->parser->get("javascript_files", array()); } if ($this->parser->mime === 'stylesheets') { $extraFiles = $this->parser->get("stylesheet_files", array()); } $absoluteFilePaths = $this->parser->getFilesArrayFromDirectives($absolutePath); if ($absoluteFilePaths) { $absoluteFilePaths = $extraFiles + $absoluteFilePaths; } foreach ($absoluteFilePaths as $absoluteFilePath) { $files[] = $this->generator->file($absoluteFilePath, false); } if (!$absoluteFilePaths) { $files[] = $this->generator->file($absolutePath, false); } $global_filters = $this->parser->get("sprockets_filters.{$this->parser->mime}", array()); $collection = new AssetCollection($files, $global_filters); $asset->setContent($collection->dump()); }
public function testMinifyCss() { $assets = array(new FileAsset(TEST_PATH . 'dummy.css')); $filters = array(new MinFilter('css')); $collection = new AssetCollection($assets, $filters); $this->assertEquals('.foo{display:block}', $collection->dump()); }
/** * {@inheritdoc} */ public function process() { $filters = new FilterCollection(array(new CssRewriteFilter())); $assets = new AssetCollection(); $styles = $this->packageStyles($this->packages); foreach ($styles as $package => $packageStyles) { foreach ($packageStyles as $style => $paths) { foreach ($paths as $path) { // The full path to the CSS file. $assetPath = realpath($path); // The root of the CSS file. $sourceRoot = dirname($path); // The style path to the CSS file when external. $sourcePath = $package . '/' . $style; // Where the final CSS will be generated. $targetPath = $this->componentDir; // Build the asset and add it to the collection. $asset = new FileAsset($assetPath, $filters, $sourceRoot, $sourcePath); $asset->setTargetPath($targetPath); $assets->add($asset); } } } $css = $assets->dump(); if (file_put_contents($this->componentDir . '/require.css', $css) === FALSE) { $this->io->write('<error>Error writing require.css to destination</error>'); return false; } }
/** * Resolve to the plugins for this module (expand). * * @throws \SxBootstrap\Exception\RuntimeException * @return \Assetic\Asset\AssetCollection */ protected function resolvePlugins() { $config = $this->config; $pluginFiles = $this->getPluginNames($config->getMakeFile()); $includedPlugins = $config->getIncludedPlugins(); $excludedPlugins = $config->getExcludedPlugins(); if (!empty($excludedPlugins) && !empty($includedPlugins)) { throw new Exception\RuntimeException('You may not set both excluded and included plugins.'); } $pluginsAsset = new AssetCollection(); $mimeType = null; foreach ($pluginFiles as $plugin) { if (!empty($excludedPlugins) && in_array($plugin, $excludedPlugins)) { continue; } elseif (!empty($includedPlugins) && !in_array($plugin, $includedPlugins)) { continue; } $res = $this->getAggregateResolver()->resolve('js/bootstrap-' . $plugin . '.js'); if (null === $res) { throw new Exception\RuntimeException("Asset '{$plugin}' could not be found."); } if (!$res instanceof AssetInterface) { throw new Exception\RuntimeException("Asset '{$plugin}' does not implement Assetic\\Asset\\AssetInterface."); } if (null !== $mimeType && $res->mimetype !== $mimeType) { throw new Exception\RuntimeException(sprintf('Asset "%s" from collection "%s" doesn\'t have the expected mime-type "%s".', $plugin, $config->getPluginAlias(), $mimeType)); } $mimeType = $res->mimetype; $this->getAssetFilterManager()->setFilters($plugin, $res); $pluginsAsset->add($res); } $pluginsAsset->mimetype = $mimeType; return $pluginsAsset; }
public function testProcess_withAssetCollection_shouldHash() { $collection = new AssetCollection(); $collection->add($this->getFileAsset('asset.txt')); $collection->add($this->getStringAsset('string', 'string.txt')); $collection->setTargetPath('collection.txt'); $this->getCacheBustingWorker()->process($collection, $this->getAssetFactory()); $this->assertSame('collection-ae851400.txt', $collection->getTargetPath()); }
public function build($collection_name) { $build_path_setting = Config::get("assetie::build_path"); $build_directory = public_path() . DIRECTORY_SEPARATOR . $build_path_setting; /** * the designated name of the build, i.e. base_123.js */ $build_name = $collection_name . "." . $this->buildExtension; $build_file = $build_directory . DIRECTORY_SEPARATOR . $build_name; $buildExists = file_exists($build_file); $build_url = URL::asset($build_path_setting . DIRECTORY_SEPARATOR . $build_name); $debugMode = Config::get("app.debug"); if (!$buildExists || $debugMode) { $files = \Collection::dump($collection_name)[$this->group]; $collection_hash = sha1(serialize($files)); $hash_in_cache = Cache::get("collection_" . $this->group . "_" . $collection_name); $collectionChanged = $collection_hash != $hash_in_cache; $src_dir = app_path() . DIRECTORY_SEPARATOR . Config::get("assetie::directories." . $this->group) . DIRECTORY_SEPARATOR; $forceRebuild = false; if ($collectionChanged) { $forceRebuild = true; } else { if ($buildExists) { /** * only recompile if no compiled build exists or when in debug mode and * build's source files or collections.php has been changed */ $forceRebuild = $this->checkModification($build_file, $files, $src_dir); } } if (!$buildExists || $forceRebuild) { $am = new AssetManager(); $assets = []; foreach ($files as $file) { $filters = $this->getFilters($file); $assets[] = new FileAsset($src_dir . $file, $filters); } $collection = new AssetCollection($assets); // , $filters $collection->setTargetPath($build_name); $am->set('collection', $collection); $writer = new AssetWriter($build_directory); $writer->writeManagerAssets($am); } // Cache::forever("collection_" . $collection_name, $collection_hash); $cache_key = "collection_" . $this->group . "_" . $collection_name; if (Cache::has($cache_key) && $collectionChanged) { Cache::forget($cache_key); } if ($collectionChanged) { Cache::put($cache_key, $collection_hash, 60); // 1 hour } } return $build_url; }
public function dump() { $file = array(new FileAsset($this->file)); $this->set_type_filter($this->type); if ($this->config->minify) { $this->set_minify_filter($this->type); } $result = new AssetCollection($file, $this->filters); return $result->dump(); }
/** * Dumps out the stylesheets for this file * * If we should concat then this should probably be a * manifest file so we should process directives inside * * @param [type] $path [description] * @return [type] [description] */ public function stylesheets($path) { $filters = array(); $files = array($this->getFullPath($path, 'stylesheets')); if ($this->shouldConcat()) { $files = $this->directives->getFilesFrom($this->getFullPath($path, 'stylesheets')); } $styles = new AssetCollection($this->getStyleAssets($files), $filters); return $styles->dump(); }
public function testOne() { $uglify = new UglifyJs2Filter("/usr/bin/uglifyjs", "/usr/bin/node"); $uglify->setCompress(true); $uglify->setMangle(true); $uglify->setCompress(true); $js = new AssetCollection(array(new GlobAsset(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "assets/src/*", array($uglify)))); echo $js->dump(); echo PHP_EOL; }
public function createVersion($request, $componentData, $component, $versionType = false, $branch = 'master') { $em = $this->_em; /** * manage versionType name * * If is additional branch add brnach name at end. */ if ($branch != 'master' && $branch != false) { if ($versionType) { $versionType = $versionType . '-' . $branch; } else { $versionType = $componentData['version']['value'] . '-' . $branch; } } else { if ($versionType) { $versionType = $versionType; } else { $versionType = $componentData['version']['value']; } } if (!$versionType) { $version = new \FWM\CraftyComponentsBundle\Entity\Versions(); $version->setValue($versionType); } else { $componentData['version']['value'] = $versionType; $version = $em->getRepository('FWMCraftyComponentsBundle:Versions')->findOneBy(array('component' => $component->getId(), 'value' => $versionType)); if (!$version) { $version = new \FWM\CraftyComponentsBundle\Entity\Versions(); $version->setValue($versionType); } } $version->setSha($componentData['version']['sha']); $version->setComponent($component); $version->setFileContent($componentData['componentFilesValue']); $version->setCreatedAt(new \DateTime()); //complete all files foreach (ArrayService::objectToArray(json_decode($componentData['componentFilesValue'])) as $value) { $tempFileContent[] = base64_decode($value); } $file = implode(' ', $tempFileContent); $path = $request->server->get('DOCUMENT_ROOT') . '/uploads/components/' . strtolower($componentData['name']) . '-' . strtolower($versionType); //create uncompressed version file_put_contents($path . '-uncompressed.js', $file); //minify uncompressed version try { $js = new AssetCollection(array(new FileAsset($path . '-uncompressed.js')), array(new Yui\JsCompressorFilter($request->server->get('DOCUMENT_ROOT') . '/../app/Resources/java/yuicompressor.jar'))); $minifidedFile = $js->dump(); } catch (\Exception $e) { $minifidedFile = $file; } // create minified version file_put_contents($path . '.js', $minifidedFile); return $version; }
public function js(array $params) { $jsfiles = Registry::getInstance()->assets['js']; $collection = new AssetCollection(); foreach ($jsfiles as $file) { $collection->add(new FileAsset($file, array(new JsCompressorFilter(APP_PATH . "/vendor/bin/yuicompressor.jar")))); } $cache = new AssetCache($collection, new FilesystemCache(APP_PATH . "/cache/assetic/js")); header('Content-Type: text/javascript'); echo $cache->dump(); }
public function addCollection($name, $assets) { $collection = new AssetCollection(array_map(function ($asset) { return new FileAsset($this->guessPath($asset['src'])); }, $assets)); $collection->setTargetPath($name); if (endsWith($name, '.css')) { $collection->ensureFilter(new CssRewriteFilter()); } $this->write($name, $collection->dump()); }
public function jsPackAction() { $collection = new AssetCollection(); foreach ($this->container->getParameter('cms.cms_resources.js_pack') as $asset) { $collection->add(new FileAsset($asset)); } $content = $this->container->getCache()->fetch('cms_assets', 'js_pack', function () use($collection) { return $collection->dump(); }, $collection->getLastModified()); return new Response($content, 200, array('Content-Type' => 'text/javascript')); }
/** * {@inheritdoc} */ public function process() { $filters = array(new CssRewriteFilter()); if ($this->config->has('component-styleFilters')) { $customFilters = $this->config->get('component-styleFilters'); if (isset($customFilters) && is_array($customFilters)) { foreach ($customFilters as $filter => $filterParams) { $reflection = new \ReflectionClass($filter); $filters[] = $reflection->newInstanceArgs($filterParams); } } } $filterCollection = new FilterCollection($filters); $assets = new AssetCollection(); $styles = $this->packageStyles($this->packages); foreach ($styles as $package => $packageStyles) { $packageAssets = new AssetCollection(); $packagePath = $this->componentDir . '/' . $package; foreach ($packageStyles as $style => $paths) { foreach ($paths as $path) { // The full path to the CSS file. $assetPath = realpath($path); // The root of the CSS file. $sourceRoot = dirname($path); // The style path to the CSS file when external. $sourcePath = $package . '/' . $style; //Replace glob patterns with filenames. $filename = basename($style); if (preg_match('~^\\*(\\.[^\\.]+)$~', $filename, $matches)) { $sourcePath = str_replace($filename, basename($assetPath), $sourcePath); } // Where the final CSS will be generated. $targetPath = $this->componentDir; // Build the asset and add it to the collection. $asset = new FileAsset($assetPath, $filterCollection, $sourceRoot, $sourcePath); $asset->setTargetPath($targetPath); $assets->add($asset); // Add asset to package collection. $sourcePath = preg_replace('{^.*' . preg_quote($package) . '/}', '', $sourcePath); $asset = new FileAsset($assetPath, $filterCollection, $sourceRoot, $sourcePath); $asset->setTargetPath($packagePath); $packageAssets->add($asset); } } if (file_put_contents($packagePath . '/' . $package . '-built.css', $packageAssets->dump()) === FALSE) { $this->io->write("<error>Error writing {$package}-built.css to destination</error>"); } } if (file_put_contents($this->componentDir . '/require.css', $assets->dump()) === FALSE) { $this->io->write('<error>Error writing require.css to destination</error>'); return false; } return null; }
public function testDefault() { $asset = __DIR__ . "/../../resources/test.coffee"; $assetCollection = new AssetCollection(); $assetCollection->add(new FileAsset($asset)); $assetCollection->ensureFilter(new CoffeeScriptPhpFilter()); $ret = $assetCollection->dump(); $exp = "var MyClass, myObject;"; $this->assertRegExp("/{$exp}/", $ret); $exp = "Generated by CoffeeScript PHP"; $this->assertRegExp("/{$exp}/", $ret); }
/** * This method is used instead of APY\JsFormValidationBundle\Generator\FormValidationScriptGenerator::generate * to return inline client-side form validation javascript * * @param FormView $formView * @param boolean $overwrite * * @return string */ public function generate(FormView $formView, $overwrite = true) { $validationBundle = $this->getValidationBundle(); $javascriptFramework = strtolower($this->container->getParameter('apy_js_form_validation.javascript_framework')); $template = $this->container->get('templating')->render("{$validationBundle}:Frameworks:JsFormValidation.js.{$javascriptFramework}.twig", $this->generateValidationParameters($formView)); // Js compression if ($this->container->getParameter('apy_js_form_validation.yui_js')) { // Create asset and compress it $asset = new AssetCollection(); $asset->setContent($template); return $asset->getContent(); } return $template; }
/** * @return AssetCollectionInterface */ public function getAssets() { if ($this->dirty) { $this->assets = new AssetCollection([], [], TL_ROOT); ksort($this->sortedAssets); foreach ($this->sortedAssets as $assets) { foreach ($assets as $asset) { $this->assets->add($asset); } } $this->dirty = false; } return $this->assets; }
public function addFiles($type, $files, $filter = NULL) { if (is_null($filter)) { $filter = $type; } $filter = AssetFacade::GetFilter($filter); if (!isset($this->collections[$type])) { $col = new AssetCollection(); $col->setTargetPath($this->path . '/' . $this->name . '.' . $type); $this->collections[$type] = $col; } $collection = $this->factory->createAsset($files, $filter); $this->collections[$type]->add($collection); }
/** * @param string $assets_dir * @param array $filters * * @return string */ public function dump($assets_dir, array $filters = []) { $assets = []; $assets_pathes = []; foreach ($this->assets as $asset) { $assets[] = $asset->getFileAsset($assets_dir); $assets_pathes[] = $asset->getTempPath(); } $collection = new AssetCollection($assets, $filters); $collection_dump = $collection->dump(); foreach ($assets_pathes as $asset_path) { @unlink($asset_path); } return $collection_dump; }
public function init() { $css = new AssetCollection(); $js = new AssetCollection(); $path =& $this->path; array_walk($this->config['css'], function ($v, $i) use(&$css, $path) { $asset = new FileAsset($path . $v, [new \Assetic\Filter\CssMinFilter()]); $css->add($asset); }); array_walk($this->config['js'], function ($v, $i) use(&$js, $path) { $asset = new FileAsset($path . $v); $js->add($asset); }); $css->setTargetPath('/theme/' . $this->skin . '_styles.css'); $js->setTargetPath('/theme/' . $this->skin . '_scripts.js'); $this->am->set('css', $css); $this->am->set('js', $js); }
/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { $this->getContainer()->get('kernel')->getRootDir(); $targetArg = rtrim($input->getArgument('target'), '/') . '/'; $rootDir = $this->getContainer()->get('kernel')->getRootDir(); $targetDir = $rootDir . '/../' . $targetArg; $confDir = $rootDir . '/config'; if (!is_dir($targetDir)) { throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target'))); } if (!file_exists($confDir . '/assets.json')) { throw new \InvalidArgumentException('The file ' . $confDir . '/assets.json does not exist.'); } $output->writeln("Combining assets"); $assetsFiles = json_decode(file_get_contents($confDir . '/assets.json'), true); foreach ($assetsFiles as $type => $combined) { foreach ($combined as $name => $files) { file_put_contents($targetDir . $files['output'], ''); $this->assets[$type][$name] = (array) $files['input']; foreach ($this->assets[$type][$name] as $value) { file_put_contents($targetDir . $files['output'], file_get_contents($targetDir . $value), FILE_APPEND); } $file = $targetDir . $files['output']; if (is_file($file)) { $f = new File($file); switch ($f->getExtension()) { case 'css': $resource = new AssetCollection(array(new FileAsset($file)), array(new MinifyCssCompressorFilter())); $resource->load(); file_put_contents($file, $resource->dump()); $output->writeln(sprintf('File <comment>%s</comment> was combined and minified', $file)); break; case 'js': $resource = new AssetCollection(array(new FileAsset($file)), array(new JSMinPlusFilter())); $resource->load(); file_put_contents($file, $resource->dump()); $output->writeln(sprintf('File <comment>%s</comment> was combined and minified', $file)); break; } } } } }
protected function createAsset($name, array $assets) { $inputs = array(); $collection = new AssetCollection(); $filters = array(); foreach ($assets as $type => $value) { if ($type === 'filters') { $filters = $value; } elseif (!is_array($value) && $value[0] === '@') { $collection->add(new AssetReference($this->am, substr_replace($value, '', 0, 1))); } elseif ($type === 'files') { foreach ($value as $keyOrSource => $sourceOrFilter) { if (!is_array($sourceOrFilter)) { $collection->add(new \Assetic\Asset\FileAsset($sourceOrFilter)); } else { $filter = array(); foreach ($sourceOrFilter as $filterName) { $filter[] = $this->fm->get($filterName); } $collection->add(new \Assetic\Asset\FileAsset($keyOrSource, $filter)); } } } elseif ($type === 'globs') { foreach ($value as $keyOrGlob => $globOrFilter) { if (!is_array($globOrFilter)) { $collection->add(new \Assetic\Asset\GlobAsset($globOrFilter)); } else { $filter = array(); foreach ($globOrFilter as $filterName) { $filter[] = $this->fm->get($filterName); } $collection->add(new \Assetic\Asset\GlobAsset($keyOrGlob, $filter)); } } } } $this->am->set($name, new AssetCache($collection, new \Assetic\Cache\FilesystemCache($this->config['cacheDir'] . '/chunks'))); $filename = str_replace('_', '.', $name); $this->_compiledAssets[$name] = "{$this->config['baseUrl']}/" . $filename; file_put_contents("{$this->config['assetDir']}/{$filename}", $this->factory->createAsset("@{$name}", $filters)->dump()); @chmod($filename, 0777); }
private function addToAssetManager($aAssets) { // Build asset array foreach ($aAssets as $sName => $aAssetGroup) { foreach ($aAssetGroup as $sType => $aFiles) { $aCollection = array(); foreach ($aFiles as $sFile) { $aCollection[] = new AssetCache(new FileAsset($sFile, $this->getFilters($sType)), new FilesystemCache($this->sCachePath)); } $oCollection = new AssetCollection($aCollection); $oCollection->setTargetPath($sName . '.' . $sType); $this->oAssetManager->set($sName . '_' . $sType, $oCollection); // Add to list of assets if (!isset($this->aAssetFiles[$sType])) { $this->aAssetFiles[$sType] = array(); } $this->aAssetFiles[$sType][] = $this->sCacheUrl . '/' . trim($sName . '.' . $sType, '/'); } } }
public static function serverAsset($dev) { $headers = Raptor::getRequest()->header; $route = $headers->get('PATH_INFO'); $web_location = Location::get('web_bundles'); $file = $web_location . $route; $js = new AssetCollection(array(new GlobAsset($file))); // the code is merged when the asset is dumped $response = new Response($js->dump()); if (preg_match("/(\\.css)\$/", $route)) { $response->addHeader('Content-Type', 'text/css'); } else { $response->addHeader('Content-Type', 'application/javascript'); } if ($dev == FALSE) { $response->setCache(true, 3, true); } $response->sendResponse(); exit; }
public function filterDump(AssetInterface $asset) { $content = ""; $files = array(); $absolutePath = $asset->getSourceRoot() . '/' . $asset->getSourcePath(); $this->parser->mime = $this->parser->mimeType($absolutePath); $absoluteFilePaths = $this->parser->getFilesArrayFromDirectives($absolutePath); foreach ($absoluteFilePaths as $absoluteFilePath) { $files[] = $this->generator->cachedFile($absoluteFilePath); } // this happens when the file isn't a manifest if (!$absoluteFilePaths) { $files[] = $this->generator->cachedFile($absolutePath); } $global_filters = $this->parser->get("sprockets_filters.{$this->parser->mime}", array()); // handle ASI issue with javascripts if ($this->parser->mime == "javascripts") { $global_filters = array_merge($global_filters, array(new Filters\JavascriptConcatenationFilter())); } $collection = new AssetCollection($files, $global_filters); $asset->setContent($collection->dump()); }