Skip to content

Commit

Permalink
changed the Poser signature
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Jun 29, 2014
1 parent c928abb commit bf68b89
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 38 deletions.
51 changes: 18 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
PHP badges poser
================

This is a php library that creates badges,
This is a php library that creates badges like ![badge-poser](badge-poser.svg) and ![I'm a badge](i_m-badge.svg) and ![dark](today-dark.svg),
according to [Shields specification](https://github.com/badges/shields#specification).

``` bash
________________
|_ _ _| _ _ | _ _ _ _ _ |
|_)(_|(_|(_|(/_ | |_)(_)_\(/_| |
_| |_|______________|
This library is used by https://poser.pugx.org.

## Use as command

#### 1. Create a project

``` bash
$ composer create-project badges/poser ~0.1
$ ln -s poser/bin/poser /usr/local/bin/poser
```

This library create this: ![badge-poser](badge-poser.svg) and ![I'm a badge](i_m-badge.svg) and ![dark](today-dark.svg)...
#### 2. lunch the command

Create an image

This library is used by the most used badge creator in php https://poser.pugx.org/
`$ poser license MIT blue -p "license.svg"`

Flush an image

`$ poser license MIT blue`

## Usage as library

Expand All @@ -29,37 +38,13 @@ This library is used by the most used badge creator in php https://poser.pugx.or
use PUGX\Poser\Poser;

$render = new SvgRender();
$poser = new Poser(array('svg' => $render));
$poser = new Poser(array($render));

echo $poser->generate('license', 'MIT', '428F7E', 'svg');
// or
echo $poser->generateFromURI('license-MIT-428F7E.svg');
```

## Use in your project as command
#### 1. Add to composer
`$ composer require badges/poser ~0.1`
or create a project
`$ composer create-project badges/poser ~0.1`
and make the link
`$ ln -s poser/bin/poser /usr/local/bin/poser`
#### 2. lunch the command
Creating an image
`$ poser license MIT blue -p "license.svg"`
Flushing the image
`$ poser license MIT blue`
## Encoding

Dashes `--``-` Dash
Expand Down
2 changes: 1 addition & 1 deletion spec/PUGX/Poser/PoserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PoserSpec extends ObjectBehavior
function let()
{
$render = new SvgRender();
$this->beConstructedWith(array('svg' => $render));
$this->beConstructedWith(array($render));
}

function it_is_initializable()
Expand Down
13 changes: 9 additions & 4 deletions src/Poser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class Poser
public function __construct($renders)
{
$this->renders = array();
if (!is_array($renders)) {
$renders = array($renders);
}

foreach ($renders as $format => $render) {
$this->addFormatRender($format, $render);
foreach ($renders as $render) {
$this->addFormatRender($render);
}
}

Expand Down Expand Up @@ -63,9 +66,11 @@ public function validFormats()
return array_keys($this->renders);
}

private function addFormatRender($format, RenderInterface $render)
private function addFormatRender(RenderInterface $render)
{
$this->renders[$format] = $render;
foreach ($render->supportedFormats() as $format) {
$this->renders[$format] = $render;
}
}

private function getRenderFor($format)
Expand Down
12 changes: 12 additions & 0 deletions src/Render/RenderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@

interface RenderInterface
{
/**
* Render a badge.
*
* @param Badge $badge
*
* @return string
*/
public function render(Badge $badge);

/**
* @return array the list of the supported format eg array('svg')
*/
public function supportedFormats();
}
12 changes: 12 additions & 0 deletions src/Render/SvgRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public function render(Badge $badge)
return $this->renderSvg(self::$template, $parameters);
}

/**
* Render a badge.
*
* @param Badge $badge
*
* @return string
*/
public function supportedFormats()
{
return array('svg');
}

private function stringWidth($text)
{
return $this->textSizeCalculator->calculateWidth($text);
Expand Down

0 comments on commit bf68b89

Please sign in to comment.