Skip to content

Commit

Permalink
Merge pull request #2 from bbs-smuller/feature/laravel58
Browse files Browse the repository at this point in the history
Feature/laravel58
  • Loading branch information
mfrancois authored Jun 12, 2019
2 parents 19bdc84 + d80503c commit f9c5801
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 119 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Distilleries
Copyright (c) 2019 Distilleries

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
54 changes: 24 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,55 @@
[![Latest Stable Version](https://poser.pugx.org/distilleries/integration/version)](https://packagist.org/packages/distilleries/integration)
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)

#Integration
# Integration

Integration is package to work with frontend developer.

## Table of contents

## Installation


##Installation
Auto detect package has been set on this release.

Add on your composer.json

``` json
```json
"require": {
"distilleries/integration": "1.*",
}
```

run `composer update`.



Add Service provider to `config/app.php`:

``` php
(or auto-loaded if Laravel >= 5.7)

```php
'providers' => [

/*
* Package Service Providers...
*/
//
// Package Service Providers...
//
Distilleries\Integration\IntegrationServiceProvider::class,


]
```


##Configurations
## Configurations

```php
return [
'path_partial_component' => resource_path('views/frontend/integration/components/partials'),
'controller' => '\Distilleries\Integration\Http\Controllers\Frontend\IntegrationController@getComponentDetail',
'prefix_uri' => 'integration',
'disabled' => false,
'pages'=>[
'controller' => '\Distilleries\Integration\Http\Controllers\Frontend\IntegrationController@getComponentDetail',
'prefix_uri' => 'integration',
'disabled' => false,
'pages' => [
[
'name'=>'Page FAQ Example',
'slug'=>'faq',
'status'=>'done', //done,in_progress,todo
'view'=>'integration::frontend.integration.pages.faq',
]
]
'name' => 'Page FAQ Example',
'slug' => 'faq',
'status' => 'done', //done,in_progress,todo
'view' => 'integration::frontend.integration.pages.faq',
],
],
];
```

Expand All @@ -66,20 +62,18 @@ prefix_uri | Uri prefix for integration route
disabled | Disable the integration generation
pages | Table of static page


##Usage
## Usage

```blade
@component('frontend.components.forms.buttons',transform('Forms\ButtonsTransformer', [
'type' => 'submit',
'background' => '',
'border' => 'border-enabled',
'text_color' => 'text-grey',
'size' => 'small'
]))
'size' => 'small',
]))
@slot('label')
EDIT
@endslot
@endcomponent
```
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
"email": "[email protected]"
}
],

