OSDN Git Service

0e80cf0659882d0da3913f18424303c38baacd95
[ethna/ethna.git] / Idea_Plugin_Extlib / class / Plugin / Generator / Ethna_Plugin_Generator_Template.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_Plugin_Generator_Template.php
5  *
6  *  @author     Masaki Fujimoto <fujimoto@php.net>
7  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
8  *  @package    Ethna
9  *  @version    $Id$
10  */
11
12 // {{{ Ethna_Plugin_Generator_Template
13 /**
14  *  スケルトン生成クラス
15  *
16  *  @author     Masaki Fujimoto <fujimoto@php.net>
17  *  @access     public
18  *  @package    Ethna
19  */
20 class Ethna_Plugin_Generator_Template extends Ethna_Plugin_Generator
21 {
22     /**
23      *  テンプレートのスケルトンを生成する
24      *
25      *  @access public
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:失敗
31      */
32     function &generate($forward_name, $skelton = null, $locale, $encoding)
33     {
34         //  ロケールが指定された場合は、それを優先する 
35         if (!empty($locale)) {
36             $this->ctl->setLocale($locale);
37         }
38
39         //  ロケール名がディレクトリに含まれていない場合は、
40         //  ディレクトリがないためなのでそれを補正 
41         $tpl_dir = $this->ctl->getTemplatedir();
42         $tpl_path = $this->ctl->getDefaultForwardPath($forward_name);
43
44         // entity
45         $entity = $tpl_dir . '/' . $tpl_path;
46         Ethna_Util::mkdir(dirname($entity), 0755);
47
48         // skelton
49         if ($skelton === null) {
50             $skelton = 'skel.template.tpl';
51         }
52
53         // macro
54         $macro = array();
55         // add '_' for tpl and no user macro for tpl
56         $macro['_project_id'] = $this->ctl->getAppId();
57         $macro['client_enc'] = $encoding;
58
59         // generate
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);
64         } else {
65             printf("template file(s) successfully created [%s]\n", $entity);
66         }
67
68         $true = true;
69         return $true;
70     }
71 }
72 // }}}
73 ?>