Merge branch 'feature/climate_integration' into develop

This commit is contained in:
Andy Miller
2016-08-17 17:49:26 -06:00
9 changed files with 219 additions and 26 deletions

View File

@@ -4,6 +4,8 @@
1. [](#improved)
* Important vendor updates to provide PHP 7.1 beta support!
* Added a `Util::arrayFlatten()` static function
* Added support for 'external_url' page header to enable easier external URL based menu items
* Improved the UI for CLI GPM Index view to use a table
1. [](#bugfix)
* Fix for lightbox media function throwing error [#981](https://github.com/getgrav/grav/issues/981)

View File

@@ -27,7 +27,8 @@
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-curl": "*",
"ext-zip": "*"
"ext-zip": "*",
"league/climate": "^3.2"
},
"require-dev": {
"codeception/codeception": "^2.1",

103
composer.lock generated
View File

@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "65cd6cc2a20addb345acc1f84d5ae3ab",
"content-hash": "0ddb599b8e9fb7f0fb76619343180ef9",
"hash": "25e59d23a9af7f43dd9cd9d462057abd",
"content-hash": "22973a67f2eae64610e739fa82a3d60b",
"packages": [
{
"name": "doctrine/cache",
@@ -365,6 +365,57 @@
],
"time": "2015-05-30 19:24:37"
},
{
"name": "league/climate",
"version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/climate.git",
"reference": "b103fc8faa3780c802cc507d5f0ff534ecc94fb5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/climate/zipball/b103fc8faa3780c802cc507d5f0ff534ecc94fb5",
"reference": "b103fc8faa3780c802cc507d5f0ff534ecc94fb5",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"seld/cli-prompt": "~1.0"
},
"require-dev": {
"mikey179/vfsstream": "~1.4",
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.6"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\CLImate\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Joe Tannenbaum",
"email": "hey@joe.codes",
"homepage": "http://joe.codes/",
"role": "Developer"
}
],
"description": "PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.",
"keywords": [
"cli",
"colors",
"command",
"php",
"terminal"
],
"time": "2016-04-04 20:24:59"
},
{
"name": "matthiasmullie/minify",
"version": "1.3.35",
@@ -741,6 +792,54 @@
],
"time": "2016-08-01 09:49:45"
},
{
"name": "seld/cli-prompt",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/cli-prompt.git",
"reference": "8cbe10923cae5bcd7c5a713f6703fc4727c8c1b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/cli-prompt/zipball/8cbe10923cae5bcd7c5a713f6703fc4727c8c1b4",
"reference": "8cbe10923cae5bcd7c5a713f6703fc4727c8c1b4",
"shasum": ""
},
"require": {
"php": ">=5.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Seld\\CliPrompt\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be"
}
],
"description": "Allows you to prompt for user input on the command line, and optionally hide the characters they type",
"keywords": [
"cli",
"console",
"hidden",
"input",
"prompt"
],
"time": "2016-04-18 09:31:41"
},
{
"name": "symfony/console",
"version": "v2.8.9",

View File

@@ -0,0 +1,36 @@
rules:
slug:
pattern: "[a-zа-я][a-zа-я0-9_\-]+"
min: 2
max: 80
form:
validation: loose
fields:
tabs:
type: tabs
active: 1
fields:
content:
type: tab
title: PLUGIN_ADMIN.CONTENT
fields:
header.title:
type: text
autofocus: true
label: PLUGIN_ADMIN.TITLE
header.external_url:
type: text
label: PLUGIN_ADMIN.EXTERNAL_URL
placeholder: https://getgrav.org
validate:
required: true
options:
type: tab
title: PLUGIN_ADMIN.OPTIONS

View File

@@ -54,6 +54,7 @@ class Page
protected $routable;
protected $modified;
protected $redirect;
protected $external_url;
protected $items;
protected $header;
protected $frontmatter;
@@ -364,6 +365,9 @@ class Page
if (isset($this->header->redirect)) {
$this->redirect = trim($this->header->redirect);
}
if (isset($this->header->external_url)) {
$this->external_url = trim($this->header->external_url);
}
if (isset($this->header->order_dir)) {
$this->order_dir = trim($this->header->order_dir);
}
@@ -1470,6 +1474,11 @@ class Page
/** @var Uri $uri */
$uri = $grav['uri'];
// Override any URL when external_url is set
if (isset($this->external_url)) {
return $this->external_url;
}
// get pre-route
if ($include_lang && $language->enabled()) {
$pre_route = $language->getLanguageURLPrefix();

View File

@@ -52,6 +52,8 @@ class Types implements \ArrayAccess, \Iterator, \Countable
// Register default by default.
$this->register('default');
$this->register('external');
}
foreach ($this->findBlueprints($uri) as $type => $blueprint) {

View File

@@ -94,6 +94,7 @@ class CleanCommand extends Command
'vendor/ircmaxell/password-compat/version-test.php',
'vendor/ircmaxell/password-compat/.travis.yml',
'vendor/ircmaxell/password-compat/test',
'vendor/league/climate/composer.json',
'vendor/matthiasmullie/minify/bin',
'vendor/matthiasmullie/minify/composer.json',
'vendor/matthiasmullie/minify/CONTRIBUTING.md',
@@ -124,6 +125,7 @@ class CleanCommand extends Command
'vendor/rockettheme/toolbox/.travis.yml',
'vendor/rockettheme/toolbox/composer.json',
'vendor/rockettheme/toolbox/phpunit.xml',
'vendor/seld/cli-prompt/composer.json',
'vendor/symfony/console/composer.json',
'vendor/symfony/console/phpunit.xml.dist',
'vendor/symfony/console/.gitignore',

View File

@@ -9,7 +9,9 @@
namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Common\Utils;
use Grav\Console\ConsoleCommand;
use League\CLImate\CLImate;
use Symfony\Component\Console\Input\InputOption;
class IndexCommand extends ConsoleCommand
@@ -100,33 +102,34 @@ class IndexCommand extends ConsoleCommand
protected function serve()
{
$this->options = $this->input->getOptions();
$this->gpm = new GPM($this->options['force']);
$this->displayGPMRelease();
$this->data = $this->gpm->getRepository();
$data = $this->filter($this->data);
foreach ($data as $type => $packages) {
$this->output->writeln("<green>" . ucfirst($type) . "</green> [ " . count($packages) . " ]");
$climate = new CLImate;
$climate->extend('Grav\Console\TerminalObjects\Table');
foreach ($data as $type => $packages) {
$this->output->writeln("<green>" . strtoupper($type) . "</green> [ " . count($packages) . " ]");
$table = [];
$index = 0;
$packages = $this->sort($packages);
foreach ($packages as $slug => $package) {
$this->output->writeln(
// index
str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " .
// package name
"<cyan>" . str_pad($package->name, 20) . "</cyan> " .
// slug
"[" . str_pad($slug, 20, ' ', STR_PAD_BOTH) . "] " .
// version details
$this->versionDetails($package)
);
$row = [
'Count' => $index++ + 1,
'Name' => "<cyan>" . Utils::truncate($package->name, 20, false, ' ', '...') . "</cyan> ",
'Slug' => $slug,
'Version'=> $this->version($package),
'Installed' => $this->installed($package)
];
$table[] = $row;
}
$climate->table($table);
$this->output->writeln('');
}
@@ -143,7 +146,7 @@ class IndexCommand extends ConsoleCommand
*
* @return string
*/
private function versionDetails($package)
private function version($package)
{
$list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}();
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
@@ -154,21 +157,31 @@ class IndexCommand extends ConsoleCommand
if (!$installed || !$updatable) {
$version = $installed ? $local->version : $package->version;
$installed = !$installed ? ' (<magenta>not installed</magenta>)' : ' (<cyan>installed</cyan>)';
return str_pad(" [v<green>" . $version . "</green>]", 35) . $installed;
return "v<green>" . $version . "</green>";
}
if ($updatable) {
$installed = !$installed ? ' (<magenta>not installed</magenta>)' : ' (<cyan>installed</cyan>)';
return str_pad(" [v<red>" . $package->version . "</red> <cyan>➜</cyan> v<green>" . $package->available . "</green>]",
61) . $installed;
return "v<red>" . $package->version . "</red> <cyan>-></cyan> v<green>" . $package->available . "</green>";
}
return '';
}
/**
* @param $package
*
* @return string
*/
private function installed($package)
{
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
$type = ucfirst(preg_replace("/s$/", '', $package->package_type));
$updatable = $this->gpm->{'is' . $type . 'Updatable'}($package->slug);
$installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug);
return !$installed ? '<magenta>not installed</magenta>' : '<cyan>installed</cyan>';
}
/**
* @param $data
*

View File

@@ -0,0 +1,29 @@
<?php
/**
* @package Grav.Console
*
* @copyright Copyright (C) 2014 - 2016 RocketTheme, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Console\TerminalObjects;
class Table extends \League\CLImate\TerminalObject\Basic\Table
{
public function result()
{
$this->column_widths = $this->getColumnWidths();
$this->table_width = $this->getWidth();
$this->border = $this->getBorder();
$this->buildHeaderRow();
foreach ($this->data as $key => $columns) {
$this->rows[] = $this->buildRow($columns);
}
$this->rows[] = $this->border;
return $this->rows;
}
}