2 // vim: foldmethod=marker
4 * Ethna_Plugin_Generator_Template.php
6 * @author Masaki Fujimoto <fujimoto@php.net>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 // {{{ Ethna_Plugin_Generator_Template
16 * @author Masaki Fujimoto <fujimoto@php.net>
20 class Ethna_Plugin_Generator_Template extends Ethna_Plugin_Generator
26 * @param string $forward_name テンプレート名
27 * @param string $skelton スケルトンファイル名
28 * @param string $locale ロケール名
29 * @param string $encoding エンコーディング
30 * @return true|Ethna_Error true:成功 Ethna_Error:失敗
32 function &generate($forward_name, $skelton = null, $locale, $encoding)
34 // ロケールが指定された場合は、それを優先する
35 if (!empty($locale)) {
36 $this->ctl->setLocale($locale);
39 // ロケール名がディレクトリに含まれていない場合は、
40 // ディレクトリがないためなのでそれを補正
41 $tpl_dir = $this->ctl->getTemplatedir();
42 $tpl_path = $this->ctl->getDefaultForwardPath($forward_name);
45 $entity = $tpl_dir . '/' . $tpl_path;
46 Ethna_Util::mkdir(dirname($entity), 0755);
49 if ($skelton === null) {
50 $skelton = 'skel.template.tpl';
55 // add '_' for tpl and no user macro for tpl
56 $macro['_project_id'] = $this->ctl->getAppId();
57 $macro['client_enc'] = $encoding;
60 if (file_exists($entity)) {
61 printf("file [%s] already exists -> skip\n", $entity);
62 } else if ($this->_generateFile($skelton, $entity, $macro) == false) {
63 printf("[warning] file creation failed [%s]\n", $entity);
65 printf("template file(s) successfully created [%s]\n", $entity);