Revision | 880 (tree) |
---|---|
Zeit | 2009-06-20 23:22:45 |
Autor | ![]() |
- added type check.
- changed behavior to require to in Ethna project.
- added -p|--plugin-package option.
@@ -25,37 +25,46 @@ | ||
25 | 25 | * @access public |
26 | 26 | * @param string $basedir ベースディレクトリ |
27 | 27 | * @param array $types プラグインのtype (Validator, Handle等) |
28 | - * @param string $no_ini iniファイル生成フラグ | |
28 | + * @param string $forpackage iniファイル生成フラグ | |
29 | 29 | * @param string $plugin_name プラグイン名 |
30 | 30 | * @return true|Ethna_Error true:成功 Ethna_Error:失敗 |
31 | 31 | */ |
32 | - function &generate($basedir, $types = array(), $no_ini = false, $plugin_name) | |
32 | + function &generate($basedir, $types = array(), $forpackage = false, $plugin_name) | |
33 | 33 | { |
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 | + | |
34 | 45 | // create plugin directory |
35 | - $plugin_dir = "$basedir/plugin"; | |
36 | 46 | if (!file_exists($plugin_dir)) { |
37 | 47 | Ethna_Util::mkdir($plugin_dir, 0755); |
38 | - } else { | |
39 | - printf("directory [$plugin_dir] already exists -> skip.\n"); | |
40 | 48 | } |
49 | + | |
41 | 50 | // type check. |
42 | 51 | if (empty($types)) { |
43 | 52 | return Ethna::raiseError('please specify plugin type.'); |
44 | 53 | } |
45 | 54 | |
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'); | |
59 | 68 | } |
60 | 69 | } |
61 | 70 |
@@ -64,6 +73,7 @@ | ||
64 | 73 | // |
65 | 74 | $plugin_name = ucfirst(strtolower($plugin_name)); |
66 | 75 | $lplugin_name = strtolower($plugin_name); |
76 | + $macro['plugin_name'] = $plugin_name; | |
67 | 77 | foreach ($types as $type) { |
68 | 78 | $ltype = strtolower($type); |
69 | 79 | $macro['plugin_type'] = $type; |
@@ -82,14 +92,17 @@ | ||
82 | 92 | case 'sm': |
83 | 93 | $type = 'Smarty'; |
84 | 94 | $pfilename = "modifier.${lplugin_name}.php"; |
95 | + $macro['plugin_name'] = $lplugin_name; | |
85 | 96 | break; |
86 | 97 | case 'sb': |
87 | 98 | $type = 'Smarty'; |
88 | 99 | $pfilename = "block.${lplugin_name}.php"; |
100 | + $macro['plugin_name'] = $lplugin_name; | |
89 | 101 | break; |
90 | 102 | case 'sf': |
91 | 103 | $type = 'Smarty'; |
92 | 104 | $pfilename = "function.${lplugin_name}.php"; |
105 | + $macro['plugin_name'] = $lplugin_name; | |
93 | 106 | break; |
94 | 107 | } |
95 | 108 | $type_dir = "$plugin_dir/$type"; |
@@ -109,6 +122,21 @@ | ||
109 | 122 | } |
110 | 123 | } |
111 | 124 | |
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 | + | |
112 | 140 | $true = true; |
113 | 141 | return $true; |
114 | 142 | } |
@@ -32,7 +32,8 @@ | ||
32 | 32 | array( |
33 | 33 | 'basedir=', |
34 | 34 | 'type=', |
35 | - 'noini', | |
35 | + 'no-inifile', | |
36 | + 'plugin-package', | |
36 | 37 | ) |
37 | 38 | ); |
38 | 39 | if (Ethna::isError($r)) { |
@@ -61,14 +62,14 @@ | ||
61 | 62 | } |
62 | 63 | |
63 | 64 | // no-ini file flag. |
64 | - $no_ini = (isset($opt_list['noini'])) ? true : false; | |
65 | + $forpackage = (isset($opt_list['plugin-package'])) ? true : false; | |
65 | 66 | |
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); | |
67 | 68 | if (Ethna::isError($r)) { |
68 | 69 | printf("error occurred while generating plugin skelton. please see also error messages given above\n\n"); |
69 | 70 | return $r; |
70 | 71 | } |
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); | |
72 | 73 | return true; |
73 | 74 | } |
74 | 75 | // }}} |
@@ -80,13 +81,14 @@ | ||
80 | 81 | function getUsage() |
81 | 82 | { |
82 | 83 | 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): | |
85 | 86 | f = Filter (default), |
86 | 87 | v = Validator (default), |
87 | 88 | sm = Smarty modifier (default) |
88 | 89 | sb = Smarty block, |
89 | 90 | sf = Smarty function, |
91 | + -p: if you want to make plugin package, set this option. | |
90 | 92 | EOS; |
91 | 93 | } |
92 | 94 | // }}} |
@@ -99,7 +101,7 @@ | ||
99 | 101 | { |
100 | 102 | return <<<EOS |
101 | 103 | 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 | |
103 | 105 | EOS; |
104 | 106 | } |
105 | 107 | // }}} |