Exemplo n.º 1
0
 public function generate()
 {
     $collection = $this->getCollection();
     $config = $this->getConfig();
     FolderChecker::check($config);
     $hasConsts = false;
     $sprites = [];
     foreach ($collection->getSprites() as $sprite) {
         $cSprite = new CheatSheetSprite($sprite);
         $sprites[] = $cSprite;
         if (!$hasConsts && $cSprite->hasConstants) {
             $hasConsts = true;
         }
     }
     uasort($sprites, [$this, 'compare']);
     $table = $this->mv->render('cheat-sheet.latte', ['sprites' => $sprites, 'hasConsts' => $hasConsts], true);
     // Generate raw table
     $filename = sprintf('%s/%s-table.html', $config->generatedPath, $config->basename);
     file_put_contents($filename, $table);
     $cssFileName = sprintf('%s/%s.css', $config->generatedPath, $config->basename);
     $pngFileName = sprintf('%s/%s.png', $config->generatedPath, $config->basename);
     $pngImage = base64_encode(file_get_contents($pngFileName));
     $pattern = sprintf('url(%s.png)', $config->basename);
     $replace = sprintf('url(data:image/png;base64,%s)', $pngImage);
     $cssContents = file_get_contents($cssFileName);
     $css = str_replace($pattern, $replace, $cssContents);
     // Generate index
     $params = ['table' => $table, 'css' => $css, 'hasConsts' => $hasConsts];
     $index = $this->mv->render('cheat-sheet-index.latte', $params, true);
     $indexFilename = sprintf('%s/%s-index.html', $config->generatedPath, $config->basename);
     file_put_contents($indexFilename, $index);
 }
Exemplo n.º 2
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));
 }