Skip to content

Refactoring #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

#for documentation
GITHUB_ACCESS_TOKEN=
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
- Создать запрос на добавление примера кода или статьи.
- Добавить ссылки на полезные ресурсы или пакеты.



## Установка

```bash
composer install
php artisan migrate
npm run dev
```

## Переменные окружения
```shell
#Для сравнивания документации из Laravel
GITHUB_ACCESS_TOKEN=
```


## Связаться с нами

Мы всегда открыты для обратной связи, вопросов и предложений. Вы можете связаться с нами через телеграм:
Expand Down
52 changes: 22 additions & 30 deletions app/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Models\Document;
use Exception;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -75,26 +77,21 @@ public function __construct(string $version, string $file)

try {
$this->variables = Yaml::parse($variables);
}catch (\Throwable){

} catch (\Throwable) {
}
}

/**
* Get the rendered view of a documentation page.
*
* @param string $view The view name.
*
* @return \Illuminate\Contracts\View\View The rendered view of the documentation page.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function view(string $view)
public function view(string $viewName): View
{
$content = Str::of($this->page)
->replace('{{version}}', $this->version)
->replace('{note}','⚠️')
->replace('{tip}','💡️')
->replace('{note}', '⚠️')
->replace('{tip}', '💡️')
->after('---')
->after('---')
->markdown();
Expand All @@ -104,7 +101,7 @@ public function view(string $view)
'edit' => $this->goToGitHub(),
]);

return view($view, $all);
return view($viewName, $all);
}

/**
Expand Down Expand Up @@ -177,9 +174,9 @@ public function docsToArray(string $html): array
*
* @param string $version The version of the Laravel documentation.
*
* @return \Illuminate\Support\Collection A collection of Docs instances.
* @return Collection<int, Docs> A collection of Docs instances.
*/
static public function every(string $version): \Illuminate\Support\Collection
public static function every(string $version): Collection
{
$files = Storage::disk('docs')->allFiles($version);

Expand All @@ -190,12 +187,7 @@ static public function every(string $version): \Illuminate\Support\Collection
->map(fn(string $path) => new static($version, $path));
}

/**
* Fetch the number of commits behind the current commit.
*
* @return int The number of commits behind.
*/
public function fetchBehind(): int
public function countCommitsBehindCurrent(): int
{
throw_unless(isset($this->variables['git']), new Exception("Document {$this->path} does not have a git hash"));

Expand Down Expand Up @@ -235,7 +227,7 @@ public function goToOriginal(): string
*
* @return string
*/
static public function compareLink(string $version, string $hash): string
public static function compareLink(string $version, string $hash): string
{
$compactHash = Str::of($hash)->limit(7, '')->toString();

Expand All @@ -245,7 +237,7 @@ static public function compareLink(string $version, string $hash): string
/**
* Get the Document model for the documentation page.
*
* @return \App\Models\Document The Document model.
* @return Document The Document model.
*/
public function getModel(): Document
{
Expand All @@ -259,18 +251,18 @@ public function getModel(): Document
return $this->model;
}

/**
* @return int
*/
public function behind():int
public function countCommitsBehind(): int
{
return $this->getModel()->behind;
return $this->getModel()->count_commits_behind;
}

/**
* @return string
*/
public function isOlderVersion()

public function translationIsLagsBehind(): bool
{
return $this->getModel()->count_commits_behind > 0;
}

public function isOlderVersion(): bool
{
return $this->version !== static::DEFAULT_VERSION;
}
Expand All @@ -283,7 +275,7 @@ public function isOlderVersion()
public function update()
{
$this->getModel()->fill([
'behind' => $this->fetchBehind(),
'count_commits_behind' => $this->countCommitsBehindCurrent(),
'current_commit' => $this->variables['git'],
])->save();
}
Expand Down
17 changes: 4 additions & 13 deletions app/Http/Controllers/DocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@

use App\Docs;
use App\Models\Document;
use Illuminate\Http\Request;
use Illuminate\Contracts\View\View;

class DocsController extends Controller
{
/**
* Show a documentation page.
*
* @param string $version
* @param string $page
*
* @return \Illuminate\View\View
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation')
public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation'): View
{
$docs = new Docs($version, $page);

Expand All @@ -29,15 +25,10 @@ public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'in
]);
}

/**
* @param string $version
*
* @return \Illuminate\Contracts\View\View
*/
public function status(string $version = Docs::DEFAULT_VERSION)
public function status(string $version = Docs::DEFAULT_VERSION): View
{
$documents = Document::where('version', $version)
->orderByDesc('behind')
->orderByDesc('count_commits_behind')
->get();

return view('pages.status', [
Expand Down
7 changes: 4 additions & 3 deletions app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class Document extends Model
{
use HasFactory, HasUuids;
use HasFactory;
use HasUuids;

/**
* @var string[]
Expand All @@ -18,7 +19,7 @@ class Document extends Model
'id',
'version',
'file',
'behind',
'count_commits_behind',
'current_commit',
'last_commit',
];
Expand All @@ -28,6 +29,6 @@ class Document extends Model
*/
protected $attributes = [
'version' => Docs::DEFAULT_VERSION,
'behind' => 0,
'count_commits_behind' => 0,
];
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
"spatie/laravel-ignition": "^2.0",
"squizlabs/php_codesniffer": "3.*"
},
"autoload": {
"psr-4": {
Expand Down
73 changes: 65 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function up(): void
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->string('status', 15);
$table->string('title');
$table->text('content');
$table->string('slug')->unique();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function up(): void
{
Schema::create('documents', function (Blueprint $table) {
$table->uuid('id');
$table->string('version');
$table->string('version', 7);
$table->string('file');
$table->integer('behind')->default(0);
$table->string('current_commit')->nullable();
$table->string('last_commit')->nullable();
$table->unsignedInteger('count_commits_behind')->default(0)->comment('count commits behind current');
$table->string('current_commit', 64)->nullable();
$table->string('last_commit', 64)->nullable();
$table->timestamps();


Expand Down
4 changes: 2 additions & 2 deletions resources/views/pages/docs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline
<div class="col-xl-9 text-center text-xl-start">

<div class="d-grid gap-3 d-md-flex justify-content-md-end mb-3">
@if($docs->behind() > 0)
<a href="{{ route('status', $docs->version) }}#{{$docs->file}}" class=""><span class="badge bg-primary-subtle text-primary rounded rounded-1 fs-6 fw-normal">Перевод отстаёт на {{ $docs->behind() }} изменения</span></a>
@if($docs->translationIsLagsBehind())
<a href="{{ route('status', $docs->version) }}#{{$docs->file}}" class=""><span class="badge bg-primary-subtle text-primary rounded rounded-1 fs-6 fw-normal">Перевод отстаёт на {{ $docs->countCommitsBehind() }} изменения</span></a>
@else
<span class="badge bg-success-subtle text-success rounded rounded-1 fs-6 fw-normal pe-none">Перевод актуален</span>
@endif
Expand Down
Loading