function testToEnglish() { $this->assertEquals('To English', Inflector::toEnglish('toEnglish')); $this->assertEquals('To English', Inflector::toEnglish('ToEnglish')); $this->assertEquals('To English', Inflector::toEnglish('to_english')); $this->assertEquals('To English', Inflector::toEnglish('_____to______english____')); }
public function __construct($part, $name, $value = '', $label = false) { $part = 'controls/' . $part; if ($label === false) { $label = Inflector::toEnglish($name); } if ($value === true) { $value = '__true__'; } else { if ($value === false) { $value = '__false__'; } } parent::__construct($part, $this, $name, $value, $label); }
<?php Layout::extend('layouts/master'); $title = 'Home'; ?> <ul> <?php // This is a really slow way to generate navigation. // You probably should not use this in a real app. Thx -Kris Library::import('recess.lang.Inflector'); $app = $controller->application(); $controllers = $app->listControllers(); foreach ($controllers as $controllerClass) { $title = Inflector::toEnglish(str_replace('Controller', '', $controllerClass)); ?> <li><?php echo Html::anchor(Url::action($controllerClass . '::index'), $title); ?> </li> <?php } ?> </ul>
/** !Route GET, $app/model/$model/scaffolding */ public function generateScaffolding($app, $model) { $app = new $app(); if (strpos($app->controllersPrefix, 'recess.apps.') !== false) { $base = $_ENV['dir.recess']; } else { $base = $_ENV['dir.apps']; } Library::import('recess.lang.Inflector'); $controllersDir = $base . str_replace(Library::dotSeparator, Library::pathSeparator, $app->controllersPrefix); $viewsDir = $app->viewsDir; Library::import($app->modelsPrefix . $model); $replacements = array('modelName' => $model, 'modelNameLower' => Inflector::toCamelCaps($model), 'fullyQualifiedModel' => $app->modelsPrefix . $model, 'primaryKey' => Model::primaryKeyName($model), 'viewsPrefix' => Inflector::toCamelCaps($model), 'routesPrefix' => Inflector::toCamelCaps($model)); $this->messages[] = $this->tryGeneratingFile('RESTful ' . $model . ' Controller', $this->application->codeTemplatesDir . 'scaffolding/controllers/ResourceController.template.php', $controllersDir . $model . 'Controller.class.php', $replacements); $indexFieldTemplate = $this->getTemplate($this->application->codeTemplatesDir . 'scaffolding/views/resource/indexField.template.php'); $indexDateFieldTemplate = $this->getTemplate($this->application->codeTemplatesDir . 'scaffolding/views/resource/indexDateField.template.php'); $editFormInputTemplate = $this->getTemplate($this->application->codeTemplatesDir . 'scaffolding/views/resource/editFormInput.template.php'); $indexFields = ''; $formFields = ''; foreach (Model::getProperties($model) as $property) { if ($property->isPrimaryKey) { continue; } $values = array('fieldName' => $property->name, 'primaryKey' => Model::primaryKeyName($model), 'modelName' => $model, 'modelNameLower' => Inflector::toCamelCaps($model), 'fieldNameEnglish' => Inflector::toEnglish($property->name)); switch ($property->type) { case RecessType::DATE: case RecessType::DATETIME: case RecessType::TIME: case RecessType::TIMESTAMP: $template = $indexDateFieldTemplate; break; default: $template = $indexFieldTemplate; break; } $formFields .= $this->fillTemplate($editFormInputTemplate, $values); $indexFields .= $this->fillTemplate($template, $values); } $replacements['fields'] = $indexFields; $replacements['editFields'] = $formFields; $viewsDir = $app->viewsDir . $replacements['viewsPrefix'] . '/'; $this->messages[] = $this->tryCreatingDirectory($viewsDir, $model . ' views dir'); $this->messages[] = $this->tryGeneratingFile('resource layout', $this->application->codeTemplatesDir . 'scaffolding/views/resource/resource.layout.template.php', $viewsDir . '../layouts/' . $replacements['viewsPrefix'] . '.layout.php', $replacements); $this->messages[] = $this->tryGeneratingFile('index view', $this->application->codeTemplatesDir . 'scaffolding/views/resource/index.template.php', $viewsDir . 'index.html.php', $replacements); $this->messages[] = $this->tryGeneratingFile('editForm view', $this->application->codeTemplatesDir . 'scaffolding/views/resource/editForm.template.php', $viewsDir . 'editForm.html.php', $replacements, true); $this->messages[] = $this->tryGeneratingFile('form part', $this->application->codeTemplatesDir . 'scaffolding/views/resource/form.part.template.php', $viewsDir . 'form.part.php', $replacements, true); $this->messages[] = $this->tryGeneratingFile('static details', $this->application->codeTemplatesDir . 'scaffolding/views/resource/details.template.php', $viewsDir . 'details.html.php', $replacements); $this->messages[] = $this->tryGeneratingFile('details part', $this->application->codeTemplatesDir . 'scaffolding/views/resource/details.part.template.php', $viewsDir . 'details.part.php', $replacements); $this->appName = get_class($app); $this->modelName = $model; }