Skip to content
Extraits de code Groupes Projets
Valider c63ca289 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

removed generator templates, added new plugin to copy files from this

parent 45985deb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 87 ajouts et 88 suppressions
...@@ -31,13 +31,17 @@ class GenerateApi extends GeneratePluginBase ...@@ -31,13 +31,17 @@ class GenerateApi extends GeneratePluginBase
{ {
$pluginName = $this->getPluginName($input, $output); $pluginName = $this->getPluginName($input, $output);
$this->copyTemplateToPlugin('api', $pluginName); $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePluginTemplate';
$replace = array('ExamplePluginTemplate' => $pluginName);
$whitelistFiles = array('/API.php');
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$this->writeSuccessMessage($output, array( $this->writeSuccessMessage($output, array(
sprintf('API.php for %s generated.', $pluginName), sprintf('API.php for %s generated.', $pluginName),
'You can now start adding API methods', 'You can now start adding API methods',
'Enjoy!' 'Enjoy!'
)); ));
} }
/** /**
......
...@@ -31,13 +31,17 @@ class GenerateController extends GeneratePluginBase ...@@ -31,13 +31,17 @@ class GenerateController extends GeneratePluginBase
{ {
$pluginName = $this->getPluginName($input, $output); $pluginName = $this->getPluginName($input, $output);
$this->copyTemplateToPlugin('controller', $pluginName); $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePluginTemplate';
$replace = array('ExamplePluginTemplate' => $pluginName);
$whitelistFiles = array('/Controller.php', '/templates', '/templates/index.twig');
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$this->writeSuccessMessage($output, array( $this->writeSuccessMessage($output, array(
sprintf('Controller for %s generated.', $pluginName), sprintf('Controller for %s generated.', $pluginName),
'You can now start adding Controller actions', 'You can now start adding Controller actions',
'Enjoy!' 'Enjoy!'
)); ));
} }
/** /**
......
...@@ -36,26 +36,49 @@ class GeneratePlugin extends GeneratePluginBase ...@@ -36,26 +36,49 @@ class GeneratePlugin extends GeneratePluginBase
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$isTheme = $this->isTheme($input); $isTheme = $this->isTheme($input);
$pluginName = $this->getPluginName($input, $output); $pluginName = $this->getPluginName($input, $output);
$description = $this->getPluginDescription($input, $output); $description = $this->getPluginDescription($input, $output);
$version = $this->getPluginVersion($input, $output); $version = $this->getPluginVersion($input, $output);
$createFullPlugin = !$isTheme && $this->getCreateFullPlugin($input, $output); $createFullPlugin = !$isTheme && $this->getCreateFullPlugin($input, $output);
$this->generatePluginFolder($pluginName); $this->generatePluginFolder($pluginName);
$this->generatePluginJson($pluginName, $version, $description, $isTheme);
if ($isTheme) { if ($isTheme) {
$this->copyTemplateToPlugin('theme', $pluginName); $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExampleTheme';
$replace = array(
'ExampleTheme' => $pluginName,
'ExampleDescription' => $description,
'0.1.0' => $version
);
$whitelistFiles = array();
} else { } else {
$this->copyTemplateToPlugin('plugin', $pluginName);
$this->generatePluginFile($pluginName); $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePluginTemplate';
$replace = array(
'ExamplePluginTemplate' => $pluginName,
'ExampleDescription' => $description,
'0.1.0' => $version
);
$whitelistFiles = array(
'/ExamplePluginTemplate.php',
'/plugin.json',
'/README.md',
'/screenshots',
'/screenshots/.gitkeep',
'/javascripts',
'/javascripts/plugin.js',
);
} }
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$this->writeSuccessMessage($output, array( $this->writeSuccessMessage($output, array(
sprintf('%s %s %s generated.', $isTheme ? 'Theme' : 'Plugin', $pluginName, $version), sprintf('%s %s %s generated.', $isTheme ? 'Theme' : 'Plugin', $pluginName, $version),
'Enjoy!' 'Enjoy!'
)); ));
if ($createFullPlugin) { if ($createFullPlugin) {
$this->executePluginCommand($output, 'generate:api', $pluginName); $this->executePluginCommand($output, 'generate:api', $pluginName);
...@@ -92,36 +115,6 @@ class GeneratePlugin extends GeneratePluginBase ...@@ -92,36 +115,6 @@ class GeneratePlugin extends GeneratePluginBase
Filesystem::mkdir($pluginPath, true); Filesystem::mkdir($pluginPath, true);
} }
protected function generatePluginJson($pluginName, $version, $description, $isTheme)
{
$pluginJson = array(
'name' => $pluginName,
'version' => $version,
'description' => $description,
'theme' => $isTheme
);
if ($isTheme) {
$pluginJson['stylesheet'] = 'stylesheets/theme.less';
}
$content = json_encode($pluginJson);
$content = str_replace('",', "\",\n ", $content);
$this->createFileWithinPluginIfNotExists($pluginName, '/plugin.json', $content);
return $pluginJson;
}
/**
* @param string $pluginName
*/
protected function generatePluginFile($pluginName)
{
$template = file_get_contents(__DIR__ . '/templates/PluginTemplate.php');
$template = str_replace('PLUGINNAME', $pluginName, $template);
$this->createFileWithinPluginIfNotExists($pluginName, '/' . $pluginName . '.php', $template);
}
/** /**
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @param OutputInterface $output
......
...@@ -46,9 +46,11 @@ class GeneratePluginBase extends ConsoleCommand ...@@ -46,9 +46,11 @@ class GeneratePluginBase extends ConsoleCommand
/** /**
* @param string $templateNameOrPath eg. 'controller' or 'api' or a full path like /home/... * @param string $templateNameOrPath eg. 'controller' or 'api' or a full path like /home/...
* @param string $pluginName * @param string $pluginName
* @param array $replace array(key => value) $key will be replaced by $value in all templates * @param array $replace array(key => value) $key will be replaced by $value in all templates
* @param array $whitelistFiles If not empty, only given files/directories will be copied.
* For instance array('/Controller.php', '/templates', '/templates/index.twig')
*/ */
protected function copyTemplateToPlugin($templateNameOrPath, $pluginName, array $replace = array()) protected function copyTemplateToPlugin($templateNameOrPath, $pluginName, array $replace = array(), $whitelistFiles = array())
{ {
if (0 === strpos($templateNameOrPath, '/')) { if (0 === strpos($templateNameOrPath, '/')) {
$templateFolder = $templateNameOrPath; $templateFolder = $templateNameOrPath;
...@@ -63,6 +65,10 @@ class GeneratePluginBase extends ConsoleCommand ...@@ -63,6 +65,10 @@ class GeneratePluginBase extends ConsoleCommand
foreach ($files as $file) { foreach ($files as $file) {
$fileNamePlugin = str_replace($templateFolder, '', $file); $fileNamePlugin = str_replace($templateFolder, '', $file);
if (!empty($whitelistFiles) && !in_array($fileNamePlugin, $whitelistFiles)) {
continue;
}
if (is_dir($file)) { if (is_dir($file)) {
$this->createFolderWithinPluginIfNotExists($pluginName, $fileNamePlugin); $this->createFolderWithinPluginIfNotExists($pluginName, $fileNamePlugin);
} else { } else {
......
@theme-color-background-base: #141414;
@theme-color-background-contrast: #5F5A60;
@theme-color-background-smallContrast: #202020;
@theme-color-background-lighter: #888;
@theme-color-highlight1: #766F31;
@theme-color-highlight2: #6C9C50;
@theme-color-highlight3: #67E750;
@theme-color-text-link: @theme-color-highlight2;
@theme-color-text-base: #59867D;
@theme-color-text-lightFocus: #AAA;
@theme-color-text-focus: @theme-color-highlight3;
@theme-color-text-active: @theme-color-highlight1;
@theme-color-box-border: @theme-color-background-contrast;
@theme-color-box-active: @theme-color-background-smallContrast;
\ No newline at end of file
...@@ -6,22 +6,22 @@ ...@@ -6,22 +6,22 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* *
* @category Piwik_Plugins * @category Piwik_Plugins
* @package Piwik_PLUGINNAME * @package Piwik_ExamplePluginTemplate
*/ */
namespace Piwik\Plugins\PLUGINNAME; namespace Piwik\Plugins\ExamplePluginTemplate;
/** /**
* API for plugin PLUGINNAME * API for plugin ExamplePluginTemplate
* *
* @package Piwik_PLUGINNAME * @package Piwik_ExamplePluginTemplate
*/ */
class API extends \Piwik\Plugin\API class API extends \Piwik\Plugin\API
{ {
/** /**
* Example method. Please remove if you do not need this API method. * Example method. Please remove if you do not need this API method.
* You can call this API method like this: * You can call this API method like this:
* /index.php?module=API&method=PLUGINNAME.getAnswerToLife * /index.php?module=API&method=ExamplePluginTemplate.getAnswerToLife
* /index.php?module=API&method=PLUGINNAME.getAnswerToLife?truth=0 * /index.php?module=API&method=ExamplePluginTemplate.getAnswerToLife?truth=0
* *
* @param bool $truth * @param bool $truth
* *
......
...@@ -6,22 +6,22 @@ ...@@ -6,22 +6,22 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* *
* @category Piwik_Plugins * @category Piwik_Plugins
* @package PLUGINNAME * @package ExamplePluginTemplate
*/ */
namespace Piwik\Plugins\PLUGINNAME; namespace Piwik\Plugins\ExamplePluginTemplate;
use Piwik\View; use Piwik\View;
/** /**
* *
* @package PLUGINNAME * @package ExamplePluginTemplate
*/ */
class Controller extends \Piwik\Plugin\Controller class Controller extends \Piwik\Plugin\Controller
{ {
public function index() public function index()
{ {
$view = new View('@PLUGINNAME/index.twig'); $view = new View('@ExamplePluginTemplate/index.twig');
$this->setBasicVariablesView($view); $this->setBasicVariablesView($view);
$view->answerToLife = '42'; $view->answerToLife = '42';
......
...@@ -6,19 +6,19 @@ ...@@ -6,19 +6,19 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* *
* @category Piwik_Plugins * @category Piwik_Plugins
* @package PLUGINNAME * @package ExamplePluginTemplate
*/ */
namespace Piwik\Plugins\PLUGINNAME; namespace Piwik\Plugins\ExamplePluginTemplate;
use Piwik\Plugin; use Piwik\Plugin;
/** /**
* @package PLUGINNAME * @package ExamplePluginTemplate
*/ */
class PLUGINNAME extends Plugin class ExamplePluginTemplate extends Plugin
{ {
/** /**
* @see Piwik_Plugin::getListHooksRegistered * @see Piwik\Plugin::getListHooksRegistered
*/ */
public function getListHooksRegistered() public function getListHooksRegistered()
{ {
...@@ -29,6 +29,6 @@ class PLUGINNAME extends Plugin ...@@ -29,6 +29,6 @@ class PLUGINNAME extends Plugin
public function getJsFiles(&$jsFiles) public function getJsFiles(&$jsFiles)
{ {
$jsFiles[] = 'plugins/PLUGINNAME/javascripts/plugin.js'; $jsFiles[] = 'plugins/ExamplePluginTemplate/javascripts/plugin.js';
} }
} }
# Piwik PLUGINNAME Plugin # Piwik ExamplePluginTemplate Plugin
## Description ## Description
......
{
"name": "ExamplePluginTemplate",
"version": "0.1.0",
"description": "ExampleDescription",
"theme": false
}
\ No newline at end of file
# Piwik PLUGINNAME Theme # Piwik ExampleTheme Theme
## Description ## Description
......
{ {
"name": "PleineLune", "name": "ExampleTheme",
"description": "A dark theme for Piwik, ideal to view your analytics reports before sunrise.", "description": "ExampleDescription",
"version": "0.1.0",
"theme": true, "theme": true,
"stylesheet": "stylesheets/theme.less" "stylesheet": "stylesheets/theme.less"
} }
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter