Exemple #1
0
 private function addSprite(SpriteImage $sprite)
 {
     $item = new ConstItem();
     $item->name = Namer::nameConstant($this->package, $sprite);
     $item->value = Namer::nameCssClass($this->package, $sprite);
     $this->constants[$item->name] = $item;
 }
 public function __construct(SpriteImage $sprite)
 {
     foreach ($sprite->packages as $package) {
         $this->cssClasses[] = Namer::nameCssClass($package, $sprite);
     }
     $this->cssClass = $this->cssClasses[0];
     $this->cssClasses = array_unique($this->cssClasses);
     $this->image = file_get_contents($sprite->getFullPath());
     $classes = ConstantsFactory::create([$sprite]);
     foreach ($classes as $class) {
         foreach ($class->constants as $const) {
             $name = $const->name;
             $this->constants[] = sprintf('%s\\%s::%s', $class->ns, $class->name, $name);
             $this->shortConstants[] = sprintf('%s::%s', $class->name, $name);
             $this->hasConstants = true;
         }
     }
 }
Exemple #3
0
 public function generate()
 {
     $collection = $this->getCollection();
     $config = $this->getConfig();
     FolderChecker::check($config);
     $css = [];
     $squares = [];
     $rects = [];
     foreach ($collection->getSprites() as $image) {
         if ($image->isSquare()) {
             $squares[$image->width] = $image->width;
         } else {
             $size = sprintf('%sx%s', $image->width, $image->height);
             $rects[$size] = [$image->width, $image->height];
         }
     }
     // Square icons
     foreach ($squares as $size) {
         $params = ['prefix' => $config->iconCssClass, 'size' => $size];
         $css[] = $this->mv->render('css-square.latte', $params, true);
     }
     // Rectangle icons
     foreach ($rects as $size) {
         $params = ['prefix' => $config->iconCssClass, 'width' => $size[0], 'height' => $size[1]];
         $css[] = $this->mv->render('css-rect.latte', $params, true);
     }
     // Generate css for each image
     foreach ($collection->getGroups() as $group) {
         $top = $group->height;
         foreach ($group->sprites as $image) {
             foreach ($image->packages as $package) {
                 $params = ['cssClass' => Namer::nameCssClass($package, $image), 'horizontal' => -$group->offset, 'vertical' => $top - $group->height];
                 $css[] = $this->mv->render('css-icon.latte', $params, true);
             }
             // NOTE: This must be in sprites loop, not packages loop
             $top -= $image->height;
         }
     }
     $filename = sprintf('%s/%s.css', $config->generatedPath, $config->basename);
     file_put_contents($filename, implode("\n", $css));
 }