Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving bake templates into templates/default.

Adding 'console template themes' to TemplateTask.
Adding test cases for console themes.
Moving files around.
  • Loading branch information...
commit ad98139e35b46f17ed742d7985523ca550210b0b 1 parent 9627af2
@markstory markstory authored
View
94 cake/console/libs/tasks/template.php
@@ -2,7 +2,6 @@
/**
* Template Task can generate templated output Used in other Tasks
*
- *
*
* PHP versions 4 and 5
*
@@ -26,39 +25,48 @@ class TemplateTask extends Shell {
* @var array
**/
var $templateVars = array();
-
+
/**
* Paths to look for templates on.
+ * Contains a list of $theme => $path
*
* @var array
**/
var $templatePaths = array();
+
/**
- * Initialize callback
+ * Initialize callback. Setup paths for the template task.
*
* @access public
* @return void
**/
function initialize() {
- $this->templatePaths = $this->Dispatch->shellPaths;
+ $this->templatePaths = $this->_findThemes();
}
/**
- * Find a template
+ * Find the paths to all the installed shell themes in the app.
*
- * @param string $directory Subdirectory to look for ie. 'views', 'objects'
- * @param string $filename lower_case_underscored filename you want.
- * @access public
- * @return string filename or false if scan failed.
+ * Bake themes are directories not named `skel` inside a `vendors/shells/templates` path.
+ *
+ * @return array Array of bake themes that are installed.
**/
- function _findTemplate($directory, $filename) {
- foreach ($this->templatePaths as $path) {
- $templatePath = $path . 'templates' . DS . $directory . DS . $filename . '.ctp';
- if (file_exists($templatePath) && is_file($templatePath)) {
- return $templatePath;
+ function _findThemes() {
+ $paths = $this->Dispatch->shellPaths;
+ $themes = array();
+ foreach ($paths as $path) {
+ $Folder =& new Folder($path . 'templates', false);
+ $contents = $Folder->read();
+ $subDirs = $contents[0];
+ foreach ($subDirs as $dir) {
+ if (empty($dir) || $dir == 'skel') {
+ continue;
+ }
+ $templateDir = $path . 'templates' . DS . $dir . DS;
+ $themes[$dir] = $templateDir;
}
}
- return false;
+ return $themes;
}
/**
@@ -106,7 +114,8 @@ function generate($directory, $filename, $vars = null) {
if (empty($this->templatePaths)) {
$this->initialize();
}
- $templateFile = $this->_findTemplate($directory, $filename);
+ $themePath = $this->getThemePath();
+ $templateFile = $this->_findTemplate($themePath, $directory, $filename);
if ($templateFile) {
extract($this->templateVars);
ob_start();
@@ -117,4 +126,57 @@ function generate($directory, $filename, $vars = null) {
}
return '';
}
+
+/**
+ * Find the theme name for the current operation.
+ * If there is only one theme in $templatePaths it will be used.
+ * If there is a -theme param in the cli args, it will be used.
+ * If there is more than one installed theme user interaction will happen
+ *
+ * @return string returns the path to the selected theme.
+ **/
+ function getThemePath() {
+ if (count($this->templatePaths) == 1) {
+ $paths = array_values($this->templatePaths);
+ return $paths[0];
+ }
+ if (!empty($this->params['theme']) && isset($this->templatePaths[$this->params['theme']])) {
+ return $this->templatePaths[$this->params['theme']];
+ }
+ $i = 1;
+ $indexedPaths = array();
+ foreach ($this->templatePaths as $key => $path) {
+ $this->out($i . '. ' . $key);
+ $indexedPaths[$i] = $path;
+ $i++;
+ }
+ $index = $this->in(__('Which bake theme would you like to use?', true), range(1, $i), 1);
+ return $indexedPaths[$index];
+ }
+
+/**
+ * Find a template inside a directory inside a path.
+ * Will scan all other theme dirs if the template is not found in the first directory.
+ *
+ * @param string $path The initial path to look for the file on. If it is not found fallbacks will be used.
+ * @param string $directory Subdirectory to look for ie. 'views', 'objects'
+ * @param string $filename lower_case_underscored filename you want.
+ * @access public
+ * @return string filename will exit program if template is not found.
+ **/
+ function _findTemplate($path, $directory, $filename) {
+ $themeFile = $path . $directory . DS . $filename . '.ctp';
+ if (file_exists($themeFile)) {
+ return $themeFile;
+ }
+ foreach ($this->templatePaths as $path) {
+ $templatePath = $path . $directory . DS . $filename . '.ctp';
+ if (file_exists($templatePath)) {
+ return $templatePath;
+ }
+ }
+ $this->err(sprintf(__('Could not find template for %s, exiting.'), $filename));
+ $this->_stop();
+ }
+
}
View
142 cake/console/libs/templates/default/actions/controller_actions.ctp
@@ -0,0 +1,142 @@
+<?php
+/**
+ * Bake Template for Controller action generation.
+ *
+ *
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package cake
+ * @subpackage cake.console.libs.template.objects
+ * @since CakePHP(tm) v 1.3
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+?>
+
+ function <?php echo $admin ?>index() {
+ $this-><?php echo $currentModelName ?>->recursive = 0;
+ $this->set('<?php echo $pluralName ?>', $this->paginate());
+ }
+
+ function <?php echo $admin ?>view($id = null) {
+ if (!$id) {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('Invalid <?php echo $singularHumanName ?>', true));
+ $this->redirect(array('action' => 'index'));
+<?php else: ?>
+ $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
+<?php endif; ?>
+ }
+ $this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
+ }
+
+<?php $compact = array(); ?>
+ function <?php echo $admin ?>add() {
+ if (!empty($this->data)) {
+ $this-><?php echo $currentModelName; ?>->create();
+ if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
+ $this->redirect(array('action' => 'index'));
+<?php else: ?>
+ $this->flash(__('<?php echo $currentModelName; ?> saved.', true), array('action' => 'index'));
+<?php endif; ?>
+ } else {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> could not be saved. Please, try again.', true));
+<?php endif; ?>
+ }
+ }
+<?php
+ foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
+ foreach ($modelObj->{$assoc} as $associationName => $relation):
+ if (!empty($associationName)):
+ $otherModelName = $this->_modelName($associationName);
+ $otherPluralName = $this->_pluralName($associationName);
+ echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
+ $compact[] = "'{$otherPluralName}'";
+ endif;
+ endforeach;
+ endforeach;
+ if (!empty($compact)):
+ echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
+ endif;
+?>
+ }
+
+<?php $compact = array(); ?>
+ function <?php echo $admin; ?>edit($id = null) {
+ if (!$id && empty($this->data)) {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('Invalid <?php echo $singularHumanName; ?>', true));
+ $this->redirect(array('action' => 'index'));
+<?php else: ?>
+ $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
+<?php endif; ?>
+ }
+ if (!empty($this->data)) {
+ if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
+ $this->redirect(array('action' => 'index'));
+<?php else: ?>
+ $this->flash(__('The <?php echo $singularHumanName; ?> has been saved.', true), array('action' => 'index'));
+<?php endif; ?>
+ } else {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> could not be saved. Please, try again.', true));
+<?php endif; ?>
+ }
+ }
+ if (empty($this->data)) {
+ $this->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
+ }
+<?php
+ foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
+ foreach ($modelObj->{$assoc} as $associationName => $relation):
+ if (!empty($associationName)):
+ $otherModelName = $this->_modelName($associationName);
+ $otherPluralName = $this->_pluralName($associationName);
+ echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
+ $compact[] = "'{$otherPluralName}'";
+ endif;
+ endforeach;
+ endforeach;
+ if (!empty($compact)):
+ echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
+ endif;
+ ?>
+ }
+
+ function <?php echo $admin; ?>delete($id = null) {
+ if (!$id) {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('Invalid id for <?php echo $singularHumanName; ?>', true));
+ $this->redirect(array('action'=>'index'));
+<?php else: ?>
+ $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
+<?php endif; ?>
+ }
+ if ($this-><?php echo $currentModelName; ?>->del($id)) {
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('<?php echo $singularHumanName; ?> deleted', true));
+ $this->redirect(array('action'=>'index'));
+<?php else: ?>
+ $this->flash(__('<?php echo $singularHumanName; ?> deleted', true), array('action' => 'index'));
+<?php endif; ?>
+ }
+<?php if ($wannaUseSession): ?>
+ $this->Session->setFlash(__('<?php echo $singularHumanName; ?> was not deleted', true));
+<?php else: ?>
+ $this->flash(__('<?php echo $singularHumanName; ?> was not deleted', true), array('action' => 'index'));
+<?php endif; ?>
+ $this->redirect(array('action' => 'index'));
+ }
View
57 cake/console/libs/templates/default/classes/controller.ctp
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Controller bake template file
+ *
+ * Allows templating of Controllers generated from bake.
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package cake
+ * @subpackage cake.
+ * @since CakePHP(tm) v 1.3
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+echo "<?php\n";
+?>
+class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController {
+
+ var $name = '<?php echo $controllerName; ?>';
+<?php if ($isScaffold): ?>
+ var $scaffold;
+<?php else: ?>
+<?php
+
+echo "\tvar \$helpers = array('Html', 'Form'";
+if (count($helpers)):
+ foreach ($helpers as $help):
+ echo ", '" . Inflector::camelize($help) . "'";
+ endforeach;
+endif;
+echo ");\n";
+
+if (count($components)):
+ echo "\tvar \$components = array(";
+ for ($i = 0, $len = count($components); $i < $len; $i++):
+ if ($i != $len - 1):
+ echo "'" . Inflector::camelize($components[$i]) . "', ";
+ else:
+ echo "'" . Inflector::camelize($components[$i]) . "'";
+ endif;
+ endfor;
+ echo ");\n";
+endif;
+
+echo $actions;
+
+endif; ?>
+}
+<?php echo "?>"; ?>
View
42 cake/console/libs/templates/default/classes/fixture.ctp
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Fixture Template file
+ *
+ * Fixture Template used when baking fixtures with bake
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package cake
+ * @subpackage cake.
+ * @since CakePHP(tm) v 1.3
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+?>
+<?php echo '<?php' . "\n"; ?>
+/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:m:s') . " : ". time(); ?> */
+class <?php echo $model; ?>Fixture extends CakeTestFixture {
+ var $name = '<?php echo $model; ?>';
+<?php if ($table): ?>
+ var $table = '<?php echo $table; ?>';
+<?php endif; ?>
+<?php if ($import): ?>
+ var $import = <?php echo $import; ?>;
+<?php endif;?>
+
+<?php if ($schema): ?>
+ var $fields = <?php echo $schema; ?>;
+<?php endif;?>
+
+<?php if ($records): ?>
+ var $records = <?php echo $records; ?>;
+<?php endif;?>
+}
+<?php echo '?>'; ?>
View
127 cake/console/libs/templates/default/classes/model.ctp
@@ -0,0 +1,127 @@
+<?php
+/**
+ * Model template file.
+ *
+ * Used by bake to create new Model files.
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package cake
+ * @subpackage cake.console.libs.templates.objects
+ * @since CakePHP(tm) v 1.3
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+echo "<?php\n"; ?>
+class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
+ var $name = '<?php echo $name; ?>';
+<?php if ($useDbConfig != 'default'): ?>
+ var $useDbConfig = '<?php echo $useDbConfig; ?>';
+<?php endif;?>
+<?php if ($useTable && $useTable !== Inflector::tableize($name)):
+ $table = "'$useTable'";
+ echo "\tvar \$useTable = $table;\n";
+endif;
+if ($primaryKey !== 'id'): ?>
+ var $primaryKey = '<?php echo $primaryKey; ?>';
+<?php endif;
+
+if (!empty($validate)):
+ echo "\tvar \$validate = array(\n";
+ foreach ($validate as $field => $validations):
+ echo "\t\t'$field' => array(\n";
+ foreach ($validations as $key => $validator):
+ echo "\t\t\t'$key' => array('rule' => array('$validator')),\n";
+ endforeach;
+ echo "\t\t),\n";
+ endforeach;
+ echo "\t);\n";
+endif;
+
+?>
+ //The Associations below have been created with all possible keys, those that are not needed can be removed
+<?php
+
+foreach (array('hasOne', 'belongsTo') as $assocType):
+ if (!empty($associations[$assocType])):
+ $typeCount = count($associations[$assocType]);
+ echo "\n\tvar \$$assocType = array(";
+ foreach ($associations[$assocType] as $i => $relation):
+ $out = "\n\t\t'{$relation['alias']}' => array(\n";
+ $out .= "\t\t\t'className' => '{$relation['className']}',\n";
+ $out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
+ $out .= "\t\t\t'conditions' => '',\n";
+ $out .= "\t\t\t'fields' => '',\n";
+ $out .= "\t\t\t'order' => ''\n";
+ $out .= "\t\t)";
+ if ($i + 1 < $typeCount) {
+ $out .= ",";
+ }
+ echo $out;
+ endforeach;
+ echo "\n\t);\n";
+ endif;
+endforeach;
+
+if (!empty($associations['hasMany'])):
+ $belongsToCount = count($associations['hasMany']);
+ echo "\n\tvar \$hasMany = array(";
+ foreach ($associations['hasMany'] as $i => $relation):
+ $out = "\n\t\t'{$relation['alias']}' => array(\n";
+ $out .= "\t\t\t'className' => '{$relation['className']}',\n";
+ $out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
+ $out .= "\t\t\t'dependent' => false,\n";
+ $out .= "\t\t\t'conditions' => '',\n";
+ $out .= "\t\t\t'fields' => '',\n";
+ $out .= "\t\t\t'order' => '',\n";
+ $out .= "\t\t\t'limit' => '',\n";
+ $out .= "\t\t\t'offset' => '',\n";
+ $out .= "\t\t\t'exclusive' => '',\n";
+ $out .= "\t\t\t'finderQuery' => '',\n";
+ $out .= "\t\t\t'counterQuery' => ''\n";
+ $out .= "\t\t)";
+ if ($i + 1 < $belongsToCount) {
+ $out .= ",";
+ }
+ echo $out;
+ endforeach;
+ echo "\n\t);\n\n";
+endif;
+
+if (!empty($associations['hasAndBelongsToMany'])):
+ $habtmCount = count($associations['hasAndBelongsToMany']);
+ echo "\n\tvar \$hasAndBelongsToMany = array(";
+ foreach ($associations['hasAndBelongsToMany'] as $i => $relation):
+ $out = "\n\t\t'{$relation['alias']}' => array(\n";
+ $out .= "\t\t\t'className' => '{$relation['className']}',\n";
+ $out .= "\t\t\t'joinTable' => '{$relation['joinTable']}',\n";
+ $out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
+ $out .= "\t\t\t'associationForeignKey' => '{$relation['associationForeignKey']}',\n";
+ $out .= "\t\t\t'unique' => true,\n";
+ $out .= "\t\t\t'conditions' => '',\n";
+ $out .= "\t\t\t'fields' => '',\n";
+ $out .= "\t\t\t'order' => '',\n";
+ $out .= "\t\t\t'limit' => '',\n";
+ $out .= "\t\t\t'offset' => '',\n";
+ $out .= "\t\t\t'finderQuery' => '',\n";
+ $out .= "\t\t\t'deleteQuery' => '',\n";
+ $out .= "\t\t\t'insertQuery' => ''\n";
+ $out .= "\t\t)";
+ if ($i + 1 < $habtmCount) {
+ $out .= ",";
+ }
+ echo $out;
+ endforeach;
+ echo "\n\t);\n\n";
+endif;
+?>
+}
+<?php echo '?>'; ?>
View
57 cake/console/libs/templates/default/classes/test.ctp
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Test Case bake template
+ *
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package cake
+ * @subpackage cake.console.libs.templates.objects
+ * @since CakePHP(tm) v 1.3
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+echo "<?php\n";
+echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n";
+?>
+App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');
+
+<?php if ($mock and strtolower($type) == 'controller'): ?>
+class Test<?php echo $fullClassName; ?> extends <?php echo $fullClassName; ?> {
+ var $autoRender = false;
+
+ function redirect($url, $status = null, $exit = true) {
+ $this->redirectUrl = $url;
+ }
+}
+
+<?php endif; ?>
+class <?php echo $fullClassName; ?>TestCase extends CakeTestCase {
+<?php if (!empty($fixtures)): ?>
+ var $fixtures = array('<?php echo join("', '", $fixtures); ?>');
+
+<?php endif; ?>
+ function startTest() {
+ $this-><?php echo $className . ' =& ' . $construction; ?>
+ }
+
+ function endTest() {
+ unset($this-><?php echo $className;?>);
+ ClassRegistry::flush();
+ }
+
+<?php foreach ($methods as $method): ?>
+ function test<?php echo Inflector::classify($method); ?>() {
+
+ }
+
+<?php endforeach;?>
+}
+<?php echo '?>'; ?>
View
69 cake/console/libs/templates/default/views/form.ctp
@@ -0,0 +1,69 @@
+<?php
+/* SVN FILE: $Id$ */
+/**
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake
+ * @subpackage cake.cake.console.libs.templates.views
+ * @since CakePHP(tm) v 1.2.0.5234
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+?>
+<div class="<?php echo $pluralVar;?> form">
+<?php echo "<?php echo \$form->create('{$modelClass}');?>\n";?>
+ <fieldset>
+ <legend><?php echo "<?php __('".Inflector::humanize($action)." {$singularHumanName}');?>";?></legend>
+<?php
+ echo "\t<?php\n";
+ foreach ($fields as $field) {
+ if ($action == 'add' && $field == $primaryKey) {
+ continue;
+ } elseif (!in_array($field, array('created', 'modified', 'updated'))) {
+ echo "\t\techo \$form->input('{$field}');\n";
+ }
+ }
+ if (!empty($associations['hasAndBelongsToMany'])) {
+ foreach ($associations['hasAndBelongsToMany'] as $assocName => $assocData) {
+ echo "\t\techo \$form->input('{$assocName}');\n";
+ }
+ }
+ echo "\t?>\n";
+?>
+ </fieldset>
+<?php
+ echo "<?php echo \$form->end('Submit');?>\n";
+?>
+</div>
+<div class="actions">
+ <ul>
+<?php if ($action != 'add'):?>
+ <li><?php echo "<?php echo \$html->link(__('Delete', true), array('action'=>'delete', \$form->value('{$modelClass}.{$primaryKey}')), null, sprintf(__('Are you sure you want to delete # %s?', true), \$form->value('{$modelClass}.{$primaryKey}'))); ?>";?></li>
+<?php endif;?>
+ <li><?php echo "<?php echo \$html->link(__('List {$pluralHumanName}', true), array('action'=>'index'));?>";?></li>
+<?php
+ $done = array();
+ foreach ($associations as $type => $data) {
+ foreach ($data as $alias => $details) {
+ if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
+ echo "\t\t<li><?php echo \$html->link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller'=> '{$details['controller']}', 'action'=>'index')); ?> </li>\n";
+ echo "\t\t<li><?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller'=> '{$details['controller']}', 'action'=>'add')); ?> </li>\n";
+ $done[] = $details['controller'];
+ }
+ }
+ }
+?>
+ </ul>
+</div>
View
82 cake/console/libs/templates/default/views/home.ctp
@@ -0,0 +1,82 @@
+<?php
+$output = "<h2>Sweet, \"".Inflector::humanize($app)."\" got Baked by CakePHP!</h2>\n";
+$output .="
+<?php
+if (Configure::read() > 0):
+ Debugger::checkSessionKey();
+endif;
+?>
+<p>
+<?php
+ if (is_writable(TMP)):
+ echo '<span class=\"notice success\">';
+ __('Your tmp directory is writable.');
+ echo '</span>';
+ else:
+ echo '<span class=\"notice\">';
+ __('Your tmp directory is NOT writable.');
+ echo '</span>';
+ endif;
+?>
+</p>
+<p>
+<?php
+ \$settings = Cache::settings();
+ if (!empty(\$settings)):
+ echo '<span class=\"notice success\">';
+ echo sprintf(__('The %s is being used for caching. To change the config edit APP/config/core.php ', true), '<em>'. \$settings['engine'] . 'Engine</em>');
+ echo '</span>';
+ else:
+ echo '<span class=\"notice\">';
+ __('Your cache is NOT working. Please check the settings in APP/config/core.php');
+ echo '</span>';
+ endif;
+?>
+</p>
+<p>
+<?php
+ \$filePresent = null;
+ if (file_exists(CONFIGS . 'database.php')):
+ echo '<span class=\"notice success\">';
+ __('Your database configuration file is present.');
+ \$filePresent = true;
+ echo '</span>';
+ else:
+ echo '<span class=\"notice\">';
+ __('Your database configuration file is NOT present.');
+ echo '<br/>';
+ __('Rename config/database.php.default to config/database.php');
+ echo '</span>';
+ endif;
+?>
+</p>
+<?php
+if (!empty(\$filePresent)):
+ uses('model' . DS . 'connection_manager');
+ \$db = ConnectionManager::getInstance();
+ \$connected = \$db->getDataSource('default');
+?>
+<p>
+<?php
+ if (\$connected->isConnected()):
+ echo '<span class=\"notice success\">';
+ __('Cake is able to connect to the database.');
+ echo '</span>';
+ else:
+ echo '<span class=\"notice\">';
+ __('Cake is NOT able to connect to the database.');
+ echo '</span>';
+ endif;
+?>
+</p>\n";
+$output .= "<?php endif;?>\n";
+$output .= "<h3><?php __('Editing this Page') ?></h3>\n";
+$output .= "<p>\n";
+$output .= "<?php\n";
+$output .= "\techo sprintf(__('To change the content of this page, edit: %s\n";
+$output .= "\t\tTo change its layout, edit: %s\n";
+$output .= "\t\tYou can also add some CSS styles for your pages at: %s', true),\n";
+$output .= "\t\tAPP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />', APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');\n";
+$output .= "?>\n";
+$output .= "</p>\n";
+?>
View
99 cake/console/libs/templates/default/views/index.ctp
@@ -0,0 +1,99 @@
+<?php
+/* SVN FILE: $Id$ */
+/**
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake
+ * @subpackage cake.cake.console.libs.templates.views
+ * @since CakePHP(tm) v 1.2.0.5234
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+?>
+<div class="<?php echo $pluralVar;?> index">
+<h2><?php echo "<?php __('{$pluralHumanName}');?>";?></h2>
+<p>
+<?php echo "<?php
+echo \$paginator->counter(array(
+'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
+));
+?>";?>
+</p>
+<table cellpadding="0" cellspacing="0">
+<tr>
+<?php foreach ($fields as $field):?>
+ <th><?php echo "<?php echo \$paginator->sort('{$field}');?>";?></th>
+<?php endforeach;?>
+ <th class="actions"><?php echo "<?php __('Actions');?>";?></th>
+</tr>
+<?php
+echo "<?php
+\$i = 0;
+foreach (\${$pluralVar} as \${$singularVar}):
+ \$class = null;
+ if (\$i++ % 2 == 0) {
+ \$class = ' class=\"altrow\"';
+ }
+?>\n";
+ echo "\t<tr<?php echo \$class;?>>\n";
+ foreach ($fields as $field) {
+ $isKey = false;
+ if (!empty($associations['belongsTo'])) {
+ foreach ($associations['belongsTo'] as $alias => $details) {
+ if ($field === $details['foreignKey']) {
+ $isKey = true;
+ echo "\t\t<td>\n\t\t\t<?php echo \$html->link(\${$singularVar}['{$alias}']['{$details['displayField']}'], array('controller'=> '{$details['controller']}', 'action'=>'view', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?>\n\t\t</td>\n";
+ break;
+ }
+ }
+ }
+ if ($isKey !== true) {
+ echo "\t\t<td>\n\t\t\t<?php echo \${$singularVar}['{$modelClass}']['{$field}']; ?>\n\t\t</td>\n";
+ }
+ }
+
+ echo "\t\t<td class=\"actions\">\n";
+ echo "\t\t\t<?php echo \$html->link(__('View', true), array('action'=>'view', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
+ echo "\t\t\t<?php echo \$html->link(__('Edit', true), array('action'=>'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
+ echo "\t\t\t<?php echo \$html->link(__('Delete', true), array('action'=>'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
+ echo "\t\t</td>\n";
+ echo "\t</tr>\n";
+
+echo "<?php endforeach; ?>\n";
+?>
+</table>
+</div>
+<div class="paging">
+<?php echo "\t<?php echo \$paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>\n";?>
+ | <?php echo "\t<?php echo \$paginator->numbers();?>\n"?>
+<?php echo "\t<?php echo \$paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>\n";?>
+</div>
+<div class="actions">
+ <ul>
+ <li><?php echo "<?php echo \$html->link(__('New {$singularHumanName}', true), array('action'=>'add')); ?>";?></li>
+<?php
+ $done = array();
+ foreach ($associations as $type => $data) {
+ foreach ($data as $alias => $details) {
+ if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
+ echo "\t\t<li><?php echo \$html->link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller'=> '{$details['controller']}', 'action'=>'index')); ?> </li>\n";
+ echo "\t\t<li><?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller'=> '{$details['controller']}', 'action'=>'add')); ?> </li>\n";
+ $done[] = $details['controller'];
+ }
+ }
+ }
+?>
+ </ul>
+</div>
View
150 cake/console/libs/templates/default/views/view.ctp
@@ -0,0 +1,150 @@
+<?php
+/* SVN FILE: $Id$ */
+/**
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake
+ * @subpackage cake.cake.console.libs.templates.views
+ * @since CakePHP(tm) v 1.2.0.5234
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+?>
+<div class="<?php echo $pluralVar;?> view">
+<h2><?php echo "<?php __('{$singularHumanName}');?>";?></h2>
+ <dl><?php echo "<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?>
+<?php
+foreach ($fields as $field) {
+ $isKey = false;
+ if (!empty($associations['belongsTo'])) {
+ foreach ($associations['belongsTo'] as $alias => $details) {
+ if ($field === $details['foreignKey']) {
+ $isKey = true;
+ echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('".Inflector::humanize(Inflector::underscore($alias))."'); ?></dt>\n";
+ echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t\t\t<?php echo \$html->link(\${$singularVar}['{$alias}']['{$details['displayField']}'], array('controller'=> '{$details['controller']}', 'action'=>'view', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?>\n\t\t\t&nbsp;\n\t\t</dd>\n";
+ break;
+ }
+ }
+ }
+ if ($isKey !== true) {
+ echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('".Inflector::humanize($field)."'); ?></dt>\n";
+ echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t\t\t<?php echo \${$singularVar}['{$modelClass}']['{$field}']; ?>\n\t\t\t&nbsp;\n\t\t</dd>\n";
+ }
+}
+?>
+ </dl>
+</div>
+<div class="actions">
+ <ul>
+<?php
+ echo "\t\t<li><?php echo \$html->link(__('Edit {$singularHumanName}', true), array('action'=>'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
+ echo "\t\t<li><?php echo \$html->link(__('Delete {$singularHumanName}', true), array('action'=>'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
+ echo "\t\t<li><?php echo \$html->link(__('List {$pluralHumanName}', true), array('action'=>'index')); ?> </li>\n";
+ echo "\t\t<li><?php echo \$html->link(__('New {$singularHumanName}', true), array('action'=>'add')); ?> </li>\n";
+
+ $done = array();
+ foreach ($associations as $type => $data) {
+ foreach ($data as $alias => $details) {
+ if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
+ echo "\t\t<li><?php echo \$html->link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller'=> '{$details['controller']}', 'action'=>'index')); ?> </li>\n";
+ echo "\t\t<li><?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller'=> '{$details['controller']}', 'action'=>'add')); ?> </li>\n";
+ $done[] = $details['controller'];
+ }
+ }
+ }
+?>
+ </ul>
+</div>
+<?php
+if (!empty($associations['hasOne'])) :
+ foreach ($associations['hasOne'] as $alias => $details): ?>
+ <div class="related">
+ <h3><?php echo "<?php __('Related ".Inflector::humanize($details['controller'])."');?>";?></h3>
+ <?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
+ <dl><?php echo "\t<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?>
+ <?php
+ foreach ($details['fields'] as $field) {
+ echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('".Inflector::humanize($field)."');?></dt>\n";
+ echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t<?php echo \${$singularVar}['{$alias}']['{$field}'];?>\n&nbsp;</dd>\n";
+ }
+ ?>
+ </dl>
+ <?php echo "<?php endif; ?>\n";?>
+ <div class="actions">
+ <ul>
+ <li><?php echo "<?php echo \$html->link(__('Edit ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller'=> '{$details['controller']}', 'action'=>'edit', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?></li>\n";?>
+ </ul>
+ </div>
+ </div>
+ <?php
+ endforeach;
+endif;
+if (empty($associations['hasMany'])) {
+ $associations['hasMany'] = array();
+}
+if (empty($associations['hasAndBelongsToMany'])) {
+ $associations['hasAndBelongsToMany'] = array();
+}
+$relations = array_merge($associations['hasMany'], $associations['hasAndBelongsToMany']);
+$i = 0;
+foreach ($relations as $alias => $details):
+ $otherSingularVar = Inflector::variable($alias);
+ $otherPluralHumanName = Inflector::humanize($details['controller']);
+ ?>
+<div class="related">
+ <h3><?php echo "<?php __('Related {$otherPluralHumanName}');?>";?></h3>
+ <?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
+ <table cellpadding = "0" cellspacing = "0">
+ <tr>
+<?php
+ foreach ($details['fields'] as $field) {
+ echo "\t\t<th><?php __('".Inflector::humanize($field)."'); ?></th>\n";
+ }
+?>
+ <th class="actions"><?php echo "<?php __('Actions');?>";?></th>
+ </tr>
+<?php
+echo "\t<?php
+ \$i = 0;
+ foreach (\${$singularVar}['{$alias}'] as \${$otherSingularVar}):
+ \$class = null;
+ if (\$i++ % 2 == 0) {
+ \$class = ' class=\"altrow\"';
+ }
+ ?>\n";
+ echo "\t\t<tr<?php echo \$class;?>>\n";
+
+ foreach ($details['fields'] as $field) {
+ echo "\t\t\t<td><?php echo \${$otherSingularVar}['{$field}'];?></td>\n";
+ }
+
+ echo "\t\t\t<td class=\"actions\">\n";
+ echo "\t\t\t\t<?php echo \$html->link(__('View', true), array('controller'=> '{$details['controller']}', 'action'=>'view', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
+ echo "\t\t\t\t<?php echo \$html->link(__('Edit', true), array('controller'=> '{$details['controller']}', 'action'=>'edit', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
+ echo "\t\t\t\t<?php echo \$html->link(__('Delete', true), array('controller'=> '{$details['controller']}', 'action'=>'delete', \${$otherSingularVar}['{$details['primaryKey']}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
+ echo "\t\t\t</td>\n";
+ echo "\t\t</tr>\n";
+
+echo "\t<?php endforeach; ?>\n";
+?>
+ </table>
+<?php echo "<?php endif; ?>\n\n";?>
+ <div class="actions">
+ <ul>
+ <li><?php echo "<?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller'=> '{$details['controller']}', 'action'=>'add'));?>";?> </li>
+ </ul>
+ </div>
+</div>
+<?php endforeach;?>
View
66 cake/tests/cases/console/libs/tasks/template.test.php
@@ -33,9 +33,7 @@
ob_end_clean();
}
-if (!class_exists('TemplateTask')) {
- require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
-}
+require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
Mock::generatePartial(
'ShellDispatcher', 'TestTemplateTaskMockShellDispatcher',
@@ -96,13 +94,40 @@ function testSet() {
}
/**
- * test Initialize
+ * test finding themes installed in
*
* @return void
**/
- function testInitialize() {
+ function testFindingInstalledThemesForBake() {
+ $consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS;
+ $this->Task->Dispatch->shellPaths = array($consoleLibs);
$this->Task->initialize();
- $this->assertEqual($this->Task->templatePaths, $this->Task->Dispatch->shellPaths);
+ $this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS));
+ }
+
+/**
+ * test getting the correct theme name. Ensure that with only one theme, or a theme param
+ * that the user is not bugged. If there are more, find and return the correct theme name
+ *
+ * @return void
+ **/
+ function testGetThemePath() {
+ $defaultTheme = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'default' .DS;
+ $this->Task->templatePaths = array('default' => $defaultTheme);
+ $this->Task->expectCallCount('in', 1);
+
+ $result = $this->Task->getThemePath();
+ $this->assertEqual($result, $defaultTheme);
+
+ $this->Task->templatePaths = array('default' => $defaultTheme, 'other' => '/some/path');
+ $this->Task->params['theme'] = 'other';
+ $result = $this->Task->getThemePath();
+ $this->assertEqual($result, '/some/path');
+
+ $this->Task->params = array();
+ $this->Task->setReturnValueAt(0, 'in', '1');
+ $result = $this->Task->getThemePath();
+ $this->assertEqual($result, $defaultTheme);
}
/**
@@ -111,12 +136,37 @@ function testInitialize() {
* @return void
**/
function testGenerate() {
- $this->Task->templatePaths = array(
+ $this->Task->Dispatch->shellPaths = array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
);
- $result = $this->Task->generate('objects', 'test_object', array('test' => 'foo'));
+ $this->Task->initialize();
+ $result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
$expected = "I got rendered\nfoo";
$this->assertEqual($result, $expected);
}
+
+/**
+ * test generate with a missing template in the chosen theme.
+ * ensure fallback to default works.
+ *
+ * @return void
+ **/
+ function testGenerateWithTemplateFallbacks() {
+ $this->Task->Dispatch->shellPaths = array(
+ TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS,
+ CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS
+ );
+ $this->Task->initialize();
+ $this->Task->params['theme'] = 'test';
+ $this->Task->set(array(
+ 'model' => 'Article',
+ 'table' => 'articles',
+ 'import' => false,
+ 'records' => false,
+ 'schema' => ''
+ ));
+ $result = $this->Task->generate('classes', 'fixture');
+ $this->assertPattern('/ArticleFixture extends CakeTestFixture/', $result);
+ }
}
?>
View
0  cake/tests/test_app/vendors/shells/templates/empty
No changes.
View
2  cake/tests/test_app/vendors/shells/templates/test/classes/test_object.ctp
@@ -0,0 +1,2 @@
+I got rendered
+<?php echo $test; ?>
Please sign in to comment.
Something went wrong with that request. Please try again.