"require": {
"php": ">=7.1.3",
"illuminate/support": "5.6.*",
"illuminate/database": "5.6.*",
"illuminate/translation": "5.6.*"
"illuminate/support": "~5.6|~5.7|~5.8",
"illuminate/database": "~5.6|~5.7|~5.8",
"illuminate/translation": "~5.6|~5.7|~5.8"
},
"require-dev": {
"orchestra/database": "3.6.*",
"orchestra/testbench": "3.6.*",
"orchestra/testbench-browser-kit": "3.6.*",
"orchestra/database": "~3.6|~3.7|~3.8",
"orchestra/testbench": "~3.6|~3.7|~3.8",
"orchestra/testbench-browser-kit": "~3.6|~3.7|~3.8",
"phpunit/phpunit": "7.1.*",
"mockery/mockery": "0.9.*",
"fzaninotto/faker": "1.6.*"
Expand Down
15 changes: 8 additions & 7 deletions src/Distilleries/Integration/Helpers/ArrayPrettyPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

class ArrayPrettyPrinter extends PrettyPrinter\Standard
{

protected function pExpr_Array(Expr\Array_ $node) {
protected function pExpr_Array(Expr\Array_ $node)
{
$syntax = $node->getAttribute('kind',
$this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG);

if ($syntax === Expr\Array_::KIND_SHORT) {
return "[\n\t" . $this->pCommaSeparatedWithBreakLine($node->items) . "\n]";
} else {
return "array(\n\t" . $this->pCommaSeparatedWithBreakLine($node->items) . "\n)";
}

return "array(\n\t" . $this->pCommaSeparatedWithBreakLine($node->items) . "\n)";
}

protected function pCommaSeparatedWithBreakLine(array $nodes) {
protected function pCommaSeparatedWithBreakLine(array $nodes)
{
return $this->pImplode($nodes, ",\n\t");
}

}
}
58 changes: 24 additions & 34 deletions src/Distilleries/Integration/Helpers/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Distilleries\Integration\Helpers;

use Illuminate\Support\Str;
use PhpParser\Error;
use PhpParser\Node\Stmt\Class_;
use Illuminate\Support\Str;
use PhpParser\ParserFactory;
use PhpParser\Node\Stmt\Class_;

/**
* Created by PhpStorm.
Expand All @@ -15,62 +15,56 @@
*/
class Integration
{


public static function getComponentsFolderByDepth($folders)
{
$files = app('files');
$files = app('files');
$childrens = $files->directories($folders);
$parent = [];
$parent = [];

if (!empty($childrens)) {
if (! empty($childrens)) {
foreach ($childrens as $children) {

$names = explode(DIRECTORY_SEPARATOR, $children);
$names = explode(DIRECTORY_SEPARATOR, $children);
$parent[] = [
'title' => last($names),
'children' => self::getComponentsFileByDepth($children)
'title' => last($names),
'children' => self::getComponentsFileByDepth($children),
];
}
}


return $parent;
}

public static function getComponentsFileByDepth($folders)
{
$files = app('files');
$files = app('files');
$childrens = $files->files($folders);

$result = [];

if (!empty($childrens)) {
if (! empty($childrens)) {
foreach ($childrens as $child) {
$names = explode(DIRECTORY_SEPARATOR, $child);
$names = explode(DIRECTORY_SEPARATOR, $child);
$template = str_replace('.blade.php', '', str_replace(resource_path('views/'), '', $child));
$content = $files->get($child);
$phpdoc = '';
$matches = [];
$content = $files->get($child);
$phpdoc = '';
$matches = [];
preg_match('/transform\(\s*([^)]+?)\s*\)/', $content, $matches);


if (!empty($matches) && is_array($matches)) {
if (! empty($matches) && is_array($matches)) {
foreach ($matches as $match) {
if (!Str::contains($match, 'transform(')) {

if (! Str::contains($match, 'transform(')) {
$match = explode(',', $match);
$phpdoc .= self::getTransformerContent(Str::substr($match[0], 1, strlen($match[0]) - 2));
}
}
}

$result[] = [
'title' => str_replace('.blade.php', '', last($names)),
'url' => action(config('integration.controller'), ['slug' => str_replace('/', '.', str_replace('.blade.php', '', $template))]),
'title' => str_replace('.blade.php', '', last($names)),
'url' => action(config('integration.controller'), ['slug' => str_replace('/', '.', str_replace('.blade.php', '', $template))]),
'template' => $template,
'doc' => $content,
'phpdoc' => $phpdoc
'doc' => $content,
'phpdoc' => $phpdoc,
];
}
}
Expand All @@ -80,28 +74,24 @@ public static function getComponentsFileByDepth($folders)

public static function getTransformerContent($transformer)
{
$code = transformGetContentClass($transformer);
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$code = transformGetContentClass($transformer);
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$prettyPrinter = new ArrayPrettyPrinter();

try {
$stmts = $parser->parse($code);

$code = '';
$code = '';
foreach ($stmts[0]->stmts as $stmt) {
if ($stmt instanceof Class_) {
$code = $prettyPrinter->prettyPrint($stmt->stmts);
break;
}
}

} catch (Error $e) {

$code = '';
}

return $code;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,43 @@

namespace Distilleries\Integration\Http\Controllers\Frontend;

use Illuminate\Support\Collection;
use Distilleries\Integration\Helpers\Integration;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Collection;

class IntegrationController extends BaseController
{

public function getComponentDetail($slug)
{
return view('integration::frontend.integration.components.component',['slug'=>$slug]);
return view('integration::frontend.integration.components.component', ['slug' => $slug]);
}

public function getComponent()
{

$tabComponents = Integration::getComponentsFolderByDepth(config('integration.path_partial_component'));

return view('integration::frontend.integration.components.components', compact('tabComponents'));
}

public function getPageListe(){
public function getPageListe()
{
$tabOfPages = config('integration.pages');

return view('integration::frontend.integration.pages', compact('tabOfPages'));
}

public function getPage($slug){

public function getPage($slug)
{
$page = (new Collection(config('integration.pages')))
->filter(function ($item, $key) use($slug) {
return $item['slug'] == $slug;
})
->first();
->filter(function ($item, $key) use ($slug) {
return $item['slug'] == $slug;
})
->first();

if(empty($page)){
if (empty($page)) {
abort(404);
}

return view($page['view']);
}
}
15 changes: 2 additions & 13 deletions src/Distilleries/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
<?php

use Illuminate\Support\Facades\Route;

if (empty(config('integration.disabled', false))) {
Route::group(['prefix' => config('integration.prefix_uri')], function (){
Route::group(['prefix' => config('integration.prefix_uri')], function () {
Route::get('/component-detail/{any}', '\Distilleries\Integration\Http\Controllers\Frontend\IntegrationController@getComponentDetail');
Route::get('/component', '\Distilleries\Integration\Http\Controllers\Frontend\IntegrationController@getComponent');
Route::get('/', '\Distilleries\Integration\Http\Controllers\Frontend\IntegrationController@getPageListe');
Expand Down
Loading

0 comments on commit f9c5801

Please sign in to comment.