コード例 #1
0
 public function testAutomaticLoad()
 {
     $filter = $this->getMock('Assetic\\Filter\\FilterInterface');
     $filter->expects($this->once())->method('filterLoad');
     $asset = new StringAsset('foo', array($filter));
     $asset->dump();
 }
コード例 #2
0
 public function testFilterDump()
 {
     $expected = 'body{baz:foo;foo:new;too:me}div.other,div.test{border:1px solid black}';
     $inputCss = 'body { foo:bar; too: me;} body { baz:foo; } body { foo: new }
     div.test { border: 1px solid black; }
     div.other { border: 1px solid black} ';
     $asset = new StringAsset($inputCss);
     $asset->ensureFilter($this->filter);
     $result = $asset->dump();
     $this->assertEquals($expected, $result);
 }
コード例 #3
0
 public function testFilter()
 {
     // Create twig env
     $twig = new \Twig_Environment($this->getLoader());
     // Create twig filter
     $filter = new TwigFilter($twig);
     // Create sample asset
     $asset = new StringAsset("{{ '<' | e('html') }}", array($filter));
     // Test asset content
     $this->assertEquals('&lt;', $asset->dump());
 }
コード例 #4
0
 public function combineThenDump()
 {
     // loop through leaves and add each raw asset
     $parts = array();
     $filtersAdded = $this->filters->all();
     foreach ($this as $asset) {
         if (!$filtersAdded) {
             $this->filters = new FilterCollection($asset->getFilters());
             $filtersAdded = true;
         }
         $parts[] = file_get_contents($asset->getSourceRoot() . '/' . $asset->getSourcePath());
     }
     $combinedAsset = new StringAsset(implode("\n", $parts), $this->filters->all());
     $combinedAsset->setLastModified($this->getLastModified());
     return $combinedAsset->dump();
 }
コード例 #5
0
ファイル: assets.php プロジェクト: boltphp/core
 public function processFile($path, $config = [])
 {
     $rel = b::param('rel', false, $config);
     $url = b::param('url', false, $config);
     $useGlobalFilters = b::param('useGlobalFilters', true, $config);
     // get the file
     $file = $this->getFile($path);
     $root = pathinfo($path)['dirname'];
     $ext = pathinfo($path)['extension'];
     // get it's tree
     $content = $file->getContent();
     if (empty($content)) {
         return $content;
     }
     $inc = [];
     // parse the string
     $found = $this->parseString($content, $root);
     if (b::param('filterOnly', false, $config) === 'true') {
         $found = ['filter' => $found['filter']];
     }
     $tree = $this->getCombinedTree($found, $ext);
     $reduce = function ($items, $reduce) {
         $resp = [];
         foreach ($items as $key => $files) {
             $resp[] = $key;
             $resp += $reduce($files, $reduce);
         }
         return $resp;
     };
     // loop through each file and append
     foreach (array_unique($reduce($tree, $reduce)) as $f) {
         if ($f === $path) {
             continue;
         }
         $inc[] = $this->processFile($f);
     }
     $source = false;
     $sourcePath = false;
     $targetPath = false;
     if ($url) {
         $parts = parse_url($url);
         $source = "{$parts['scheme']}://{$parts['host']}";
         $targetPath = trim($parts['path'], '/');
         $sourcePath = $targetPath . '/' . trim($rel, '/');
     }
     $inc[] = $content;
     $a = new StringAsset(implode("\n", $inc), [], $source, $sourcePath);
     if ($targetPath) {
         $a->setTargetPath($targetPath);
     }
     // use filters
     if ($useGlobalFilters !== false) {
         if (array_key_exists($ext, $this->_filters)) {
             foreach ($this->_filters[$ext] as $filter) {
                 if ($filter[1] === false and b::env() === 'dev') {
                     continue;
                 }
                 $a->ensureFilter(new $filter[0]());
             }
         }
         foreach ($this->_filters['*'] as $filter) {
             if ($filter[1] === false and b::env() === 'dev') {
                 continue;
             }
             $a->ensureFilter(new $filter[0]());
         }
     }
     $a->ensureFilter(new CssRewriteFilter());
     return trim($a->dump());
 }
