Commit: 05c24e95f0dcd27d7905029547eae112cb75dcf7
Author: gwoo | Date: 2009-12-24 10:44:57 -0800
diff --git a/controllers/BrowserController.php b/controllers/BrowserController.php
index 928b79e..519a143 100644
--- a/controllers/BrowserController.php
+++ b/controllers/BrowserController.php
@@ -1,4 +1,10 @@
<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
namespace li3_docs\controllers;
diff --git a/extensions/command/Docs.php b/extensions/command/Docs.php
new file mode 100644
index 0000000..9681583
--- /dev/null
+++ b/extensions/command/Docs.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_docs\extensions\command;
+
+use li3_docs\extensions\command\docs\Generator;
+use li3_docs\extensions\command\docs\Todo;
+
+/**
+ * Adds headers and docblocks to classes and methods.
+ */
+class Docs extends \lithium\console\Command {
+
+ public function run() {
+
+ }
+
+ public function generator() {
+ $generator = new Generator(array('request' => $this->request));
+ return $generator->run();
+ }
+
+ public function todo() {
+ $todo = new Todo(array('request' => $this->request));
+ return $todo->run();
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/extensions/command/docs/Generator.php b/extensions/command/docs/Generator.php
new file mode 100644
index 0000000..9df305a
--- /dev/null
+++ b/extensions/command/docs/Generator.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_docs\extensions\command\docs;
+
+use \lithium\core\Libraries;
+use \lithium\util\reflection\Inspector;
+
+/**
+ * Adds headers and docblocks to classes and methods
+ *
+ **/
+class Generator extends \lithium\console\Command {
+
+ public function run() {
+ $classes = Libraries::find(true, array(
+ 'exclude' => "/webroot|index$|^app\\\\config|^app\\\\views/",
+ 'recursive' => true
+ ));
+
+ foreach($classes as $class) {
+ $path = Libraries::path($class);
+ $contents = explode("\n", file_get_contents($path));
+ $contents = $this->_header($contents);
+ if (file_put_contents($path, implode("\n", $contents))) {
+ $this->out($path . ' written');
+ }
+ }
+ }
+
+ protected function _header($contents) {
+ if (strpos($contents[1], '*') === false) {
+ $header = explode("\n", file_get_contents(
+ dirname(__DIR__) . '/template/docs/header.txt.php')
+ );
+ $one = array_shift($contents);
+ $contents = array_merge($header, $contents);
+ array_unshift($contents, $one);
+ }
+ return $contents;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/extensions/command/docs/Todo.php b/extensions/command/docs/Todo.php
new file mode 100644
index 0000000..e95a8cd
--- /dev/null
+++ b/extensions/command/docs/Todo.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_docs\extensions\command\docs;
+
+use \lithium\core\Libraries;
+use \lithium\util\Inflector;
+use \lithium\util\reflection\Parser;
+
+/**
+ * Searches and displays @todo, @discuss, @fix and @important comments in your code.
+ */
+class Todo extends \lithium\console\Command {
+
+ /**
+ * undocumented variable
+ *
+ * @var id
+ */
+ public $show = true;
+
+ /**
+ * undocumented function
+ *
+ * @param string $dir
+ * @return void
+ */
+ public function run($library = 'lithium') {
+ $libs = Libraries::find($library, array('recursive' => true));
+ $files = array();
+
+ foreach ((array)$libs as $lib) {
+ $file = Libraries::path($lib);
+ $this->_display($file);
+ }
+ }
+
+ protected function _display($file) {
+ $matches = Parser::tokenize(file_get_contents($file));
+ if (empty($matches)) {
+ $this->stop(1, 'no matches');
+ }
+ if (!$this->show) {
+ $this->out($file.':');
+ }
+ $rows = array(array('', 'ID', 'LINE', 'TYPE', 'TEXT'));
+ foreach ($matches as $match) {
+ $id = substr(sha1($file . $match['line']), 0, 4);
+ if ($id == $this->show) {
+ $this->stop(0, $file);
+ }
+ $rows[] = array('', $id, $match['line'], $match['type'], $match['text']);
+ }
+ if (!$this->show) {
+ $this->out($this->columns($rows));
+ $this->hr();
+ $this->nl();
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/extensions/command/template/docs/header.txt.php b/extensions/command/template/docs/header.txt.php
new file mode 100644
index 0000000..988a712
--- /dev/null
+++ b/extensions/command/template/docs/header.txt.php
@@ -0,0 +1,6 @@
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
\ No newline at end of file
diff --git a/tests/cases/extensions/command/DocsTest.php b/tests/cases/extensions/command/DocsTest.php
new file mode 100644
index 0000000..46f781d
--- /dev/null
+++ b/tests/cases/extensions/command/DocsTest.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_docs\tests\cases\extensions\command;
+
+use \li3_docs\extensions\command\Docs;
+
+class DocsTest extends \lithium\test\Unit {
+}
+
+?>
\ No newline at end of file
diff --git a/tests/cases/extensions/command/docs/GeneratorTest.php b/tests/cases/extensions/command/docs/GeneratorTest.php
new file mode 100644
index 0000000..736b718
--- /dev/null
+++ b/tests/cases/extensions/command/docs/GeneratorTest.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_docs\tests\cases\extensions\command\docs;
+
+use \li3_docs\extensions\command\docs\Generator;
+
+class GeneratorTest extends \lithium\test\Unit {
+}
+
+?>
\ No newline at end of file
diff --git a/tests/cases/extensions/command/docs/TodoTest.php b/tests/cases/extensions/command/docs/TodoTest.php
new file mode 100644
index 0000000..c2e39bf
--- /dev/null
+++ b/tests/cases/extensions/command/docs/TodoTest.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_docs\tests\cases\extensions\command\docs;
+
+use \li3_docs\extensions\command\docs\Todo;
+
+class TodoTest extends \lithium\test\Unit {
+}
+
+?>
\ No newline at end of file