Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2013-10-14 01:25:52 +0400
committerThomas Steur <thomas.steur@gmail.com>2013-10-14 01:25:52 +0400
commitec52d4f107ef59882cfc37c4ed85bb90298355ba (patch)
tree4b8fc6a19b13970816bfb892330331aea807ed84
parent92f8f4fe4ab48af5331aeab30c4f3e3166426cbb (diff)
added command to generate a visualization plugin based on our VisualizationExamplePlugin
-rw-r--r--core/Console.php2
-rw-r--r--plugins/CoreConsole/GeneratePlugin.php10
-rw-r--r--plugins/CoreConsole/GeneratePluginBase.php22
-rw-r--r--plugins/CoreConsole/GenerateVisualizationPlugin.php101
-rw-r--r--plugins/ExampleVisualization/ExampleVisualization.php4
-rw-r--r--plugins/ExampleVisualization/SimpleTable.php4
-rw-r--r--plugins/ExampleVisualization/plugin.json2
7 files changed, 131 insertions, 14 deletions
diff --git a/core/Console.php b/core/Console.php
index c450869459..8ce6884bad 100644
--- a/core/Console.php
+++ b/core/Console.php
@@ -13,6 +13,7 @@ namespace Piwik;
use Piwik\Plugins\CoreConsole\GenerateApi;
use Piwik\Plugins\CoreConsole\GenerateController;
use Piwik\Plugins\CoreConsole\GeneratePlugin;
+use Piwik\Plugins\CoreConsole\GenerateVisualizationPlugin;
use Piwik\Plugins\CoreConsole\GitCommit;
use Piwik\Plugins\CoreConsole\GitPull;
use Piwik\Plugins\CoreConsole\GitPush;
@@ -37,6 +38,7 @@ class Console
$console->add(new GeneratePlugin());
$console->add(new GenerateApi());
$console->add(new GenerateController());
+ $console->add(new GenerateVisualizationPlugin());
$console->add(new WatchLog());
$console->add(new GitPull());
$console->add(new GitCommit());
diff --git a/plugins/CoreConsole/GeneratePlugin.php b/plugins/CoreConsole/GeneratePlugin.php
index 6ec8cfd995..da88c60934 100644
--- a/plugins/CoreConsole/GeneratePlugin.php
+++ b/plugins/CoreConsole/GeneratePlugin.php
@@ -86,13 +86,13 @@ class GeneratePlugin extends GeneratePluginBase
return false !== strpos($commandName, 'theme');
}
- private function generatePluginFolder($pluginName)
+ protected function generatePluginFolder($pluginName)
{
$pluginPath = $this->getPluginPath($pluginName);
Filesystem::mkdir($pluginPath, true);
}
- private function generatePluginJson($pluginName, $version, $description, $isTheme)
+ protected function generatePluginJson($pluginName, $version, $description, $isTheme)
{
$pluginJson = array(
'name' => $pluginName,
@@ -115,7 +115,7 @@ class GeneratePlugin extends GeneratePluginBase
/**
* @param string $pluginName
*/
- private function generatePluginFile($pluginName)
+ protected function generatePluginFile($pluginName)
{
$template = file_get_contents(__DIR__ . '/templates/PluginTemplate.php');
$template = str_replace('PLUGINNAME', $pluginName, $template);
@@ -128,7 +128,7 @@ class GeneratePlugin extends GeneratePluginBase
* @return array
* @throws \RunTimeException
*/
- private function getPluginName(InputInterface $input, OutputInterface $output)
+ protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$self = $this;
@@ -170,7 +170,7 @@ class GeneratePlugin extends GeneratePluginBase
* @return mixed
* @throws \RunTimeException
*/
- private function getPluginDescription(InputInterface $input, OutputInterface $output)
+ protected function getPluginDescription(InputInterface $input, OutputInterface $output)
{
$validate = function ($description) {
if (empty($description)) {
diff --git a/plugins/CoreConsole/GeneratePluginBase.php b/plugins/CoreConsole/GeneratePluginBase.php
index 9f0b86e244..23fce45d5f 100644
--- a/plugins/CoreConsole/GeneratePluginBase.php
+++ b/plugins/CoreConsole/GeneratePluginBase.php
@@ -44,12 +44,19 @@ class GeneratePluginBase extends Command
}
/**
- * @param string $templateName eg. 'controller' or 'api'
+ * @param string $templateNameOrPath eg. 'controller' or 'api' or a full path like /home/...
* @param string $pluginName
+ * @param array $replace array(key => value) $key will be replaced by $value in all templates
*/
- protected function copyTemplateToPlugin($templateName, $pluginName)
+ protected function copyTemplateToPlugin($templateNameOrPath, $pluginName, array $replace = array())
{
- $templateFolder = __DIR__ . '/templates/' . $templateName;
+ if (0 === strpos($templateNameOrPath, '/')) {
+ $templateFolder = $templateNameOrPath;
+ } else {
+ $templateFolder = __DIR__ . '/templates/' . $templateNameOrPath;
+ }
+
+ $replace['PLUGINNAME'] = $pluginName;
$files = Filesystem::globr($templateFolder, '*');
@@ -60,7 +67,14 @@ class GeneratePluginBase extends Command
$this->createFolderWithinPluginIfNotExists($pluginName, $fileNamePlugin);
} else {
$template = file_get_contents($file);
- $template = str_replace('PLUGINNAME', $pluginName, $template);
+ foreach ($replace as $key => $value) {
+ $template = str_replace($key, $value, $template);
+ }
+
+ foreach ($replace as $key => $value) {
+ $fileNamePlugin = str_replace($key, $value, $fileNamePlugin);
+ }
+
$this->createFileWithinPluginIfNotExists($pluginName, $fileNamePlugin, $template);
}
diff --git a/plugins/CoreConsole/GenerateVisualizationPlugin.php b/plugins/CoreConsole/GenerateVisualizationPlugin.php
new file mode 100644
index 0000000000..179e442338
--- /dev/null
+++ b/plugins/CoreConsole/GenerateVisualizationPlugin.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik_Plugins
+ * @package CoreConsole
+ */
+
+namespace Piwik\Plugins\CoreConsole;
+
+
+use Piwik\Filesystem;
+use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * @package CoreConsole
+ */
+class GenerateVisualizationPlugin extends GeneratePlugin
+{
+ protected function configure()
+ {
+ $this->setName('generate:visualizationplugin')
+ ->setDescription('Generates a new visualization plugin including all needed files')
+ ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Plugin name ([a-Z0-9_-])')
+ ->addOption('visualizationname', null, InputOption::VALUE_REQUIRED, 'Visualization name ([a-Z0-9])')
+ ->addOption('description', null, InputOption::VALUE_REQUIRED, 'Plugin description, max 150 characters')
+ ->addOption('pluginversion', null, InputOption::VALUE_OPTIONAL, 'Plugin version')
+ ->addOption('full', null, InputOption::VALUE_OPTIONAL, 'If a value is set, an API and a Controller will be created as well. Option is only available for creating plugins, not for creating themes.');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $pluginName = $this->getPluginName($input, $output);
+ $visualizationName = $this->getVisualizationName($input, $output);
+ $description = $this->getPluginDescription($input, $output);
+ $version = $this->getPluginVersion($input, $output);
+
+ $this->generatePluginFolder($pluginName);
+ $this->generatePluginJson($pluginName, $version, $description, false);
+
+ $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExampleVisualization';
+ $replace = array(
+ 'ExampleVisualization' => $pluginName,
+ 'SimpleTable' => $visualizationName,
+ 'simpleTable' => lcfirst($visualizationName),
+ 'Simple Table' => $visualizationName
+ );
+
+ $this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace);
+ $this->generatePluginFile($pluginName);
+
+ $this->writeSuccessMessage($output, array(
+ sprintf('Visualization plugin %s %s generated.', $pluginName, $version),
+ 'Enjoy!'
+ ));
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return string
+ * @throws \RunTimeException
+ */
+ private function getVisualizationName(InputInterface $input, OutputInterface $output)
+ {
+ $self = $this;
+
+ $validate = function ($visualizationName) use ($self) {
+ if (empty($visualizationName)) {
+ throw new \RunTimeException('You have to enter a visualization name');
+ }
+
+ if (!ctype_alnum($visualizationName)) {
+ throw new \RunTimeException(sprintf('The visualization name %s is not valid', $visualizationName));
+ }
+
+ return $visualizationName;
+ };
+
+ $visualizationName = $input->getOption('visualizationname');
+
+ if (empty($visualizationName)) {
+ $dialog = $this->getHelperSet()->get('dialog');
+ $visualizationName = $dialog->askAndValidate($output, 'Enter a visualization name: ', $validate);
+ } else {
+ $validate($visualizationName);
+ }
+
+ $visualizationName = ucfirst($visualizationName);
+
+ return $visualizationName;
+ }
+
+
+} \ No newline at end of file
diff --git a/plugins/ExampleVisualization/ExampleVisualization.php b/plugins/ExampleVisualization/ExampleVisualization.php
index 9aa6b363c6..e445bb18a4 100644
--- a/plugins/ExampleVisualization/ExampleVisualization.php
+++ b/plugins/ExampleVisualization/ExampleVisualization.php
@@ -6,14 +6,14 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
- * @package SimpleTableVisualizationExample
+ * @package ExampleVisualization
*/
namespace Piwik\Plugins\ExampleVisualization;
use Piwik\Plugin;
/**
- * @package SimpleTableVisualizationExample
+ * @package ExampleVisualization
*/
class ExampleVisualization extends Plugin
{
diff --git a/plugins/ExampleVisualization/SimpleTable.php b/plugins/ExampleVisualization/SimpleTable.php
index 0ec31af005..e38debf9c1 100644
--- a/plugins/ExampleVisualization/SimpleTable.php
+++ b/plugins/ExampleVisualization/SimpleTable.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
- * @package TreemapVisualization
+ * @package ExampleVisualization
*/
namespace Piwik\Plugins\ExampleVisualization;
@@ -17,7 +17,7 @@ use Piwik\Visualization\Config;
use Piwik\Visualization\Request;
/**
- * Simple Visualization Example.
+ * SimpleTable Visualization.
*/
class SimpleTable extends Visualization
{
diff --git a/plugins/ExampleVisualization/plugin.json b/plugins/ExampleVisualization/plugin.json
index 30d7d51150..a3a5202a33 100644
--- a/plugins/ExampleVisualization/plugin.json
+++ b/plugins/ExampleVisualization/plugin.json
@@ -4,7 +4,7 @@
"description": "Example for generating a simple visualization",
"theme": false,
"license": "GPL-3.0+",
- "keywords": ["visualization", "example", "table"],
+ "keywords": ["SimpleTable"],
"homepage": "http://piwik.org",
"authors": [
{