Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Aug 1, 2021
0 parents commit 7492d9b
Show file tree
Hide file tree
Showing 18 changed files with 598 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php_cs.dist export-ignore
/psalm.xml export-ignore
/psalm.xml.dist export-ignore
/testbench.yaml export-ignore
37 changes: 37 additions & 0 deletions .github/workflows/phptest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on: [push]

name: "CI"

jobs:
test:
name: Test

runs-on: ubuntu-latest

strategy:
matrix:
php-versions: [7.4, 8.0.6]
# laravel-versions: [8.*, 8.12]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
coverage: pcov
extensions: intl, gd, zip, pdo, sqlite, pdo_sqlite, dom, curl, libxml, mbstring, fileinfo, exif, iconv
ini-values: memory_limit=-1,disable_functions="",pcov.exclude="~(vendor|tests|node_modules)~",pcov.directory="./"
php-version: ${{ matrix.php-versions }}
tools: composer:v2

- name: Composer Install
run: composer install

- name: PHPUNIT Tests
run: |
./vendor/bin/phpunit
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
composer.lock
coverage
docs
phpunit.xml
psalm.xml
testbench.yaml
vendor
node_modules
.php-cs-fixer.cache
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) rakutentech <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Automatically generate Laravel docs from request rules, controllers and routes

[![Latest Version on Packagist](https://img.shields.io/packagist/v/rakutentech/laravel-request-docs.svg?style=flat-square)](https://packagist.org/packages/rakutentech/laravel-request-docs)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/rakutentech/laravel-request-docs/run-tests?label=tests)](https://github.com/rakutentech/laravel-request-docs/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/rakutentech/laravel-request-docs/Check%20&%20fix%20styling?label=code%20style)](https://github.com/rakutentech/laravel-request-docs/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/rakutentech/laravel-request-docs.svg?style=flat-square)](https://packagist.org/packages/rakutentech/laravel-request-docs)

---
This repo can be used to scaffold a Laravel package. Follow these steps to get started:

1. Press the "Use template" button at the top of this repo to create a new repo with the contents of this laravel-request-docs
2. Run "./configure-laravel-request-docs.sh" to run a script that will replace all placeholders throughout all the files
3. Remove this block of text.
4. Have fun creating your package.
5. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
---

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-request-docs.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-request-docs)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

You can install the package via composer:

```bash
composer require rakutentech/laravel-request-docs
```

You can publish and run the migrations with:

```bash
php artisan vendor:publish --provider="Rakutentech\LaravelRequestDocs\LaravelRequestDocsServiceProvider"
```


This is the contents of the published config file:

```php
return [
];
```

## Usage

```php
$laravel-request-docs = new Rakutentech\LaravelRequestDocs();
echo $laravel-request-docs->echoPhrase('Hello, Spatie!');
```

## Testing

```bash
composer test
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Security Vulnerabilities

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

## Credits

- [Pulkit Kathuria](https://github.com/rakutentech)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
61 changes: 61 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "rakutentech/laravel-request-docs",
"description": "Automatically generate Laravel docs from request rules, controllers and routes",
"keywords": [
"rakutentech",
"laravel",
"laravel-request-docs"
],
"homepage": "https://github.com/rakutentech/laravel-request-docs",
"license": "MIT",
"authors": [
{
"name": "Pulkit Kathuria",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^8.0",
"spatie/laravel-package-tools": "^1.4.3",
"illuminate/contracts": "^8.37"
},
"require-dev": {
"brianium/paratest": "^6.2",
"nunomaduro/collision": "^5.3",
"orchestra/testbench": "^6.15",
"phpunit/phpunit": "^9.3",
"spatie/laravel-ray": "^1.23",
"vimeo/psalm": "^4.8"
},
"autoload": {
"psr-4": {
"Rakutentech\\LaravelRequestDocs\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Rakutentech\\LaravelRequestDocs\\Tests\\": "tests"
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Rakutentech\\LaravelRequestDocs\\LaravelRequestDocsServiceProvider"
],
"aliases": {
"LaravelRequestDocs": "Rakutentech\\LaravelRequestDocs\\LaravelRequestDocsFacade"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
11 changes: 11 additions & 0 deletions config/request-docs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
// config for Rakutentech/ClassName
return [
// localhost:8080/request-docs
'url' => 'request-docs',
'middlewares' => [
//Example
// \App\Http\Middleware\NotFoundWhenProduction::class,
],
'docs_path' => base_path('docs/request-docs/')
];
12 changes: 12 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="PSR2">
<description>Standard Based on PSR2</description>
<exclude-pattern type="relative-root">tests/*</exclude-pattern>
<rule ref="PSR2"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="210"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
</ruleset>
Empty file added resources/views/.gitkeep
Empty file.
95 changes: 95 additions & 0 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Laravel Request Docs</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-grey-lightest tracking-wide">

<div class="w-full flex flex-wrap mx-auto px-2 pt-8 lg:pt-16">
<div class="text-xl text-grey-darkest break-all">
<h1>Routes List</h1>
<table class="table-fixed text-sm">
<tbody>
@foreach ($docs as $index => $doc)
<tr>
<td>
<a href="#{{$doc['uri']}}">
<span class="font-thin inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-{{$doc['methods'][0] == 'GET' ? 'green': 'red'}}-100 bg-{{$doc['methods'][0] == 'GET' ? 'green': 'red'}}-500 rounded">
{{$doc['methods'][0]}}
</span>
<span class="font-mono">{{$doc['uri']}}</span>
</a>
<td>
</td>
@endforeach
</tbody>
</table>
</div>
<br><br>
<div class="pl-2 w-2/3 text-black">
@foreach ($docs as $index => $doc)
<div class="font-sans" id="{{$doc['uri']}}">
<h1 class="font-sans break-normal text-black pt-1 pb-2 ">
<span class="font-thin">{{$doc['methods'][0]}}</span>
<span class="font-mono">{{$doc['uri']}}</span>
</h1>
</div>
<hr class="border-b border-grey-light">
<table class="table-fixed align-center min-w-full text-sm mt-5">
<thead class="border">
<tr class="border">
<th class="border pl-2 pr-16 pt-1 pb-1 w-12 text-left bg-{{in_array('GET', $doc['methods']) ? 'green' : 'red'}}-200">Attributes</th>
<th class="border pl-2 pr-16 pt-1 pb-1 w-12 text-left bg-{{in_array('GET', $doc['methods']) ? 'green' : 'red'}}-200">Required</th>
<th class="border pl-2 pr-16 pt-1 pb-1 w-10 text-left bg-{{in_array('GET', $doc['methods']) ? 'green' : 'red'}}-200">Type</th>
<th class="border pl-2 pr-16 pt-1 pb-1 w-1/20 text-left bg-{{in_array('GET', $doc['methods']) ? 'green' : 'red'}}-200">Rules</th>
</tr>
</thead>
<tbody>
@foreach ($doc['rules'] as $attribute => $rules)
<tr class="border">
<td class="border pl-3 pt-1 pb-1 pr-2 bg-gray-100">{{$attribute}}</td>
<td class="border pl-3 pt-1 pb-1 pr-2">
@foreach ($rules as $rule)
@if (str_contains($rule, 'required'))
<span class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-pink-100 bg-pink-600 rounded">REQUIRED</span>
@endif
<br>
@endforeach
</td>
<td class="border pl-3 pt-1 pb-1 pr-2 bg-gray-100">
@foreach ($rules as $rule)
@if (str_contains($rule, 'integer'))
<span class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-blue-100 bg-blue-500 rounded">Integer</span>
@endif
@if (str_contains($rule, 'string'))
<span class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-green-100 bg-green-500 rounded">String</span>
@endif
@if (str_contains($rule, 'array'))
<span class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-gray-700 bg-yellow-400 rounded">Array</span>
@endif
<br>
@endforeach
</td>
<td class="border pl-3 pr-2">
<div class="font-mono">
@foreach ($rules as $rule)
{{ str_replace(["required|", "integer|", "string|"], ["", "", ""], $rule) }}
@endforeach
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
<br><br>
@endforeach
</div>
</div>
</body>
</html>
Loading

0 comments on commit 7492d9b

Please sign in to comment.