Skip to content

Instantly share code, notes, and snippets.

@kellymears
Created August 23, 2019 21:48
Show Gist options
  • Save kellymears/7d10e09377f026aa1afce67d770b7d69 to your computer and use it in GitHub Desktop.
Save kellymears/7d10e09377f026aa1afce67d770b7d69 to your computer and use it in GitHub Desktop.
<?php
namespace App\Composers;
use App\Composers\Concerns\Services;
use TinyPixel\FieldsComposer\FieldsComposer;
/**
* Plugin single template
*/
class Plugin extends FieldsComposer
{
use Services;
/**
* Github account
* @var string
*/
public static $account = 'pixelcollective';
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'partials.header-plugin',
'partials.content-single-plugin',
'partials.plugin-meta',
];
/**
* Data to be passed to view before rendering.
*
* @param array $data
* @param \Illuminate\View\View $view
* @return array
*/
public function with($data, $view)
{
$this->useServices([
'github',
'commonmark',
'cache',
]);
$this->repoId = $this->fields('plugin')->githubId;
return $this->forever($this->repoId, function () {
return [
'plugin' => $this->fields('plugin'),
'git' => $this->repo($this->repoId),
'readme' => $this->readme($this->repoId),
];
});
}
/**
* Repository.
*
* @param string $repoId
*
* @return array
*/
public function repo($repoId) : array
{
return $this->github->repo()->show(self::$account, $repoId);
}
/**
* Readme.
*
* @param string $repoId
* @return string
*/
public function readme($repoId) : string
{
return $this->commonmark->convertToHtml(
$this->github->repo()->readme(self::$account, $repoId)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment