From d2519ae0ae064f4063a6ded72a07d3267affce19 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 7 Jul 2011 01:57:55 -0430 Subject: [PATCH] Adding support to the extract task to operate on a single plugin, thus removing the hassle of declaring the plugin path in command line --- lib/Cake/Console/Command/Task/ExtractTask.php | 21 +++++++++---- .../Console/Command/Task/ExtractTaskTest.php | 30 ++++++++++++++++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 61ce73f11..80b765230 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -126,6 +126,12 @@ class ExtractTask extends Shell { } if (isset($this->params['paths'])) { $this->_paths = explode(',', $this->params['paths']); + } else if (isset($this->params['plugin'])) { + $plugin = Inflector::camelize($this->params['plugin']); + if (!CakePlugin::loaded($plugin)) { + CakePlugin::load($plugin); + } + $this->_paths = array(CakePlugin::path($plugin)); } else { $defaultPath = APP; $message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one"); @@ -160,10 +166,12 @@ class ExtractTask extends Shell { if (isset($this->params['output'])) { $this->_output = $this->params['output']; + } else if (isset($this->params['plugin'])) { + $this->_output = $this->_paths[0] . DS . 'Locale'; } else { - $message = __d('cake_console', "What is the path you would like to output?\n[Q]uit", $this->_paths[0] . DS . 'locale'); + $message = __d('cake_console', "What is the path you would like to output?\n[Q]uit", $this->_paths[0] . DS . 'Locale'); while (true) { - $response = $this->in($message, null, $this->_paths[0] . DS . 'locale'); + $response = $this->in($message, null, $this->_paths[0] . DS . 'Locale'); if (strtoupper($response) === 'Q') { $this->out(__d('cake_console', 'Extract Aborted')); $this->_stop(); @@ -238,15 +246,18 @@ class ExtractTask extends Shell { ->addOption('exclude-plugins', array( 'boolean' => true, 'default' => true, - 'help' => __d('cake_console', 'Ignores all files in plugins if this command is run inside from the same app directory') + 'help' => __d('cake_console', 'Ignores all files in plugins if this command is run inside from the same app directory.') + )) + ->addOption('plugin', array( + 'help' => __d('cake_console', 'Extracts tokens only from the plugin specified and puts the result in the plugin\'s Locale directory.') )) ->addOption('ignore-model-validation', array( 'boolean' => true, 'default' => false, - 'help' => __d('cake_console', 'Ignores validation messages in the $validate property. If this flag is not set and the command is run from the same app directory, all messages in model validation rules will be extracted as tokens') + 'help' => __d('cake_console', 'Ignores validation messages in the $validate property. If this flag is not set and the command is run from the same app directory, all messages in model validation rules will be extracted as tokens.') )) ->addOption('validation-domain', array( - 'help' => __d('cake_console', 'If set to a value, the localization domain to be used for model validation messages') + 'help' => __d('cake_console', 'If set to a value, the localization domain to be used for model validation messages.') )) ->addOption('exclude', array( 'help' => __d('cake_console', 'Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors') diff --git a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php index 6f2cdb859..4a45e9d6a 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php @@ -227,7 +227,35 @@ class ExtractTaskTest extends CakeTestCase { $this->Task->execute(); $result = file_get_contents($this->path . DS . 'default.pot'); - $this->assertNoPattern('#TesPlugin#', $result); + $this->assertNoPattern('#TestPlugin#', $result); + } + +/** + * Test that is possible to extract messages form a single plugin + * + * @return void + */ + public function testExtractPlugin() { + App::build(array( + 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) + )); + + $this->out = $this->getMock('ConsoleOutput', array(), array(), '', false); + $this->in = $this->getMock('ConsoleInput', array(), array(), '', false); + $this->Task = $this->getMock('ExtractTask', + array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'), + array($this->out, $this->out, $this->in) + ); + + $this->Task->params['output'] = $this->path . DS; + $this->Task->params['plugin'] = 'TestPlugin'; + + $this->Task->execute(); + $result = file_get_contents($this->path . DS . 'default.pot'); + $this->assertNoPattern('#Pages#', $result); + $this->assertContains('translate.ctp:1', $result); + $this->assertContains('This is a translatable string', $result); + CakePlugin::unload(); } /**