function it_should_render_a_license_mit_exactly_like_this_svg() { $template = <<<EOF <svg xmlns="http://www.w3.org/2000/svg" width="40" height="20"> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="a"> <rect width="40" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#a)"> <rect width="20" height="20" fill="#555"/> <rect x="20" width="20" height="20" fill="#007ec6"/> <rect width="40" height="20" fill="url(#b)"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="11" y="15" fill="#010101" fill-opacity=".3">license</text> <text x="11" y="14">license</text> <text x="29" y="15" fill="#010101" fill-opacity=".3">MIT</text> <text x="29" y="14">MIT</text> </g> </svg> EOF; $badge = Badge::fromURI('license-MIT-blue.svg'); $this->render($badge)->__toString()->shouldBeLike($template); }
function it_should_render_a_license_mit_exactly_like_this_svg() { $fixture = __DIR__ . '/../../../Fixtures/flat.svg'; $template = file_get_contents($fixture); $badge = Badge::fromURI('license-MIT-blue.svg'); $this->render($badge)->__toString()->shouldBeLike($template); }
function it_should_not_render_non_svg_xml($calculator) { $templatesDir = __DIR__ . '/../../../Fixtures/xml_template'; $this->beConstructedWith($calculator, $templatesDir); $badge = Badge::fromURI('version-stable-97CA00.svg'); $this->shouldThrow(new \RuntimeException('Generated xml is not a SVG'))->duringRender($badge); }
public function positiveConversionExamples() { $colorNames = Badge::getColorNamesAvailable(); $data = array(); foreach ($colorNames as $colorName) { $data[] = array($colorName, null); } return $data; }
function it_should_be_constructed_by_fromURI_factory_method_escaping_correctly_with_dashes() { $this->beConstructedWith('a', 'b', '97CA00', 'svg'); $input = 'I--m--liuggio-b-97CA00.svg'; $assertInput = 'I-m-liuggio-b-97CA00.svg'; $it = \PUGX\Poser\Badge::fromURI($input); if ((string) $it !== $assertInput) { throw new Exception(sprintf("from[%s] wants[%s] having[%s]\n", $input, $assertInput, (string) $it)); } }
/** * @param Badge $badge * * @return mixed */ public function render(Badge $badge) { $parameters = array(); $parameters['vendorWidth'] = $this->stringWidth($badge->getSubject()); $parameters['valueWidth'] = $this->stringWidth($badge->getStatus()); $parameters['totalWidth'] = $parameters['valueWidth'] + $parameters['vendorWidth']; $parameters['vendorColor'] = self::VENDOR_COLOR; $parameters['valueColor'] = $badge->getHexColor(); $parameters['vendor'] = $badge->getSubject(); $parameters['value'] = $badge->getStatus(); $parameters['vendorStartPosition'] = round($parameters['vendorWidth'] / 2, 1) + 1; $parameters['valueStartPosition'] = $parameters['vendorWidth'] + round($parameters['valueWidth'] / 2, 1) - 1; return $this->renderSvg(self::$template, $parameters, $badge->getFormat()); }
function it_should_render_a_svg() { $badge = Badge::fromURI('version-stable-97CA00.svg'); $this->render($badge)->shouldBeAValidSVGImage(); }
/** * @param Badge $badge * * @return array */ private function buildParameters(Badge $badge) { $parameters = array(); $parameters['vendorWidth'] = $this->stringWidth($badge->getSubject()); $parameters['valueWidth'] = $this->stringWidth($badge->getStatus()); $parameters['totalWidth'] = $parameters['valueWidth'] + $parameters['vendorWidth']; $parameters['vendorColor'] = static::VENDOR_COLOR; $parameters['valueColor'] = $badge->getHexColor(); $parameters['vendor'] = $badge->getSubject(); $parameters['value'] = $badge->getStatus(); $parameters['vendorStartPosition'] = round($parameters['vendorWidth'] / 2, 1) + 1; $parameters['valueStartPosition'] = $parameters['vendorWidth'] + round($parameters['valueWidth'] / 2, 1) - 1; return $parameters; }
/** * Generate and Render a badge according to the format from an URI, * eg license-MIT-blue.svg or I_m-liuggio-yellow.svg. * * @param $string * @return Image */ public function generateFromURI($string) { $badge = Badge::fromURI($string); return $this->getRenderFor($badge->getFormat())->render($badge); }
protected function configure() { $this->init(); $this->setName('generate')->setDescription('Create a badge you are a Poser.')->addArgument('subject', InputArgument::OPTIONAL, 'The subject eg. `license`')->addArgument('status', InputArgument::OPTIONAL, 'The status example `MIT`')->addArgument('color', InputArgument::OPTIONAL, 'The hexadecimal color eg. `97CA00` or the name [' . join(', ', Badge::getColorNamesAvailable()) . ']')->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'The format of the image eg. `svg`, formats available [' . join(', ', $this->poser->validFormats()) . ']')->addOption('path', 'p', InputOption::VALUE_REQUIRED, 'The path of the file to save the create eg. `/tmp/license.svg`'); }