Refactored the developer module. When a new module is generated a

skeleton adminstration page is generated as well.
@todo is still generate a skeleton block and a skeleton dialog.
This commit is contained in:
Tim Almdal
2009-03-15 05:15:45 +00:00
parent 181737fb12
commit 7c5ba9d422
12 changed files with 496 additions and 75 deletions

View File

@@ -25,68 +25,97 @@ class developer_task_Core {
static function create_module($task) {
$context = unserialize($task->context);
$module_path = (MODPATH . "{$context['path_part']}");
if (empty($context["module"])) {
$context["class_name"] = strtr($context["name"], " ", "_");
$context["module"] = strtolower($context["class_name"]);
$context["module_path"] = (MODPATH . $context["module"]);
}
switch ($context["step"]) {
case 0: // Create directory tree
Kohana::log("debug", Kohana::debug($context));
foreach (array("", "controllers", "helpers", "js", "views") as $dir) {
$path = "$module_path/$dir";
$path = "{$context['module_path']}/$dir";
if (!file_exists($path)) {
mkdir($path, 0774);
}
mkdir($path);
chmod($path, 0774);
}
}
break;
case 1: // Generate installer
ob_start();
$v = new View("installer.txt");
$v->module_name = $context['name'];
$v->callbacks = $context["theme"];
print $v->render();
file_put_contents("$module_path/helpers/{$context['name']}_installer.php", ob_get_contents());
ob_end_clean();
$context["installer"] = 1;
self::_render_helper_file($context, "installer");
break;
case 2: // Generate theme helper
self::_render_helper_file($context, "theme");
break;
case 3: // Generate block helper
$context["block"] = 1;
self::_render_helper_file($context, "block");
break;
case 4: // Generate menu helper
$context["menu"] = empty($context["menu"]) ? 1 : $context["menu"];
self::_render_helper_file($context, "menu");
break;
case 5: // Generate event helper
self::_render_helper_file($context, "event");
break;
case 6: // Generate module.info (do last)
case 6: // Generate admin controller
$file = "{$context['module_path']}/controllers/admin_{$context['module']}.php";
ob_start();
$v = new View("admin_controller.txt");
$v->name = $context["name"];
$v->module = $context["module"];
$v->class_name = $context["class_name"];
print $v->render();
file_put_contents($file, ob_get_contents());
ob_end_clean();
break;
case 7: // Generate admin form
$file = "{$context['module_path']}/views/admin_{$context['module']}.html.php";
Kohana::log("debug", $file);
ob_start();
$v = new View("admin_html.txt");
$v->name = $context["name"];
$v->module = $context["module"];
$v->class = strtr($context["name"], " ", "");
Kohana::log("debug", Kohana::debug($v->render()));
print $v->render();
file_put_contents($file, ob_get_contents());
ob_end_clean();
break;
case 8: // Generate module.info (do last)
$file = "{$context["module_path"]}/module.info";
ob_start();
$v = new View("module_info.txt");
$v->module_name = $context['name'];
$v->module_name = $context["name"];
$v->module_description = $context["description"];
print $v->render();
file_put_contents("$module_path/module.info", ob_get_contents());
file_put_contents($file, ob_get_contents());
ob_end_clean();
break;
}
$task->done = (++$context["step"]) >= 7;
$task->done = (++$context["step"]) >= 9;
$task->context = serialize($context);
$task->state = "success";
$task->percent_complete = ($context["step"] / 7.0) * 100;
$task->percent_complete = ($context["step"] / 9.0) * 100;
}
private static function _render_helper_file($context, $helper) {
if (!empty($context[$helper])) {
$config = Kohana::config("developer.methods");
$file = "{$context["module_path"]}/helpers/{$context["module"]}_{$helper}.php";
touch($file);
chmod($file, 0772);
ob_start();
$v = new View("helpers.txt");
$v = new View("$helper.txt");
$v->helper = $helper;
$v->module_name = $context['name'];
$v->callbacks = array();
foreach ($context[$helper] as $callback) {
$v->callbacks[$callback] = $config[$helper][$callback];
}
$v->module = $context["module"];
$v->module_name = $context["name"];
$v->callbacks = empty($context[$helper]) ? array() : array_fill_keys($context[$helper], 1);
print $v->render();
file_put_contents(MODPATH . "{$context['name']}/helpers/{$context['name']}_{$helper}.php",
ob_get_contents());
file_put_contents($file, ob_get_contents());
ob_end_clean();
}
}