From 77a7e3da2ebc4694ed4433768009c86ac7f2d2d4 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 17 Aug 2016 14:19:20 -0600 Subject: [PATCH 1/3] Added support for `external_url:` page header --- CHANGELOG.md | 1 + system/blueprints/pages/external.yaml | 36 +++++++++++++++++++++++++++ system/src/Grav/Common/Page/Page.php | 9 +++++++ system/src/Grav/Common/Page/Types.php | 2 ++ 4 files changed, 48 insertions(+) create mode 100644 system/blueprints/pages/external.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff4dbf77..5c0bcc99d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 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 1. [](#bugfix) * Fix for lightbox media function throwing error [#981](https://github.com/getgrav/grav/issues/981) diff --git a/system/blueprints/pages/external.yaml b/system/blueprints/pages/external.yaml new file mode 100644 index 000000000..13085ed75 --- /dev/null +++ b/system/blueprints/pages/external.yaml @@ -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 diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index abb421078..63805f3e6 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -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(); diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index e915c07b6..04a6ad3d0 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -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) { From 6fb49a3a8a74f1bee8eb65c83cc69932b9e42386 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 17 Aug 2016 17:48:46 -0600 Subject: [PATCH 2/3] Improved UI for CLI GPM Index to use tables --- CHANGELOG.md | 1 + system/src/Grav/Console/Gpm/IndexCommand.php | 59 +++++++++++-------- .../Grav/Console/TerminalObjects/Table.php | 29 +++++++++ 3 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 system/src/Grav/Console/TerminalObjects/Table.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0bcc99d..1573d854b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * 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) diff --git a/system/src/Grav/Console/Gpm/IndexCommand.php b/system/src/Grav/Console/Gpm/IndexCommand.php index 2e3edb229..9426aeaac 100644 --- a/system/src/Grav/Console/Gpm/IndexCommand.php +++ b/system/src/Grav/Console/Gpm/IndexCommand.php @@ -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("" . ucfirst($type) . " [ " . count($packages) . " ]"); + $climate = new CLImate; + $climate->extend('Grav\Console\TerminalObjects\Table'); + foreach ($data as $type => $packages) { + $this->output->writeln("" . strtoupper($type) . " [ " . 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 - "" . str_pad($package->name, 20) . " " . - // slug - "[" . str_pad($slug, 20, ' ', STR_PAD_BOTH) . "] " . - // version details - $this->versionDetails($package) - ); + $row = [ + 'Count' => $index++ + 1, + 'Name' => "" . Utils::truncate($package->name, 20, false, ' ', '...') . " ", + '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 ? ' (not installed)' : ' (installed)'; - - return str_pad(" [v" . $version . "]", 35) . $installed; + return "v" . $version . ""; } if ($updatable) { - $installed = !$installed ? ' (not installed)' : ' (installed)'; - - return str_pad(" [v" . $package->version . " v" . $package->available . "]", - 61) . $installed; + return "v" . $package->version . " -> v" . $package->available . ""; } 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 ? 'not installed' : 'installed'; + } + /** * @param $data * diff --git a/system/src/Grav/Console/TerminalObjects/Table.php b/system/src/Grav/Console/TerminalObjects/Table.php new file mode 100644 index 000000000..7c5dc328b --- /dev/null +++ b/system/src/Grav/Console/TerminalObjects/Table.php @@ -0,0 +1,29 @@ +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; + } +} From ea6dc3ef22d05a57214a8277b8366259097df1ba Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 17 Aug 2016 17:49:06 -0600 Subject: [PATCH 3/3] Added CLImate composer package for tables support in CLI --- composer.json | 3 +- composer.lock | 103 ++++++++++++++++++- system/src/Grav/Console/Cli/CleanCommand.php | 2 + 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 97bad168c..9c0079cc0 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-curl": "*", - "ext-zip": "*" + "ext-zip": "*", + "league/climate": "^3.2" }, "require-dev": { "codeception/codeception": "^2.1", diff --git a/composer.lock b/composer.lock index 3e655f805..4c4901c7b 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/system/src/Grav/Console/Cli/CleanCommand.php b/system/src/Grav/Console/Cli/CleanCommand.php index 69d05758b..9fea3fd7b 100644 --- a/system/src/Grav/Console/Cli/CleanCommand.php +++ b/system/src/Grav/Console/Cli/CleanCommand.php @@ -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',