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); }
public function render($view = 'index', $data = []) { $mv = new MiniView($this); $fileName = sprintf('%s/%s/%s.%s', $this->getOwner()->getRootPath(), $this->getOwner()->getContentPath(), $view, $this->extension); $content = $mv->renderFile($fileName, $data, true); return (new Parsedown())->text($content); }
public function decorate(RendererAwareInterface $owner, &$content, $data) { $template = empty($data['template']) ? $this->template : $data['template']; $view = new MiniView($this, sprintf('%s/%s', $owner->getRootPath(), $owner->getLayoutPath())); $view->setViewsPath(''); $data['content'] = $content; $content = $view->render($template, ['data' => (object) $data, 'view' => $view], true); }
public function input($documentation, $fileName) { $this->decorator->decorate($documentation); $this->_tempName = sprintf('%s.tmp', $this->_fileName); $this->_fileName = $fileName; $this->view = new MiniView($this, dirname($this->_tempName)); $this->_doc = $this->view->render(basename($this->_tempName), [], true); }
public function testIfWillPassVariableToViewWithRendererDetection() { $var = 'New Variable'; $view = new MiniView($this); $result = $view->render('passVariable3.twig', ['var' => $var], true); $this->assertInstanceOf(PhpRenderer::class, $view->getRenderer(), 'That renderer was reverted back to default renderer'); $this->assertSame($var, $result); }
public function generate() { $collection = $this->getCollection(); $sprites = $collection->getSprites(); $classes = ConstantsFactory::create($sprites); foreach ($classes as $class) { $definition = $this->mv->render('constants-class.latte', ['class' => $class], true); file_put_contents($class->getPath(), $definition); } }
public function __toString() { try { return $this->view->render('gallery', [], true); } catch (Exception $exc) { echo $exc->getTraceAsString(); } }
public function __toString() { try { return $this->mv->render(sprintf('%s/%s', $this->lang, 'contact-form'), [], true); } catch (Exception $exc) { echo $exc->getTraceAsString(); } }
public function render($view = 'index', $data = []) { $message = $this->_code; if (!empty($this->_message)) { $message .= ": {$this->_message}"; } header("HTTP/1.0 {$this->_code}"); $path = sprintf('%s/%s/_%s.php', $this->getOwner()->getRootPath(), $this->getOwner()->getContentPath(), $this->_code); if (file_exists($path)) { $mv = new MiniView($this, $this->getOwner()->getRootPath()); $mv->setViewsPath($this->getOwner()->getContentPath()); return $mv->render(sprintf('_%s', $this->_code), ['code' => $this->_code, 'message' => $this->_message], true); } return <<<HTML \t\t<h1>{$message}</h1> HTML; }
public function generate() { $destName = (new ReflectionClass(\Maslosoft\Mangan\Traits\AvailableCommands::class))->getFileName(); $srcName = $destName . 's'; $view = new MiniView($this); $cmd = new Command(); $commands = $cmd->listCommands()['commands']; $functions = []; foreach ($commands as $name => $cmdData) { if ($cmdData['adminOnly']) { continue; } $functions[] = $view->render('command', ['mongoName' => $name, 'name' => $this->_sanitize($name), 'help' => explode("\n", $cmdData['help'])], true); } $src = file_get_contents($srcName); $code = implode("\n", $functions) . "\n}"; $result = str_replace('}', $code, $src); file_put_contents($destName, $result); }
public static function generate(SpritePackageInterface $package) { $path = $package->getConstantsClassPath(); if (empty($path)) { return; } $className = $package->getConstantsClass(); $parts = explode('\\', $className); $name = array_pop($parts); $ns = implode('\\', $parts); $fileName = sprintf('%s/%s.php', $path, $name); if (!file_exists($fileName)) { $view = new MiniView(new self()); $params = ['tag' => '<?php', 'ns' => $ns, 'name' => $name]; $def = $view->render('constantsClass.latte', $params, true); $result = file_put_contents($fileName, $def); assert($result, new RuntimeException("Could not write into {$fileName}")); } }
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)); }
public function render($view = 'index', $data = []) { $mv = new MiniView($this, $this->getOwner()->getRootPath()); $mv->setViewsPath($this->getOwner()->getContentPath()); return $mv->render($view, $data, true); }
public function testIfWillForwardPropertyToOwner() { $view = new MiniView($this); $result = $view->render('forwardProperty', [], true); $this->assertSame($this->value, $result); }
public function __toString() { return $this->mv->render('sub-nav-recursive/nav', ['mv' => $this->mv], true); }
public function __toString() { return $this->mv->render('sub-nav', [], true); }
public function __toString() { return $this->mv->render('carousel', [], true); }
public function __toString() { return $this->mv->render('playlist', [], true); }