Skip to content

Commit

Permalink
Merge pull request PUGX#61 from liuggio/master
Browse files Browse the repository at this point in the history
fixed composer alias + repository on one text field
  • Loading branch information
leopro committed Jun 10, 2013
2 parents 99e5661 + 4f8c5d6 commit 6f2be49
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "1.0-dev"
}
}
}
21 changes: 16 additions & 5 deletions src/PUGX/BadgeBundle/Controller/SnippetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ class SnippetController extends ContainerAware
*/
public function allAction()
{
$username = $this->container->get('request')->get('username');
$repository = $this->container->get('request')->get('repository');
$repository = sprintf('%s/%s', $username, $repository);
$response = new JsonResponse();

if (!$this->isValidRepositoryName($repository)) {
$response->setData(array('msg' => 'Package not found. Please check the package name. eg. (symfony/symfony)'));
$response->setStatusCode(404);
return $response;
}

try {
//Check if repository exists
$this->container->get('package_manager')->fetchPackage($repository);

$badges = $this->container->get('snippet_generator')->generateAllSnippets($repository);
$response->setData($badges);
} catch(ClientErrorResponseException $e) {
Expand All @@ -53,4 +53,15 @@ public function allAction()

return $response;
}

/**
* Validates a repository name.
*
* @param string $repository
* @return Boolean
*/
private function isValidRepositoryName($repository)
{
return (preg_match('/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?/', $repository) === 1);
}
}
2 changes: 1 addition & 1 deletion src/PUGX/BadgeBundle/Resources/public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ body {
}
/* Main marketing message and sign up button */
.jumbotron {
margin: 60px 0;
margin: 30px 0;
text-align: center;
}
.jumbotron h1 {
Expand Down
13 changes: 6 additions & 7 deletions src/PUGX/BadgeBundle/Resources/views/Page/home.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<h1>Badge Poser</h1>
<p class="lead">Pimp your README!</p>
<p class="lead">
<a href="https://packagist.org/packages/pugx/badge-poser"><img style="max-width:100%;" alt="Latest Stable Version" src="https://poser.pugx.org/pugx/badge-poser/version.png"></a>
<a target="_blank" href="http:https://travis-ci.org/PUGX/badge-poser"><img src="https://secure.travis-ci.org/PUGX/badge-poser.png" /></a>
</p>
</div>
Expand All @@ -42,14 +43,12 @@
Use shields for you <a href="https://packagist.org">packagist.org</a> repository, that shows how many times your project has been downloaded from Packagist.org or its latest stable version.
</p>
<hr class="styled">
<h3 class="centered-content">Create your own Badge</h3>
<h3 class="centered-content">Show the markdown for your Badges</h3>
<form id="generate-form" action="{{ url('pugx_snippet_all') }}" class="form-inline centered-content">
<input type="text" name="username" class="input-small" placeholder="Username">
/
<input type="text" name="repository" class="input" placeholder="Repository">
<button id="generate" class="btn">Generate</button>
<input type="text" name="repository" class="input" placeholder="vendor/repository">
<button id="generate" class="btn">Show</button>
</form>
<p class="centered-content"><small >put the following snippets in your README:</small></p>
<p class="centered-content"><small >put the following snippets in your README.markdown:</small></p>

<div id="badges">
<div>
Expand All @@ -70,7 +69,7 @@
</div>
<div>
<h4>Latest Unstable Version <img class="pull-right spinned" id="latest_unstable_version_img" src="https://poser.pugx.org/symfony/symfony/v/unstable.png"></h4>
<pre id="latest_unstablejs_version_markdown" class="prettyprint">[![Latest Unstable Version](https://poser.pugx.org/symfony/symfony/v/unstable.png)](https://packagist.org/packages/symfony/symfony)</pre>
<pre id="latest_unstable_version_markdown" class="prettyprint">[![Latest Unstable Version](https://poser.pugx.org/symfony/symfony/v/unstable.png)](https://packagist.org/packages/symfony/symfony)</pre>
</div>
</div>
</article>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testAllAction()

$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $this->packagistClient);
$crawler = $client->request('GET','/snippet/all/?username=pugx&repository=badge-poser');
$crawler = $client->request('GET','/snippet/all/?repository=pugx/badge-poser');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertEquals($expectedData, $client->getResponse()->getContent());
}
Expand Down

0 comments on commit 6f2be49

Please sign in to comment.