OSDN Git Service

- added [-e|encoding] option to "ethna add-project" command.
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Mon, 30 Jun 2008 14:12:24 +0000 (14:12 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Mon, 30 Jun 2008 14:12:24 +0000 (14:12 +0000)
CHANGES
class/Plugin/Generator/Ethna_Plugin_Generator_Project.php
class/Plugin/Handle/Ethna_Plugin_Handle_AddProject.php
skel/app.controller.php

diff --git a/CHANGES b/CHANGES
index 96b4262..e0427c2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -29,6 +29,7 @@
 --- 2.3.5 までのコードは、gettext.so がロードされていれば *無条件に* gettext が実行されるようになっているので、Ethna 独自のメッセージカタログとの選択がわかりづらいため。
 --- 2.3.5までのコードで gettext を利用している場合は、設定が明示的に必要です。
 -- "ethna add-project" コマンドに [-l|locale] オプションを追加
+-- "ethna add-project" コマンドに [-e|encoding] オプションを追加
 -- スケルトンの日本語コメントをすべてASCIIに変更(好みのエンコーディングで編集できるようにするため)
 -- gettextを使わない場合向けに、Ethna独自のメッセージカタログを実装
 --- ini ファイルライクなフォーマットで msgid と翻訳を格納する方式
index 875bfea..e9205e3 100644 (file)
@@ -30,9 +30,10 @@ class Ethna_Plugin_Generator_Project extends Ethna_Plugin_Generator
      *                              も追加してコピーする 
      *  @param  string  $locale     ロケール名
      *                              (ロケール名は、ll_cc の形式。ll = 言語コード cc = 国コード)
+     *  @param  string  $encoding   プロジェクトで使用するエンコーディング 
      *  @return bool    true:成功   Ethna_Error:失敗
      */
-    function generate($id, $basedir, $skeldir, $locale)
+    function generate($id, $basedir, $skeldir, $locale, $encoding)
     {
         $dir_list = array(
             array("app", 0755),
@@ -112,6 +113,7 @@ class Ethna_Plugin_Generator_Project extends Ethna_Plugin_Generator
         $macro['project_prefix'] = $id;
         $macro['basedir'] = realpath($basedir);
         $macro['locale'] = $locale;
+        $macro['client_enc'] = $encoding;
 
         $macro['action_class'] = '{$action_class}';
         $macro['action_form'] = '{$action_form}';
index 5b18afe..c895f0b 100644 (file)
@@ -26,7 +26,7 @@ class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
      */
     function perform()
     {
-        $r = $this->_getopt(array('basedir=', 'skeldir=', 'locale='));
+        $r = $this->_getopt(array('basedir=', 'skeldir=', 'locale=', 'encoding='));
         if (Ethna::isError($r)) {
             return $r;
         }
@@ -70,7 +70,20 @@ class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
             $locale = 'ja_JP';  //  default locale. 
         }
 
-        $r = Ethna_Generator::generate('Project', null, $app_id, $basedir, $skeldir, $locale);
+        // encoding
+        if (isset($opt_list['encoding'])) {
+            $encoding = end($opt_list['encoding']);
+            if (function_exists('mb_list_encodings')) {
+                $supported_enc = mb_list_encodings();
+                if (!in_array($encoding, $supported_enc)) {
+                    return Ethna::raiseError("Unknown Encoding : $encoding", 'usage');
+                }
+            }
+        } else {
+            $encoding = 'UTF-8';  //  default encoding. 
+        }
+
+        $r = Ethna_Generator::generate('Project', null, $app_id, $basedir, $skeldir, $locale, $encoding);
         if (Ethna::isError($r)) {
             printf("error occurred while generating skelton. please see also error messages given above\n\n");
             return $r;
@@ -89,7 +102,7 @@ class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
     {
         return <<<EOS
 add new project:
-    {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [Application id]
+    {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [-e|--encoding] [Application id]
 
 EOS;
     }
@@ -102,7 +115,7 @@ EOS;
     function getUsage()
     {
         return <<<EOS
-ethna {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [Application id]
+ethna {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [-e|--encoding] [Application id]
 EOS;
     }
 }
index 75429b6..287f1df 100644 (file)
@@ -270,7 +270,7 @@ class {$project_id}_Controller extends Ethna_Controller
      */
     function _getDefaultLanguage()
     {
-        return array('{$locale}', 'UTF-8', 'UTF-8');
+        return array('{$locale}', 'UTF-8', '{$client_enc}');
     }
 }