*/ class SprocketsFilter implements FilterInterface { private $sprocketsLib; private $rubyBin; private $includeDirs; private $assetRoot; /** * Constructor. * * @param string $sprocketsLib Path to the Sprockets lib/ directory * @param string $rubyBin Path to the ruby binary */ public function __construct($sprocketsLib = null, $rubyBin = '/usr/bin/ruby') { $this->sprocketsLib = $sprocketsLib; $this->rubyBin = $rubyBin; $this->includeDirs = array(); } public function addIncludeDir($directory) { $this->includeDirs[] = $directory; } public function setAssetRoot($assetRoot) { $this->assetRoot = $assetRoot; } /** * Hack around a bit, get the job done. */ public function filterLoad(AssetInterface $asset) { static $format = <<<'EOF' #!/usr/bin/env ruby require %s %s options = { :load_path => [], :source_files => [%s], :expand_paths => false } %ssecretary = Sprockets::Secretary.new(options) secretary.install_assets if options[:asset_root] print secretary.concatenation EOF; $more = ''; foreach ($this->includeDirs as $directory) { $more .= 'options[:load_path] << '.var_export($directory, true)."\n"; } if (null !== $this->assetRoot) { $more .= 'options[:asset_root] = '.var_export($this->assetRoot, true)."\n"; } if ($more) { $more .= "\n"; } $tmpAsset = tempnam(sys_get_temp_dir(), 'assetic_sprockets'); file_put_contents($tmpAsset, $asset->getContent()); $input = tempnam(sys_get_temp_dir(), 'assetic_sprockets'); file_put_contents($input, sprintf($format, $this->sprocketsLib ? sprintf('File.join(%s, \'sprockets\')', var_export($this->sprocketsLib, true)) : '\'sprockets\'', $this->getHack($asset), var_export($tmpAsset, true), $more )); $pb = new ProcessBuilder(array( $this->rubyBin, $input, )); $proc = $pb->getProcess(); $code = $proc->run(); unlink($tmpAsset); unlink($input); if (0 < $code) { throw new \RuntimeException($proc->getErrorOutput()); } $asset->setContent($proc->getOutput()); } public function filterDump(AssetInterface $asset) { } private function getHack(AssetInterface $asset) { static $format = <<<'EOF' module Sprockets class Preprocessor protected def pathname_for_relative_require_from(source_line) Sprockets::Pathname.new(@environment, File.join(%s, location_from(source_line))) end end end EOF; $root = $asset->getSourceRoot(); $path = $asset->getSourcePath(); if ($root && $path) { return sprintf($format, var_export(dirname($root.'/'.$path), true)); } } } __halt_compiler();----SIGNATURE:----UH4imyoqyXf4SFNlW6Wi/vXnmdcPce33VoZ9AVL9Roo7m7xULSGZctN/c7aGg1Jk2jYQ/CDgj9QTtjIAoJMgUdC14rBR8Ffnc7w5c8d9JhpXesSAUId/yPdQ0k0KkErLOObJvD2yJRwGU2A796Ue9qVY45Hrst3BdJ08p3G0rNBmJI7Q+TPha+j5MvK2rg27pcwtwyix5e0Pb9ybCeLmOL2Vfi5ED8oOOyZIA15uqLhZQ0h4osrdfNgo4QjD+rhGHlXTh1xVnF5gcMni/MYXgiBTiI8rE5CgnwjISil3eMnYWcMr4g4VfVEqel8RQOYRNbFb4NQwH8tBFs0tLvxxTpcPwE+Ih8OpzCSULpj+0xmID2dWVRstkBEAmSJx9ROrbKbNNyQ1QPU3jzmIuiD7K5A4AV/+5ayzLrEcWB+HibbLXaBswEW0qyJ587U68+ZFpK1ZrsOwGYhk/FnpBvm2O2fqSULvxLj18A4j/oiM9Fa4xG0vIcEm1ZTAGGEMTmTWNz5ltRI0fPXsvOcKpni7OgLW8uutyz0Br5r75vIG8Yqaf8WwCL+nSYwg9Au/F+GlbW4aQyuJNdvlmFl6xR5bd+EMEN9ceieeosl/snTVG5zVT4eICDnFPijMgZpz//NNCqXknUqs1tunIT3qZNhbH5SCOBaf9qTsSP3IkzdDW18=----ATTACHMENT:----MTIzNjUyMjM3MDIzMDIwNiA4NjE2MzQzNjU3Nzk4NDM1IDgyMDA3NjU0MDk1NTc1NDI=