Skip to content
This repository
Browse code

Implementing a new option 'exclude-plugins' from the ExtractTask

  • Loading branch information...
commit 991501d489a11bb57c261c70e9b28aad3136f4e0 1 parent e669a81
José Lorenzo Rodríguez authored May 27, 2011
66  lib/Cake/Console/Command/Task/ExtractTask.php
@@ -113,7 +113,7 @@ public function execute() {
113 113
 		if (isset($this->params['paths'])) {
114 114
 			$this->_paths = explode(',', $this->params['paths']);
115 115
 		} else {
116  
-			$defaultPath = APP_PATH;
  116
+			$defaultPath = APP;
117 117
 			$message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one");
118 118
 			while (true) {
119 119
 				$response = $this->in($message, null, $defaultPath);
@@ -133,6 +133,10 @@ public function execute() {
133 133
 			}
134 134
 		}
135 135
 
  136
+		if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
  137
+			$this->_exclude = array_merge($this->_exclude, App::path('plugins'));
  138
+		}
  139
+
136 140
 		if (isset($this->params['output'])) {
137 141
 			$this->_output = $this->params['output'];
138 142
 		} else {
@@ -208,40 +212,25 @@ public function getOptionParser() {
208 212
 			))
209 213
 			->addOption('output', array('help' => __d('cake_console', 'Full path to output directory.')))
210 214
 			->addOption('files', array('help' => __d('cake_console', 'Comma separated list of files.')))
  215
+			->addOption('exclude-plugins', array(
  216
+				'boolean' => true,
  217
+				'default' => true,
  218
+				'help' => __d('cake_console', 'Ignores all files in plugins.')
  219
+			))
  220
+			->addOption('ignore-model-validation', array(
  221
+				'boolean' => true,
  222
+				'default' => false,
  223
+				'help' => __d('cake_console', 'Ignores validation messages in the $validate property. Needs to be run in from the same app directory')
  224
+			))
  225
+			->addOption('validation-domain', array(
  226
+				'help' => __d('cake_console', 'If set to a value, the localization domain to be used for model validation messages')
  227
+			))
211 228
 			->addOption('exclude', array(
212 229
 				'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')
213 230
 			));
214 231
 	}
215 232
 
216 233
 /**
217  
- * Show help options
218  
- *
219  
- * @return void
220  
- */
221  
-	public function help() {
222  
-		$this->out(__d('cake_console', 'CakePHP Language String Extraction:'));
223  
-		$this->hr();
224  
-		$this->out(__d('cake_console', 'The Extract script generates .pot file(s) with translations'));
225  
-		$this->out(__d('cake_console', 'By default the .pot file(s) will be place in the locale directory of -app'));
226  
-		$this->out(__d('cake_console', 'By default -app is ROOT/app'));
227  
-		$this->hr();
228  
-		$this->out(__d('cake_console', 'Usage: cake i18n extract <command> <param1> <param2>...'));
229  
-		$this->out();
230  
-		$this->out(__d('cake_console', 'Params:'));
231  
-		$this->out(__d('cake_console', '   -app [path...]: directory where your application is located'));
232  
-		$this->out(__d('cake_console', '   -root [path...]: path to install'));
233  
-		$this->out(__d('cake_console', '   -core [path...]: path to cake directory'));
234  
-		$this->out(__d('cake_console', '   -paths [comma separated list of paths]'));
235  
-		$this->out(__d('cake_console', '   -merge [yes|no]: Merge all domains strings into the default.pot file'));
236  
-		$this->out(__d('cake_console', '   -output [path...]: Full path to output directory'));
237  
-		$this->out(__d('cake_console', '   -files: [comma separated list of files]'));
238  
-		$this->out();
239  
-		$this->out(__d('cake_console', 'Commands:'));
240  
-		$this->out(__d('cake_console', '   cake i18n extract help: Shows this help message.'));
241  
-		$this->out();
242  
-	}
243  
-
244  
-/**
245 234
  * Extract tokens out of all files to be processed
246 235
  *
247 236
  * @return void
@@ -524,7 +513,14 @@ protected function _markerError($file, $line, $marker, $count) {
524 513
 	protected function _searchFiles() {
525 514
 		$pattern = false;
526 515
 		if (!empty($this->_exclude)) {
527  
-			$pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/';
  516
+			$exclude = array();
  517
+			foreach ($this->_exclude as $e) {
  518
+				if ($e[0] !== DS) {
  519
+					$e = DS . $e;
  520
+				}
  521
+				$exclude[] = preg_quote($e, '/');
  522
+			}
  523
+			$pattern =  '/' . implode('|', $exclude) . '/';
528 524
 		}
529 525
 		foreach ($this->_paths as $path) {
530 526
 			$Folder = new Folder($path);
@@ -540,4 +536,14 @@ protected function _searchFiles() {
540 536
 			$this->_files = array_merge($this->_files, $files);
541 537
 		}
542 538
 	}
  539
+
  540
+/**
  541
+ * Returns whether this execution is meant to extract string only from directories in folder represented by the
  542
+ * APP constant, i.e. this task is extracting strings from same application.
  543
+ *
  544
+ * @return boolean
  545
+ */
  546
+	protected function _isExtractingApp() {
  547
+		return $this->_paths === array(APP);
  548
+	}
543 549
 }
29  lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php
@@ -202,4 +202,33 @@ function testExtractMultiplePaths() {
202 202
 		$pattern = '/msgid "Add User"/';
203 203
 		$this->assertPattern($pattern, $result);
204 204
 	}
  205
+
  206
+/**
  207
+ * Tests that it is possible to exclude plugin paths by enabling the param option for the ExtractTask
  208
+ *
  209
+ * @return void
  210
+ */
  211
+	public function testExtractExcludePlugins() {
  212
+		$this->Task->params['paths'] = array(
  213
+			CAKE . 'Test' . DS . 'test_app'
  214
+		);
  215
+		App::build(array(
  216
+			'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  217
+		));
  218
+		$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  219
+		$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
  220
+		$this->Task = $this->getMock('ExtractTask',
  221
+			array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
  222
+			array($this->out, $this->out, $this->in)
  223
+		);
  224
+		$this->Task->expects($this->once())->method('_isExtractingApp')->will($this->returnValue(true));
  225
+
  226
+		$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
  227
+		$this->Task->params['output'] = $this->path . DS;
  228
+		$this->Task->params['exclude-plugins'] = true;
  229
+
  230
+		$this->Task->execute();
  231
+		$result = file_get_contents($this->path . DS . 'default.pot');
  232
+		$this->assertNoPattern('#TesPlugin#', $result);
  233
+	}
205 234
 }
1  lib/Cake/Test/test_app/Plugin/TestPlugin/View/Elements/translate.ctp
... ...
@@ -0,0 +1 @@
  1
+<?php __('This is a translatable string'); ?>

0 notes on commit 991501d

Please sign in to comment.
Something went wrong with that request. Please try again.