Example #1
0
 /**
  * Compile an asset collection.
  *
  * @param  Basset\Collection  $collection
  * @return void
  */
 protected function compile(Collection $collection)
 {
     $force = isset($_SERVER['CLI']['FORCE']);
     // If the compile path does not exist attempt to create it.
     if (!File::exists($this->compilePath)) {
         File::mkdir($this->compilePath);
     }
     $groups = $collection->getAssets();
     if (empty($groups)) {
         echo "The collection '{$collection->getName()}' has no assets to compile.\n";
     }
     foreach ($groups as $group => $assets) {
         $path = $this->compilePath . '/' . $collection->getCompiledName($group);
         // We only compile a collection if a compiled file doesn't exist yet or if a change to one of the assets
         // in the collection is detected by comparing the last modified times.
         if (File::exists($path) and File::modified($path) >= $collection->lastModified($group)) {
             // If the force flag has been set then we'll recompile, otherwise this collection does not need
             // to be changed.
             if (!$force) {
                 echo "The {$group}s for the collection '{$collection->getName()}' do not need to be compiled.\n";
                 continue;
             }
         }
         $compiled = $collection->compile($group);
         echo "Successfully compiled {$collection->getCompiledName($group)}\n";
         File::put($path, $compiled);
     }
 }
Example #2
0
 /**
  * Prepares the response before sending to the browser.
  * 
  * @return Laravel\Response
  */
 public function prepare()
 {
     $collection = new Collection(null);
     $asset = $this->getAssetFromUri(URI::current());
     if (!($asset = $collection->add($asset))) {
         return;
     }
     // Create a new LaravelResponse object with the contents of the asset. Once we have the
     // response object we can adjust the headers before sending it to the browser.
     $this->response = new LaravelResponse($collection->compile($asset->getGroup()));
     switch ($asset->getGroup()) {
         case 'style':
             $this->response->header('content-type', 'text/css');
             break;
         case 'script':
             $this->response->header('content-type', 'application/javascript');
             break;
     }
     return $this;
 }