Esempio n. 1
0
 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());
 }
Esempio n. 2
0
 /**
  * {@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;
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function dump(FilterInterface $additionalFilter = null)
 {
     if (!$this->loaded) {
         $this->loadResourcesFromRepo();
     }
     return parent::dump($additionalFilter);
 }
Esempio n. 4
0
 public function dump(FilterInterface $additionalFilter = null)
 {
     if (!$this->initialized) {
         $this->initialize();
     }
     return parent::dump($additionalFilter);
 }
Esempio n. 5
0
 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();
 }
Esempio n. 6
0
 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());
 }
Esempio n. 7
0
 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());
 }
 /**
  * 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();
 }
Esempio n. 9
0
 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();
 }
 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;
 }
Esempio n. 12
0
 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'));
 }
 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());
 }
Esempio n. 14
0
 /**
  * {@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);
 }
Esempio n. 16
0
 /**
  * @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;
 }
 /**
  * @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;
                 }
             }
         }
     }
 }
Esempio n. 18
0
 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;
 }
Esempio n. 19
0
 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());
 }
Esempio n. 20
0
 /**
  * Eejecuta la rutina de minificacion
  * 
  * Los tipos de recursos aceptados son:
  * Resources:CSS
  * Resources:JS
  * Resources:NONE
  * 
  * @param int $compile El tipo de recurso a minificar
  */
 public function compile($compile = Resources::NONE)
 {
     require_once __DIR__ . '/cssmin-v3.0.1.php';
     require_once __DIR__ . '/jsmin.php';
     $asset = new AssetCollection();
     $this->resources->each(function ($key, $value) use(&$asset) {
         if ($value->flag) {
             $asset->add(new FileAsset($value->asset));
         } else {
             $asset->add(new GlobAsset($value->asset));
         }
     });
     if ($compile == Resources::JS) {
         $asset->ensureFilter(new \Assetic\Filter\JSMinFilter());
     }
     if ($compile == Resources::CSS) {
         $asset->ensureFilter(new \Assetic\Filter\CssMinFilter());
     }
     // the code is merged when the asset is dumped
     $bundles = \Raptor\Core\Location::get('web_bundles');
     if (!file_exists($bundles . $this->bundleName)) {
         mkdir($bundles . $this->bundleName, 0777, true);
     }
     if ($this->name[0] == '/' or $this->name[0] == DIRECTORY_SEPARATOR) {
         unset($this->name[0]);
     }
     $dir = dirname($bundles . $this->bundleName . '/' . $this->name);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     if ($this->force == true) {
         file_put_contents($bundles . $this->bundleName . '/' . $this->name, $asset->dump());
     } else {
         if (!file_exists($bundles . $this->bundleName . '/' . $this->name)) {
             file_put_contents($bundles . $this->bundleName . '/' . $this->name, $asset->dump());
         }
     }
 }
Esempio n. 21
0
 protected function getAsseticAssets($onlyTypes = [], $onlySections = [])
 {
     $return = [];
     $onlyTypes = $this->getKeysIfEmpty($this->collections, $onlyTypes);
     foreach ($onlyTypes as $type) {
         if (!isset($this->collections[$type])) {
             continue;
         }
         $onlySections = $this->getKeysIfEmpty($this->collections[$type], $onlySections);
         foreach ($onlySections as $section) {
             if (!isset($this->collections[$type][$section])) {
                 continue;
             } else {
                 $collections = $this->collections[$type][$section];
             }
             /**
              * Sort collections by priority.
              */
             ksort($collections);
             foreach ($collections as $priority => $collection) {
                 $typePath = path('storage') . 'cache' . path('ds') . 'www' . path('ds') . $type . path('ds');
                 $assetCollection = new AssetCollection([], [], $typePath);
                 foreach ($collection as $asset) {
                     $filters = [];
                     if ($type == 'less') {
                         $filters[] = new LessPckgFilter();
                         $filters[] = new PathPckgFilter();
                     }
                     if (in_array($type, ['css', 'less'])) {
                         $filters[] = new PathPckgFilter();
                     }
                     $assetCollection->add(new FileAsset($asset, $filters));
                 }
                 $lastModified = $assetCollection->getLastModified();
                 $cachePath = $typePath . $priority . '-' . $section . '-' . $lastModified . '.' . $type;
                 $assetCollection->setTargetPath($cachePath);
                 file_put_contents($cachePath, $assetCollection->dump());
                 $return[] = str_replace('##LINK##', str_replace(path('root'), path('ds'), $cachePath), $this->types[$type]);
             }
         }
     }
     return $return;
 }
Esempio n. 22
0
$options = getopt($shortopts, $longopts);
// Combine the options to their shorter names
if (empty($options['s']) && !empty($options['source'])) {
    $options['s'] = $options['source'];
}
if (!isset($options['s'])) {
    exit('Please specify a source document  build.php -s resume.pdf');
}
$basename = pathinfo($options['s'], PATHINFO_FILENAME);
$source = './resume/' . $options['s'];
$pdf_source = './output/' . $basename . '-pdf.html';
$output = './output/' . $basename . '.html';
$pdf_output = './output/' . $basename . '.pdf';
$refresh_dev = isset($options['r']) || isset($options['refresh']);
$css = new AssetCollection(array(new GlobAsset(APPLICATION_BASE_PATH . '/assets/css/*.css')), array(new Filter\LessphpFilter()));
$style = $css->dump();
$template = file_get_contents(APPLICATION_BASE_PATH . '/assets/templates/default.html');
$resume = file_get_contents($source);
$resume = Markdown($resume);
$resume = SmartyPants($resume);
$html = str_get_html($resume);
$title = sprintf('%s | %s', $html->find('h1', 0)->innertext, $html->find('h2', 0)->innertext);
$m = new Mustache();
$rendered = $m->render($template, array('title' => $title, 'style' => $style, 'resume' => $resume, 'reload' => $refresh_dev));
file_put_contents($output, $rendered);
echo "Wrote html to {$output}\n";
$pdf_classed = str_replace('body class=""', 'body class="pdf"', $rendered);
if (isset($options['pdf'])) {
    file_put_contents($pdf_source, $pdf_classed);
    exec('wkhtmltopdf ' . $pdf_source . ' ' . $pdf_output . ' && open ' . $pdf_output);
    unlink($pdf_source);
 public function testDumpDedupByStrictEquality()
 {
     $asset = new StringAsset('foo');
     $coll = new AssetCollection(array($asset, $asset));
     $coll->load();
     $this->assertEquals('foo', $coll->dump(), '->dump() detects duplicate assets based on strict equality');
 }
Esempio n. 24
0
use Assetic\AssetManager;
use Assetic\Asset\AssetReference;
use Assetic\Filter\JSMinPlusFilter;
use Assetic\AssetWriter;
use Assetic\Cache\FilesystemCache;
use Assetic\Asset\AssetCache;
// Define the locations for the asset and cache directories
$assets = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'assets';
$cache = $assets . DIRECTORY_SEPARATOR . 'cache';
$am = new AssetManager();
// Create asset refrences to jQuery and all the other js files in the JS folder
// Creating a refernce to jQuery will allow us to put it first in the file
$am->set('jquery', new AssetCache(new FileAsset($assets . DIRECTORY_SEPARATOR . 'jquery' . DIRECTORY_SEPARATOR . 'jquery-1.11.1.min.js'), new FilesystemCache($cache)));
$am->set('jquery_ui', new AssetCache(new FileAsset($assets . DIRECTORY_SEPARATOR . 'jquery' . DIRECTORY_SEPARATOR . 'jquery-ui-1.9.2.min.js'), new FilesystemCache($cache)));
$am->set('otherjs', new AssetCache(new GlobAsset($assets . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . '*.js'), new FilesystemCache($cache)));
//include guide.js if reffer is from guide.php
//if (isset( $_SERVER['HTTP_REFERER'])) {
//	$lobjSplit = explode( '/', $_SERVER['HTTP_REFERER']);
//  if( strpos($lobjSplit[count($lobjSplit) - 1], 'guide.php') !== FALSE && $lobjSplit[count($lobjSplit) - 2] == 'guides' )
//{
$am->set('guidejs', new AssetCache(new GlobAsset($assets . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'guides' . DIRECTORY_SEPARATOR . '*.js'), new FilesystemCache($cache)));
//   }
//} else { }
// Apply the JSMinPlus filter to all the files
$jquery = new AssetCollection(array(new AssetReference($am, 'jquery')));
$jquery_ui = new AssetCollection(array(new AssetReference($am, 'jquery_ui')));
$other_js = $am->has('guidejs') ? new AssetCollection(array(new AssetReference($am, 'otherjs'), new AssetReference($am, 'guidejs'))) : new AssetCollection(array(new AssetReference($am, 'otherjs')));
// Place jQuery first in the final output
$javascripts = new AssetCollection(array($jquery, $jquery_ui, $other_js));
echo $javascripts->dump();
Esempio n. 25
0
 /**
  *
  */
 private function buildAssetCache($cache_file, $files)
 {
     $assets = [];
     foreach ($files as $file) {
         $extension = pathinfo($file, PATHINFO_EXTENSION);
         $filters = $this->getAssetFilters($extension);
         $assets[] = preg_match('#^http(s?)://(.*)$#', $file) ? new Asset\HttpAsset($file, $filters) : new Asset\FileAsset($file, $filters);
     }
     $collection = new Asset\AssetCollection($assets);
     if (!file_put_contents($cache_file, $collection->dump())) {
         throw new Flourish\EnvironmentException('Could not write to asset cache file %s', $cache_file);
     }
 }
Esempio n. 26
0
$am = new AssetManager();
// Step 1.
$am->set('pure', new AssetCache(new FileAsset($assets . '/css/shared/pure-min.css'), new FilesystemCache($cache)));
$am->set('pure_grid', new AssetCache(new FileAsset($assets . '/css/shared/grids-responsive-min.css'), new FilesystemCache($cache)));
$am->set('jqueryui', new AssetCache(new FileAsset($assets . '/css/shared/jquery-ui.css'), new FilesystemCache($cache)));
$am->set('colorbox', new AssetCache(new FileAsset($assets . '/css/shared/colorbox.css'), new FilesystemCache($cache)));
$am->set('admin_styles', new AssetCache(new FileAsset($assets . '/css/admin/admin_styles.css'), new FilesystemCache($cache)));
$am->set('override', new AssetCache(new FileAsset($assets . '/css/admin/override.css'), new FilesystemCache($cache)));
$am->set('font_awesome', new AssetCache(new FileAsset($assets . '/css/shared/font-awesome.min.css'), new FilesystemCache($cache)));
// Glob all the rest of the CSS files together
// $am->set('css', new AssetCache(new GlobAsset($assets . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR .  '*.css'), new FilesystemCache($cache)));
// Step 2.
// This is where the CSSMin filter will be applied eventually.
$pure = new AssetCollection(array(new AssetReference($am, 'pure')));
$pure_grid = new AssetCollection(array(new AssetReference($am, 'pure_grid')));
$jqueryui = new AssetCollection(array(new AssetReference($am, 'jqueryui')));
$colorbox = new AssetCollection(array(new AssetReference($am, 'colorbox')));
$override = new AssetCollection(array(new AssetReference($am, 'override')));
$admin_styles = new AssetCollection(array(new AssetReference($am, 'admin_styles')));
$font_awesome = new AssetCollection(array(new AssetReference($am, 'font_awesome')));
//$css_files = new AssetCollection(array (new AssetReference($am, 'css')));
// Step 3.
// Create an AssetCollection that uses the newly minified css
//$css = new AssetCollection(array ($pure, $colorbox, $guide,  $jqueryui,  $css_files) );
$css = new AssetCollection(array($pure, $pure_grid, $colorbox, $admin_styles, $jqueryui, $override, $font_awesome));
// Tell the browser that this is CSS and that it should be cached
header('Cache-control: public');
header('Content-Type: text/css');
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 21600));
echo $css->dump();
Esempio n. 27
0
 /**
  * Concatenate all scripts together into one destination file.
  */
 public function aggregateScripts($package, array $scripts, $file)
 {
     // Aggregate all the assets into one file.
     $assets = new AssetCollection();
     foreach ($scripts as $script) {
         // Collect each candidate from a glob file search.
         $path = $this->getVendorDir($package) . DIRECTORY_SEPARATOR . $script;
         $matches = $this->fs->recursiveGlobFiles($path);
         foreach ($matches as $match) {
             $assets->add(new FileAsset($match));
         }
     }
     $js = $assets->dump();
     // Write the file if there are any JavaScript assets.
     if (!empty($js)) {
         $destination = $this->componentDir . DIRECTORY_SEPARATOR . $file;
         $this->fs->ensureDirectoryExists(dirname($destination));
         return file_put_contents($destination, $js);
     }
     return false;
 }
Esempio n. 28
0
 public function runResolve(framework\Request $request)
 {
     $theme = isset($request['theme_name']) ? $request['theme_name'] : framework\Settings::getThemeName();
     $module_path = framework\Context::isInternalModule($request['module_name']) ? THEBUGGENIE_INTERNAL_MODULES_PATH : THEBUGGENIE_MODULES_PATH;
     if ($request->hasParameter('css')) {
         $this->getResponse()->setContentType('text/css');
         if ($request->hasParameter('module_name') && framework\Context::isModuleLoaded($request['module_name'])) {
             $basepath = $module_path . $request['module_name'] . DS . 'public' . DS . 'css';
             $asset = $module_path . $request['module_name'] . DS . 'public' . DS . 'css' . DS . $request->getParameter('css');
         } elseif (!$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'])) {
             $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');
         }
     } elseif ($request->hasParameter('image')) {
         $basepath = THEBUGGENIE_PATH . 'themes';
         $asset = THEBUGGENIE_PATH . 'themes' . DS . $theme . DS . 'images';
         if (isset($request['module_name'])) {
             $asset .= DS . "modules" . DS . $request['module_name'];
         }
         if (isset($request['folder'])) {
             $asset .= DS . $request['folder'];
         }
         $asset .= DS . $request->getParameter('image');
         if (!file_exists($asset) && isset($request['module_name']) && framework\Context::isModuleLoaded($request['module_name'])) {
             $basepath = $module_path . $request['module_name'] . DS . 'public' . DS . 'images';
             $asset = $module_path . $request['module_name'] . DS . 'public' . DS . 'images';
             if (isset($request['folder'])) {
                 $asset .= DS . $request['folder'];
             }
             $asset .= DS . $request->getParameter('image');
         }
         $fileinfo = finfo_open(FILEINFO_MIME_TYPE);
         $mimetype = finfo_file($fileinfo, $asset);
         finfo_close($fileinfo);
         $this->getResponse()->setContentType($mimetype);
     } else {
         throw new \Exception('The expected theme Asset type is not supported.');
     }
     $last_modified = filemtime($asset);
     $this->getResponse()->addHeader('Cache-Control: max-age=3600, must-revalidate');
     $this->getResponse()->addHeader('Last-Modified: ' . gmdate('D, d M Y H:i:s ', $last_modified) . 'GMT');
     $this->getResponse()->addHeader('ETag: ' . md5($last_modified));
     if (!$this->getResponse()->isModified($last_modified)) {
         return $this->return304();
     }
     $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());
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $filesystem = $container->get('filesystem');
     $languages = $container->getParameter('hatimeria_ext_js.locales');
     $files = $container->getParameter('hatimeria_ext_js.compiled_files');
     $domains = $container->getParameter("hatimeria_ext_js.translation_domains");
     $vendorPath = $container->getParameter("hatimeria_ext_js.javascript_vendor_path");
     $hdefault = new JavascriptController();
     $hdefault->setContainer($container);
     $dynamic = $hdefault->dynamicAction()->getContent();
     $hdirect = new DirectController();
     $hdirect->setContainer($container);
     $api = $hdirect->getApiAction()->getContent();
     $expose = $container->get('bazinga.exposetranslation.controller');
     $routing = $container->get('fos_js_routing.controller');
     $compressor = new JsCompressorFilter('vendor/bundles/Hatimeria/ExtJSBundle/Resources/jar/yuicompressor.jar');
     $extjs = "web/bundles/hatimeriaextjs/js/extjs/";
     // @todo recursive glob
     foreach ($languages as $lang) {
         $ac = new AssetCollection();
         $ac->add(new FileAsset("web/" . $vendorPath . "/ext-all.js"));
         $ac->add(new FileAsset($extjs . "/core/overrides.js"));
         $ac->add(new StringAsset($dynamic));
         $ac->add(new FileAsset($extjs . "/translation/Translation.js"));
         foreach ($domains as $domain) {
             $ac->add(new StringAsset($expose->exposeTranslationAction($domain, $lang, 'js')->getContent()));
         }
         $ac->add(new FileAsset("web/" . $vendorPath . "locale/ext-lang-" . $lang . ".js"));
         $ac->add(new FileAsset($extjs . "/core/direct-api-handler.js"));
         $ac->add(new FileAsset($extjs . "/routing/Routing.js"));
         $ac->add(new GlobAsset($extjs . "/core/utils/*"));
         $ac->add(new GlobAsset($extjs . "/core/mixins/*"));
         $ac->add(new GlobAsset($extjs . "/core/store/*"));
         $ac->add(new GlobAsset($extjs . "/core/model/*"));
         $ac->add(new GlobAsset($extjs . "/core/grid/*"));
         $ac->add(new GlobAsset($extjs . "/core/response/*"));
         $ac->add(new GlobAsset($extjs . "/core/window/*"));
         $ac->add(new FileAsset($extjs . "/core/form/BaseForm.js"));
         $ac->add(new GlobAsset($extjs . "/core/form/*"));
         $ac->add(new GlobAsset($extjs . "/core/field/*"));
         $ac->add(new GlobAsset($extjs . "/core/user/*"));
         $ac->add(new GlobAsset($extjs . "/treeselect/store/*"));
         $ac->add(new GlobAsset($extjs . "/treeselect/panel/*"));
         $ac->add(new GlobAsset($extjs . "/treeselect/field/*"));
         $ac->add(new StringAsset($api));
         $ac->add(new StringAsset($routing->indexAction('js')->getContent()));
         foreach ($files as $file) {
             $ac->add(new FileAsset('web/' . $file));
         }
         $ac->ensureFilter($compressor);
         $compiled = $ac->dump();
         @mkdir('web/compiled/js', 0755, true);
         file_put_contents(sprintf("web/compiled/js/ext-%s.js", $lang), $compiled);
     }
     $output->writeln('Assets compiled');
 }
Esempio n. 30
0
 public function getContent($name)
 {
     $assets = $this->getAssetsPathInfo($name, !$this->options['debug']);
     $asset_list = array();
     foreach ($assets as $asset) {
         $extensions = explode('.', basename($asset['requested_asset']));
         $filters = array();
         foreach (array_reverse($extensions) as $ext) {
             $filters_by_ext = $this->filter_manager->getFiltersByExtension($ext);
             if ($filters_by_ext) {
                 $filters = array_merge($filters, $filters_by_ext);
             }
         }
         $prefixed_url = $this->getPrefixedUrl($asset);
         $file_asset = new FileAsset($asset['absolute_path'], $filters, dirname($asset['absolute_path']), $prefixed_url);
         $asset_list[] = $file_asset;
     }
     $collection = new AssetCollection($asset_list);
     return $collection->dump();
 }