• R/O
  • SSH
  • HTTPS

ethna: Commit


Commit MetaInfo

Revision880 (tree)
Zeit2009-06-20 23:22:45
Autormumumu-org

Log Message

- added type check.
- changed behavior to require to in Ethna project.
- added -p|--plugin-package option.

Ändern Zusammenfassung

Diff

--- ethna/trunk/class/Plugin/Generator/CreatePlugin.php (revision 879)
+++ ethna/trunk/class/Plugin/Generator/CreatePlugin.php (revision 880)
@@ -25,37 +25,46 @@
2525 * @access public
2626 * @param string $basedir ベースディレクトリ
2727 * @param array $types プラグインのtype (Validator, Handle等)
28- * @param string $no_ini iniファイル生成フラグ
28+ * @param string $forpackage iniファイル生成フラグ
2929 * @param string $plugin_name プラグイン名
3030 * @return true|Ethna_Error true:成功 Ethna_Error:失敗
3131 */
32- function &generate($basedir, $types = array(), $no_ini = false, $plugin_name)
32+ function &generate($basedir, $types = array(), $forpackage = false, $plugin_name)
3333 {
34+ $plugin_dir = "$basedir/plugin";
35+ if (!$forpackage) {
36+ $chk_ctl = Ethna_Handle::getAppController(getcwd());
37+ if (Ethna::isError($chk_ctl)) {
38+ return Ethna::raiseError(
39+ "ERROR: You are not in Ethna project. specify [-p|--plugin-package] option, or change directory to the Ethna Project\n"
40+ );
41+ }
42+ $plugin_dir = $chk_ctl->getDirectory('plugin');
43+ }
44+
3445 // create plugin directory
35- $plugin_dir = "$basedir/plugin";
3646 if (!file_exists($plugin_dir)) {
3747 Ethna_Util::mkdir($plugin_dir, 0755);
38- } else {
39- printf("directory [$plugin_dir] already exists -> skip.\n");
4048 }
49+
4150 // type check.
4251 if (empty($types)) {
4352 return Ethna::raiseError('please specify plugin type.');
4453 }
4554
46- // generate ini file
47- if ($no_ini == false) {
48- $ini_skel = 'plugin/skel.plugin.ini';
49- $ini_file = strtolower($plugin_name) . '.ini';
50- $ini_path = "$plugin_dir/$ini_file";
51-
52- $macro['plugin_name'] = $plugin_name;
53- if (file_exists($ini_path)) {
54- printf("file [%s] already exists -> skip\n", $ini_file);
55- } else if ($this->_generateFile($ini_skel, $ini_path, $macro) == false) {
56- printf("[warning] file creation failed [%s]\n", $ini_file);
57- } else {
58- printf("plugin ini file successfully created [%s]\n", $ini_file);
55+ //
56+ // type check
57+ //
58+ foreach ($types as $type) {
59+ switch (strtolower($type)) {
60+ case 'f':
61+ case 'v':
62+ case 'sm':
63+ case 'sb':
64+ case 'sf':
65+ break;
66+ default:
67+ return Ethna::raiseError("unknown plugin type: ${type}", 'usage');
5968 }
6069 }
6170
@@ -64,6 +73,7 @@
6473 //
6574 $plugin_name = ucfirst(strtolower($plugin_name));
6675 $lplugin_name = strtolower($plugin_name);
76+ $macro['plugin_name'] = $plugin_name;
6777 foreach ($types as $type) {
6878 $ltype = strtolower($type);
6979 $macro['plugin_type'] = $type;
@@ -82,14 +92,17 @@
8292 case 'sm':
8393 $type = 'Smarty';
8494 $pfilename = "modifier.${lplugin_name}.php";
95+ $macro['plugin_name'] = $lplugin_name;
8596 break;
8697 case 'sb':
8798 $type = 'Smarty';
8899 $pfilename = "block.${lplugin_name}.php";
100+ $macro['plugin_name'] = $lplugin_name;
89101 break;
90102 case 'sf':
91103 $type = 'Smarty';
92104 $pfilename = "function.${lplugin_name}.php";
105+ $macro['plugin_name'] = $lplugin_name;
93106 break;
94107 }
95108 $type_dir = "$plugin_dir/$type";
@@ -109,6 +122,21 @@
109122 }
110123 }
111124
125+ // generate ini file
126+ if ($forpackage) {
127+ $ini_skel = 'plugin/skel.plugin.ini';
128+ $ini_file = strtolower($plugin_name) . '.ini';
129+ $ini_path = "$plugin_dir/$ini_file";
130+
131+ if (file_exists($ini_path)) {
132+ printf("file [%s] already exists -> skip\n", $ini_file);
133+ } else if ($this->_generateFile($ini_skel, $ini_path, $macro) == false) {
134+ printf("[warning] file creation failed [%s]\n", $ini_file);
135+ } else {
136+ printf("plugin ini file successfully created [%s]\n", $ini_file);
137+ }
138+ }
139+
112140 $true = true;
113141 return $true;
114142 }
--- ethna/trunk/class/Plugin/Handle/CreatePlugin.php (revision 879)
+++ ethna/trunk/class/Plugin/Handle/CreatePlugin.php (revision 880)
@@ -32,7 +32,8 @@
3232 array(
3333 'basedir=',
3434 'type=',
35- 'noini',
35+ 'no-inifile',
36+ 'plugin-package',
3637 )
3738 );
3839 if (Ethna::isError($r)) {
@@ -61,14 +62,14 @@
6162 }
6263
6364 // no-ini file flag.
64- $no_ini = (isset($opt_list['noini'])) ? true : false;
65+ $forpackage = (isset($opt_list['plugin-package'])) ? true : false;
6566
66- $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $no_ini, $plugin_name);
67+ $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $forpackage, $plugin_name);
6768 if (Ethna::isError($r)) {
6869 printf("error occurred while generating plugin skelton. please see also error messages given above\n\n");
6970 return $r;
7071 }
71- printf("\nplugin skelton for [%s] is successfully generated at [%s]\n\n", $plugin_name, "$basedir/$plugin_name");
72+ printf("\nplugin skelton for [%s] is successfully generated.\n\n", $plugin_name);
7273 return true;
7374 }
7475 // }}}
@@ -80,13 +81,14 @@
8081 function getUsage()
8182 {
8283 return <<<EOS
83-ethna {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-n|--no-inifile] plugin-name
84- type is as follows (separated by comma):
84+ethna {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-p|--plugin-package] plugin-name
85+ -t: type is as follows (separated by comma):
8586 f = Filter (default),
8687 v = Validator (default),
8788 sm = Smarty modifier (default)
8889 sb = Smarty block,
8990 sf = Smarty function,
91+ -p: if you want to make plugin package, set this option.
9092 EOS;
9193 }
9294 // }}}
@@ -99,7 +101,7 @@
99101 {
100102 return <<<EOS
101103 make plugin package:
102- {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-n|--no-inifile] plugin-name
104+ {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-p|--plugin-package] plugin-name
103105 EOS;
104106 }
105107 // }}}
Show on old repository browser