Skip to content

Commit 8ee56d2

Browse files
committed
Integrate gravatar image + GitHub link to README
1 parent dfb18c5 commit 8ee56d2

File tree

4 files changed

+111
-21
lines changed

4 files changed

+111
-21
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"require": {
77
"php": ">=8.0.0",
88
"symfony/console": "^5.3",
9-
"monolog/monolog": "^2.3"
9+
"monolog/monolog": "^2.3",
10+
"ph-7/ph2gravatar": "^1.0"
1011
},
1112
"require-dev": {
1213
"phpunit/phpunit": "^9.5",

src/Command/Markdown/Builder.php

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,46 @@
44

55
namespace PH7\PhpReadmeGeneratorFile\Command\Markdown;
66

7+
use PH7\PH2Gravatar\Gravatar\Image;
8+
use PH7\PhpReadmeGeneratorFile\DefaultValue;
9+
710
class Builder
811
{
9-
private string $title;
12+
private string $projectName;
1013

1114
private string $heading;
1215

1316
private string $description;
1417

18+
private string $requirements;
19+
1520
private string $authorName;
1621

1722
private string $authorEmail;
1823

24+
private string $authorWebpage;
25+
1926
private string $licenseType;
2027

28+
private string $licenseLink;
29+
30+
private string $gravatarImage;
31+
32+
private string $githubUsername;
33+
2134
public function __construct(array $data)
2235
{
23-
$this->title = $data['title'];
36+
$this->probjectName = $data['name'];
2437
$this->heading = $data['heading'];
2538
$this->description = $data['description'];
39+
$this->projectRequirements = $data['requirements'];
2640
$this->authorName = $data['author'];
2741
$this->authorEmail = $data['email'];
42+
$this->authorWebpage = $data['webpage'];
2843
$this->licenseType = $data['license'];
2944
$this->licenseLink = License::getLicenseLink($data['license']);
45+
$this->gravatarImage = $this->getGravatar();
46+
$this->githubUsername = $data['github'];
3047
}
3148

3249
public function save(string $path): bool|int
@@ -39,26 +56,39 @@ private function getContents(): string
3956
return $this->parse(file_get_contents(__DIR__ . '/view/readme-template.md'));
4057
}
4158

59+
private function getGravatar(): string
60+
{
61+
return Image::get($this->authorEmail, ['size' => DefaultValue::GRAVATAR_SIZE]);
62+
}
63+
4264
private function parse(string $contents): string
4365
{
4466
return str_ireplace(
4567
[
46-
':TITLE:',
68+
':PROJECT-NAME:',
4769
':HEADING:',
4870
':DESCRIPTION:',
49-
':AUTHOR:',
71+
':REQUIREMENTS:',
72+
':AUTHOR-NAME:',
5073
':EMAIL:',
51-
':LICENSE_NAME:',
52-
':LICENSE_LINK:'
74+
':AUTHOR-URL:',
75+
':LICENSE-NAME:',
76+
':LICENSE-LINK:',
77+
':GRAVATAR-IMAGE:',
78+
':GITHUB-USERNAME:',
5379
],
5480
[
55-
$this->title,
81+
$this->projectName,
5682
$this->heading,
5783
$this->description,
84+
$this->requirements,
5885
$this->authorName,
5986
$this->authorEmail,
87+
$this->authorWebpage,
6088
$this->licenseType,
6189
$this->licenseLink,
90+
$this->gravatarImage,
91+
$this->githubUsername,
6292
],
6393
$contents
6494
);

src/Command/Markdown/Generator.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ public function __construct()
2525

2626
protected function configure()
2727
{
28-
$this
29-
->setName('markdown:generate')
30-
->addArgument(
31-
'title',
32-
InputArgument::REQUIRED,
33-
'Project Name'
34-
);
28+
$this->setName('markdown:generate');
3529
}
3630

3731
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -77,18 +71,23 @@ private function treatFields(InputInterface $input, OutputInterface $output): ar
7771
$io = new SymfonyStyle($input, $output);
7872

7973
try {
74+
$name = $this->promptName($io);
8075
$heading = $this->promptHeading($io);
8176
$description = $this->promptDescription($io);
8277
$author = $this->promptAuthor($io);
8378
$email = $this->promptEmail($io);
79+
$webpage = $this->promptHomepageUrl($io);
80+
$githubUsername = $this->promptGithub($io);
8481
$license = $this->promptLicense($helper, $input, $output);
8582

8683
return [
87-
'title' => $input->getArgument('title'),
84+
'name' => $name,
8885
'heading' => $heading,
8986
'description' => $description,
9087
'author' => $author,
9188
'email' => $email,
89+
'webpage' => $webpage,
90+
'github' => $githubUsername,
9291
'license' => $license
9392
];
9493
} catch (EmptyFieldException $e) {
@@ -98,6 +97,17 @@ private function treatFields(InputInterface $input, OutputInterface $output): ar
9897
}
9998
}
10099

100+
private function promptName(SymfonyStyle $io): string
101+
{
102+
$heading = $io->ask('Project Name');
103+
104+
if (!$this->isFieldFilled($heading)) {
105+
throw new EmptyFieldException('Mention a name for your project 😺');
106+
}
107+
108+
return $heading;
109+
}
110+
101111
private function promptHeading(SymfonyStyle $io): string
102112
{
103113
$heading = $io->ask('Project Heading');
@@ -142,6 +152,29 @@ private function promptEmail(SymfonyStyle $io): string
142152
return $email;
143153
}
144154

155+
private function promptHomepageUrl(SymfonyStyle $io): string
156+
{
157+
$webpage = $io->ask('Author Webpage');
158+
159+
160+
if (!$this->isFieldFilled($webpage)) {
161+
throw new EmptyFieldException('Can you mention your homepage (.e.g website, GitHub profile, etc).');
162+
}
163+
164+
return $webpage;
165+
}
166+
167+
private function promptGithub(SymfonyStyle $io): string
168+
{
169+
$github = $io->ask('GitHub Username');
170+
171+
if (!$this->isFieldFilled($github)) {
172+
throw new EmptyFieldException('GitHub nickname is required.');
173+
}
174+
175+
return $github;
176+
}
177+
145178
private function promptLicense(HelperInterface $helper, InputInterface $input, OutputInterface $output): string
146179
{
147180
$question = new ChoiceQuestion(
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
1-
# :TITLE:
1+
# :PROJECT-NAME:
22

33
## :HEADING:
44

55
:DESCRIPTION:
66

7-
## About
7+
## ⛏ Requirements
88

9-
:AUTHOR:, :EMAIL:
9+
:REQUIREMENTS:
1010

11+
## 🏗 How to install it?
1112

12-
## License
13+
<!-- Add what you need here -->
1314

14-
[:LICENSE_NAME:](:LICENSE_LINK:)
15+
## 💭 How to use it?
16+
17+
<!-- Add what you need here -->
18+
19+
## 🪄 Author
20+
21+
I'm **[:AUTHOR-NAME:][:AUTHOR-URL:]**. A passionate, zen &amp; dedicated software engineer 😊
22+
23+
24+
![[github-url]][github-image]][github-url]
25+
26+
---
27+
28+
[![:AUTHOR-NAME:](:GRAVATAR:)](:AUTHOR-URL: ":AUTHOR-NAME:, a Software Developer")
29+
30+
## 📃 License
31+
32+
pH2Gravatar is distributed under [:LICENSE-NAME:](:LICENSE-LINK:) license 🚀 Enjoy! ❤️
33+
34+
<!-- GitHub's Markdown reference links -->
35+
[author-url]: :AUTHOR-URL:
36+
[license-url]: :LICENSE-LINK:
37+
[github-url]: https://github.com/:GITHUB-USERNAME:
38+
[github-image]: https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white
39+
40+
<!-- Generated by README Generator CLI: https://github.com/pH-7 -->

0 commit comments

Comments
 (0)