Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit 59ebdfb

Browse files
committed
Merge pull request #320 from ins0/feature/parsedown
[WIP] feature/parsedown
2 parents 7c9b63b + e1d9717 commit 59ebdfb

File tree

6 files changed

+83
-7
lines changed

6 files changed

+83
-7
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"zendframework/zendframework": "~2.3.0",
1010
"rwoverdijk/assetmanager": "1.3.*",
1111
"evandotpro/edp-github": "dev-master",
12-
"evandotpro/edp-markdown": "0.2.*",
1312
"evandotpro/edp-module-layouts": "1.0.*",
1413
"zf-commons/zfc-user": "1.0.*",
1514
"zfcampus/zf-development-mode": "~2.0",

config/application.config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'User',
1414
'EdpModuleLayouts',
1515
'ZfModule',
16-
'EdpMarkdown',
1716
],
1817
'module_listener_options' => [
1918
'config_glob_paths' => [

module/Application/src/Application/Service/RepositoryRetriever.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,40 @@ public function getUserRepositories($user, $params = [])
5858
* @param string $user
5959
* @param string $module
6060
* @param string $filePath
61+
* @param bool $parseMarkdown
6162
*
6263
* @return bool|string
6364
*/
64-
public function getRepositoryFileContent($user, $module, $filePath)
65+
public function getRepositoryFileContent($user, $module, $filePath, $parseMarkdown = false)
6566
{
6667
$contentResponse = $this->getRepositoryFileMetadata($user, $module, $filePath);
6768

6869
if (!isset($contentResponse->content)) {
6970
return false;
7071
}
7172

72-
return base64_decode($contentResponse->content);
73+
$content = base64_decode($contentResponse->content);
74+
if ($content && $parseMarkdown) {
75+
return $this->requestContentMarkdown($content);
76+
}
77+
78+
return $content;
79+
}
80+
81+
/**
82+
* Request content as parsed markdown
83+
*
84+
* @param string $content
85+
*
86+
* @return string|null
87+
*/
88+
private function requestContentMarkdown($content)
89+
{
90+
try {
91+
return $this->githubClient->api('markdown')->render($content);
92+
} catch (RuntimeException $e) {
93+
return null;
94+
}
7395
}
7496

7597
/**

module/Application/test/ApplicationTest/Service/RepositoryRetrieverTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ApplicationTest\Service;
44

55
use Application\Service\RepositoryRetriever;
6+
use EdpGithub;
67
use EdpGithub\Api;
78
use EdpGithub\Collection;
89
use EdpGithub\Listener\Exception;
@@ -77,6 +78,61 @@ public function testCanRetrieveRepositoryFileContent()
7778
$this->assertEquals('foo', $response);
7879
}
7980

81+
public function testRepositoryContentCanParsedMarkdown()
82+
{
83+
$content = 'repository file __FOO__ content';
84+
$markdown = function($content) {
85+
return str_replace('__FOO__', 'bar', $content);
86+
};
87+
88+
$apiMock = $this->getMock(Api\Markdown::class, ['content','render']);
89+
$apiMock
90+
->expects($this->once())
91+
->method('render')
92+
->with($this->equalTo($content))
93+
->willReturn($markdown($content));
94+
95+
$apiMock
96+
->expects($this->any())
97+
->method('content')
98+
->willReturn(json_encode(['content' => base64_encode($content)]));
99+
100+
$clientMock = $this->getMock(EdpGithub\Client::class);
101+
$clientMock->expects($this->any())
102+
->method('api')
103+
->willReturn($apiMock);
104+
105+
$service = new RepositoryRetriever($clientMock);
106+
$contentMarkdown = $service->getRepositoryFileContent('foo', 'bar', 'foo.md', true);
107+
108+
$this->assertEquals('repository file bar content', $contentMarkdown);
109+
}
110+
111+
public function testRepositoryContentMarkdownFails()
112+
{
113+
$content = 'repository file __FOO__ content';
114+
$apiMock = $this->getMock(Api\Markdown::class, ['content','render']);
115+
$apiMock
116+
->expects($this->once())
117+
->method('render')
118+
->willThrowException(new Exception\RuntimeException);
119+
120+
$apiMock
121+
->expects($this->any())
122+
->method('content')
123+
->willReturn(json_encode(['content' => base64_encode($content)]));
124+
125+
$clientMock = $this->getMock(EdpGithub\Client::class);
126+
$clientMock->expects($this->any())
127+
->method('api')
128+
->willReturn($apiMock);
129+
130+
$service = new RepositoryRetriever($clientMock);
131+
$contentMarkdown = $service->getRepositoryFileContent('foo', 'bar', 'foo.md', true);
132+
133+
$this->assertNull($contentMarkdown);
134+
}
135+
80136
public function testResponseContentMissingOnGetRepositoryFileContent()
81137
{
82138
$payload = [];

module/ZfModule/src/ZfModule/Controller/IndexController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function viewAction()
5858
return $this->notFoundAction();
5959
}
6060

61-
$readme = $this->repositoryRetriever->getRepositoryFileContent($vendor, $module, 'README.md');
61+
$readme = $this->repositoryRetriever->getRepositoryFileContent($vendor, $module, 'README.md', true);
6262
$license = $this->repositoryRetriever->getRepositoryFileContent($vendor, $module, 'LICENSE');
6363
$composerConf = $this->repositoryRetriever->getRepositoryFileContent($vendor, $module, 'composer.json');
6464

module/ZfModule/view/zf-module/index/view.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
<div class="tab-content">
1515
<div class="tab-pane active" id="readme">
16-
<?php if ($readme): ?>
17-
<?php echo $this->sanitizeHtml($this->markdown($this->readme)); ?>
16+
<?php if($readme): ?>
17+
<?php echo $this->sanitizeHtml($this->readme); ?>
1818
<?php else: ?>
1919
No README file found for this Module
2020
<?php endif; ?>

0 commit comments

Comments
 (0)