Example #1
0
 /**
  * Build a development collection.
  *
  * @param  \Basset\Collection  $collection
  * @param  string  $group
  * @return void
  * @throws \Basset\Exceptions\BuildNotRequiredException
  */
 public function buildAsDevelopment(Collection $collection, $group)
 {
     // Get the assets of the given group from the collection. The collection is also responsible
     // for handling any ordering of the assets so that we just need to build them.
     $assets = $collection->getAssetsWithoutRaw($group);
     $entry = $this->manifest->make($identifier = $collection->getIdentifier());
     // If the collection definition has changed when compared to the manifest entry or if the
     // collection is being forcefully rebuilt then we'll reset the development assets.
     if ($this->collectionDefinitionHasChanged($assets, $entry, $group) or $this->force) {
         $entry->resetDevelopmentAssets($group);
     } else {
         $assets = $assets->filter(function ($asset) use($entry) {
             return !$entry->hasDevelopmentAsset($asset) or $asset->getBuildPath() != $entry->getDevelopmentAsset($asset);
         });
     }
     if (!$assets->isEmpty()) {
         foreach ($assets as $asset) {
             $path = "{$this->buildPath}/{$identifier}/{$asset->getBuildPath()}";
             // If the build directory does not exist we'll attempt to recursively create it so we can
             // build the asset to the directory.
             !$this->files->exists($directory = dirname($path)) and $this->files->makeDirectory($directory, 0777, true);
             $this->files->put($path, $this->gzip($asset->build()));
             // Add the development asset to the manifest entry so that we can save the built asset
             // to the manifest.
             $entry->addDevelopmentAsset($asset);
         }
     } else {
         throw new BuildNotRequiredException();
     }
 }
Example #2
0
 /**
  * Get the collections identifier from a collection instance.
  * 
  * @param  string|\Basset\Collection  $collection
  * @return string
  */
 protected function getCollectionNameFromInstance($collection)
 {
     return $collection instanceof Collection ? $collection->getIdentifier() : $collection;
 }
Example #3
0
 /**
  * Serve a development collection.
  * 
  * @param  \Basset\Collection  $collection
  * @param  string  $group
  * @param  string  $format
  * @return array
  */
 protected function serveDevelopmentCollection(Collection $collection, $group, $format)
 {
     $identifier = $collection->getIdentifier();
     // Before we fetch the collections manifest entry we'll try to build the collection
     // again if there is anything outstanding. This doesn't have a huge impact on
     // page loads time like trying to dynamically serve each asset.
     $this->tryDevelopmentBuild($collection, $group);
     $entry = $this->getCollectionEntry($collection);
     $responses = array();
     foreach ($collection->getAssetsWithRaw($group) as $asset) {
         if (!$asset->isRaw() and $path = $entry->getDevelopmentAsset($asset)) {
             $path = $this->prefixBuildPath($identifier . '/' . $path);
         } else {
             $path = $asset->getRelativePath();
         }
         $responses[] = $this->{'create' . studly_case($group) . 'Element'}($path, $format);
     }
     return $this->formatResponse($responses);
 }
Example #4
0
 /**
  * Clean collection development files.
  * 
  * @param  \Basset\Collection  $collection
  * @param  \Basset\Manifest\Entry  $entry
  * @return void
  */
 protected function cleanDevelopmentFiles(Collection $collection, Entry $entry)
 {
     foreach ($entry->getDevelopmentAssets() as $assets) {
         foreach ($assets as $asset) {
             $wildcardPath = $this->replaceFingerprintWithWildcard($asset);
             $this->deleteMatchingFiles($this->buildPath . '/' . $collection->getIdentifier() . '/' . $wildcardPath, array_values($assets));
         }
     }
 }