Skip to content

Commit

Permalink
refs #4121 code cleanup and copy plugin/theme folder if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Oct 5, 2013
1 parent e217596 commit a12ae95
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 53 deletions.
61 changes: 17 additions & 44 deletions plugins/CoreConsole/GeneratePlugin.php
Expand Up @@ -12,7 +12,6 @@
namespace Piwik\Plugins\CoreConsole;

use Piwik\Common;
use Piwik\Console\Command;
use Piwik\Filesystem;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -22,7 +21,7 @@
/**
* @package CoreConsole
*/
class GeneratePlugin extends Command
class GeneratePlugin extends GeneratePluginBase
{
protected function configure()
{
Expand All @@ -45,23 +44,28 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->generatePluginFolder($pluginName);
$this->generatePluginJson($pluginName, $version, $description, $isTheme);
$this->generatePluginFiles($isTheme, $pluginName);

$title = $isTheme ? 'Theme' : 'Plugin';
if ($isTheme) {
$this->copyTemplateToPlugin('theme', $pluginName);
} else {
$this->copyTemplateToPlugin('plugin', $pluginName);
$this->generatePluginFile($pluginName);
}

$this->writeSuccessMessage($output, array(
sprintf('%s %s %s generated. Enjoy!', $title, $pluginName, $version)
sprintf('%s %s %s generated.', $isTheme ? 'Theme' : 'Plugin', $pluginName, $version),
'Enjoy!'
));

if (!empty($createFullPlugin)) {
if ($createFullPlugin) {
$this->executePluginCommand($output, 'generate:api', $pluginName);
$this->executePluginCommand($output, 'generate:controller', $pluginName);
}
}

private function executePluginCommand(OutputInterface $output, $commandName, $pluginName)
{
$command = $this->getApplication()->find($commandName);
$command = $this->getApplication()->find($commandName);
$arguments = array(
'command' => $commandName,
'--pluginname' => $pluginName
Expand All @@ -82,29 +86,12 @@ private function isTheme(InputInterface $input)
return false !== strpos($commandName, 'theme');
}

/**
* @param $pluginName
* @return string
*/
public function getPluginPath($pluginName)
{
$pluginPath = PIWIK_INCLUDE_PATH . '/plugins/' . ucfirst($pluginName);
return $pluginPath;
}

private function generatePluginFolder($pluginName)
{
$pluginPath = $this->getPluginPath($pluginName);
Filesystem::mkdir($pluginPath, true);
}

/**
* @param $pluginName
* @param $version
* @param $description
* @param $isTheme
* @return array
*/
private function generatePluginJson($pluginName, $version, $description, $isTheme)
{
$pluginJson = array(
Expand All @@ -120,33 +107,19 @@ private function generatePluginJson($pluginName, $version, $description, $isThem

$content = json_encode($pluginJson);
$content = str_replace('",', "\",\n ", $content);
$this->writePluginFile($pluginName, '/plugin.json', $content);
$this->createFileWithinPluginIfNotExists($pluginName, '/plugin.json', $content);

return $pluginJson;
}

private function writePluginFile($pluginName, $fileName, $content)
{
$pluginPath = $this->getPluginPath($pluginName);

file_put_contents($pluginPath . $fileName, $content);
}

/**
* @param $isTheme
* @param $pluginName
* @param string $pluginName
*/
private function generatePluginFiles($isTheme, $pluginName)
private function generatePluginFile($pluginName)
{
if ($isTheme) {
$pluginPath = $this->getPluginPath($pluginName);
Filesystem::mkdir($pluginPath . '/stylesheets', false);
$this->writePluginFile($pluginName, '/stylesheets/theme.less', '');
} else {
$template = file_get_contents(__DIR__ . '/templates/PluginTemplate.php');
$pluginFile = str_replace('PLUGINNAME', $pluginName, $template);
$this->writePluginFile($pluginName, '/' . $pluginName . '.php', $pluginFile);
}
$template = file_get_contents(__DIR__ . '/templates/PluginTemplate.php');
$template = str_replace('PLUGINNAME', $pluginName, $template);
$this->createFileWithinPluginIfNotExists($pluginName, '/' . $pluginName . '.php', $template);
}

/**
Expand Down
13 changes: 4 additions & 9 deletions plugins/CoreConsole/GeneratePluginBase.php
Expand Up @@ -22,14 +22,9 @@
*/
class GeneratePluginBase extends Command
{
/**
* @param $pluginName
* @return string
*/
protected function getPluginPath($pluginName)
public function getPluginPath($pluginName)
{
$pluginPath = PIWIK_INCLUDE_PATH . '/plugins/' . ucfirst($pluginName);
return $pluginPath;
return PIWIK_INCLUDE_PATH . '/plugins/' . ucfirst($pluginName);
}

private function createFolderWithinPluginIfNotExists($pluginName, $folder)
Expand All @@ -41,7 +36,7 @@ private function createFolderWithinPluginIfNotExists($pluginName, $folder)
}
}

private function createFileWithinPluginIfNotExists($pluginName, $fileName, $content)
protected function createFileWithinPluginIfNotExists($pluginName, $fileName, $content)
{
$pluginPath = $this->getPluginPath($pluginName);

Expand All @@ -66,7 +61,7 @@ protected function copyTemplateToPlugin($templateName, $pluginName)
if (is_dir($file)) {
$this->createFolderWithinPluginIfNotExists($pluginName, $fileNamePlugin);
} else {
$template = file_get_contents($file);
$template = file_get_contents($file);
$template = str_replace('PLUGINNAME', $pluginName, $template);
$this->createFileWithinPluginIfNotExists($pluginName, $fileNamePlugin, $template);
}
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions plugins/CoreConsole/templates/theme/stylesheets/theme.less
@@ -0,0 +1,15 @@
@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;

0 comments on commit a12ae95

Please sign in to comment.