コード例 #6
0
ファイル: Asset.php プロジェクト: chugga/basset
 /**
  * Build the asset.
  *
  * @param  bool  $production
  * @return string
  */
 public function build($production = false)
 {
     $filters = $this->prepareFilters($production);
     $asset = new StringAsset($this->getContent(), $filters->all(), dirname($this->absolutePath), basename($this->absolutePath));
     return $asset->dump();
 }
コード例 #7
0
 /**
  * Combines the script data from all minified scripts
  */
 protected function buildScriptData($where)
 {
     global $wp_scripts;
     $data = '';
     if (empty($this->scripts[$where])) {
         return '';
     }
     foreach ($this->scripts[$where] as $handle => $filepath) {
         $data .= $wp_scripts->print_extra_script($handle, false);
     }
     $asset = new StringAsset($data, array(new JSMinFilter()));
     return $asset->dump();
 }
コード例 #8
0
ファイル: Js.php プロジェクト: Tusko/WP-Anatomy
 /**
  * Combines the script data from all minified scripts
  *
  * @param string $where The page's place to dump the scripts in (header or footer)
  * @return string The script to include within the page
  */
 protected function buildScriptData($where)
 {
     $data = '';
     if (empty($this->localized[$where])) {
         return '';
     }
     foreach ($this->localized[$where] as $script) {
         $data .= $script;
     }
     $asset = new StringAsset($data, array(new JSqueezeFilter()));
     return $asset->dump();
 }
コード例 #9
0
ファイル: asset.php プロジェクト: jvillasante/cubanartjb
 /**
  * Compile the asset.
  * 
  * @return string
  */
 public function compile()
 {
     $filters = array();
     foreach ($this->filters as $name => $arguments) {
         if (class_exists($filter = "Assetic\\Filter\\{$name}") or class_exists($filter = "Basset\\Filter\\{$name}")) {
             $reflection = new ReflectionClass($filter);
             $filters[] = $reflection->newInstanceArgs((array) $arguments);
         }
     }
     $asset = new StringAsset($this->contents, $filters, dirname($this->path), $this->name);
     return $asset->dump();
 }
コード例 #10
0
ファイル: Compiler.php プロジェクト: creolab/assets
 /**
  * Compiles a given collection
  * @return void
  */
 public function run()
 {
     app('log')->debug("[ASSETS] Compiling collection '" . $this->collection->id . "'");
     // Collection contents
     $this->collection->contents = '';
     foreach ($this->collection->assets() as $asset) {
         if ($asset->type == 'css') {
             // Rewrite relative URL's
             $rewriteFilter = new \Creolab\Assets\Filters\CSSRewriteFilter($asset);
             // Dump contents
             $contents = $rewriteFilter->dump($asset);
         } else {
             // Dump contents
             $contents = $asset->contents();
         }
         // Assign to contents
         $this->collection->contents .= PHP_EOL . $asset->contents();
         $asset->contents = null;
     }
     // Filters
     $filters = array();
     foreach ($this->collection->filters() as $filter) {
         $filterClass = app('config')->get('assets::filters.' . $filter);
         if (class_exists($filterClass)) {
             $filters[] = new $filterClass();
         } else {
             app('log')->error('[ASSETS] Problem with filter "' . $filter . '". The associated class "' . $filterClass . '" was not found.', array('package' => 'ASSETS', 'module' => 'Compiler'));
         }
     }
     // Create the collection in Assetic
     try {
         // Clear the cache
         app('assets')->clearCache($this->collection->id);
         // Create string asset
         $asset = new StringAsset($this->collection->contents, $filters);
         // Directory
         $cachePath = public_path() . '/' . app('config')->get('assets::cache_path');
         if (!app('files')->exists($cachePath)) {
             app('files')->makeDirectory($cachePath, 0777, true);
         }
         // And write contents
         if ($this->collection->cacheFilePath) {
             app('files')->put($this->collection->cacheFilePath, $asset->dump());
         }
         $this->collection->contents = null;
     } catch (\Exception $e) {
         // echo '<pre>'; print_r($e->getMessage()); echo '</pre>';
         // app('files')->put($this->collection->cacheFilePath, $this->collection->contents());
     }
     // Finished
     app('events')->fire('assets.compiled');
     app('log')->debug("[ASSETS] Collection finished compiling '" . $this->collection->id . "'");
     return $this->collection->contents;
 }