OSDN Git Service

- added ethna create-plugin command implementation.
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Fri, 19 Jun 2009 22:33:35 +0000 (22:33 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Fri, 19 Jun 2009 22:33:35 +0000 (22:33 +0000)
CHANGES
class/Plugin/Generator/CreatePlugin.php [new file with mode: 0644]
class/Plugin/Handle/CreatePlugin.php [new file with mode: 0644]
skel/plugin/skel.plugin.f.php [new file with mode: 0644]
skel/plugin/skel.plugin.ini [new file with mode: 0644]
skel/plugin/skel.plugin.sb.php [new file with mode: 0644]
skel/plugin/skel.plugin.sf.php [new file with mode: 0644]
skel/plugin/skel.plugin.sm.php [new file with mode: 0644]
skel/plugin/skel.plugin.v.php [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index fb0e824..f900e4c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -46,6 +46,7 @@
 --- ethna uninstall-plugin (削除)
 --- ethna upgrade-plugin (削除)
 --- ethna list-plugin (削除)
+-- プラグインパッケージのスケルトンを生成するコマンドとして ethna create-plugin コマンドを追加
 -- Filterは一貫してプラグインを使うように変更したため、add-project時の app/filter ディレクトリを削除。
 - Smartyに関する変更
 -- Smarty を 2.6.26 に追随
diff --git a/class/Plugin/Generator/CreatePlugin.php b/class/Plugin/Generator/CreatePlugin.php
new file mode 100644 (file)
index 0000000..678cd46
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  CreatePlugin.php
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com> 
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna
+ *  @version    $Id$
+ */
+
+// {{{ Ethna_Plugin_Generator_CreatePlugin
+/**
+ *  プラグインパッケージスケルトン生成クラス
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com> 
+ *  @access     public
+ *  @package    Ethna
+ */
+class Ethna_Plugin_Generator_CreatePlugin extends Ethna_Plugin_Generator
+{
+    /**
+     *  テンプレートのスケルトンを生成する
+     *
+     *  @access public
+     *  @param  string  $basedir        ベースディレクトリ
+     *  @param  array   $types          プラグインのtype (Validator, Handle等)
+     *  @param  string  $no_ini         iniファイル生成フラグ 
+     *  @param  string  $plugin_name    プラグイン名 
+     *  @return true|Ethna_Error        true:成功 Ethna_Error:失敗
+     */
+    function &generate($basedir, $types = array(), $no_ini = false, $plugin_name)
+    {
+        //  create plugin directory
+        $plugin_dir = "$basedir/$plugin_name";
+        if (!file_exists($plugin_dir)) {
+            Ethna_Util::mkdir($plugin_dir, 0755);
+        } else {
+            printf("directory [$plugin_dir] already exists -> skip.\n");
+        }
+        //   type check.
+        if (empty($types)) {
+            return Ethna::raiseError('please specify plugin type.');
+        }
+
+        //   generate ini file
+        if ($no_ini == false) {
+            $ini_skel = 'plugin/skel.plugin.ini';
+            $ini_file = strtolower($plugin_name) . '.ini';
+            $ini_path = "$plugin_dir/$ini_file";
+        
+            $macro['plugin_name'] = $plugin_name;
+            if (file_exists($ini_path)) {
+                printf("file [%s] already exists -> skip\n", $ini_file);
+            } else if ($this->_generateFile($ini_skel, $ini_path, $macro) == false) {
+                printf("[warning] file creation failed [%s]\n", $ini_file);
+            } else {
+                printf("plugin ini file successfully created [%s]\n", $ini_file);
+            }
+        }
+
+        //
+        //   Generate Plugin PHP File   
+        //
+        $plugin_name = ucfirst(strtolower($plugin_name));
+        $lplugin_name = strtolower($plugin_name);
+        foreach ($types as $type) {
+            $ltype = strtolower($type);
+            $macro['plugin_type'] = $type;
+            $plugin_file_skel = "plugin/skel.plugin.${ltype}.php";
+        
+            //   create directory
+            switch ($type) {
+            case 'f':
+                $type = 'Filter';
+                $pfilename = "${plugin_name}.php";
+                break;
+            case 'v':
+                $type = 'Validator';
+                $pfilename = "${plugin_name}.php";
+                break;
+            case 'sm':
+                $type = 'Smarty';
+                $pfilename = "modifier.${lplugin_name}.php";
+                break;
+            case 'sb':
+                $type = 'Smarty';
+                $pfilename = "block.${lplugin_name}.php";
+                break;
+            case 'sf':
+                $type = 'Smarty';
+                $pfilename = "function.${lplugin_name}.php";
+                break;
+            }
+            $type_dir = "$plugin_dir/$type";
+            if (!file_exists($type_dir)) {
+                Ethna_Util::mkdir($type_dir, 0755);
+            }
+
+            $type_file_path = "$type_dir/${pfilename}";
+
+            // generate
+            if (file_exists($type_file_path)) {
+                printf("file [%s] already exists -> skip\n", $type_file_path);
+            } else if ($this->_generateFile($plugin_file_skel, $type_file_path, $macro) == false) {
+                printf("[warning] file creation failed [%s]\n", $type_file_path);
+            } else {
+                printf("plugin php file successfully created [%s]\n", $type_file_path);
+            }
+        } 
+
+        $true = true;
+        return $true;
+    }
+}
+// }}}
+?>
diff --git a/class/Plugin/Handle/CreatePlugin.php b/class/Plugin/Handle/CreatePlugin.php
new file mode 100644 (file)
index 0000000..f28567f
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  CreatePlugin.php
+ *
+ *  please go to http://ethna.jp/ethna-document-dev_guide-pearchannel.html
+ *  for more info.
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna
+ *  @version    $Id$
+ */
+
+// {{{ Ethna_Plugin_Handle_CreatePlugin
+/**
+ *  create Ethna Plugin Skelton handler.
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @access     public
+ *  @package    Ethna
+ */
+class Ethna_Plugin_Handle_CreatePlugin extends Ethna_Plugin_Handle
+{
+    // {{{ perform()
+    /**
+     * @access public
+     */
+    function perform()
+    {
+        $r =& $this->_getopt(
+            array(
+                'basedir=',
+                'type=',
+                'noini',
+            )
+        ); 
+        if (Ethna::isError($r)) {
+            return $r;
+        }
+        list($opt_list, $arg_list) = $r;
+
+        //  plugin name
+        $plugin_name = array_shift($arg_list);
+        if (empty($plugin_name)) {
+            return Ethna::raiseError('Please specify plugin Name.', 'usage');
+        }
+
+        //  plugin types
+        $type = end($opt_list['type']);
+        $types = explode(',', $type);
+        if (empty($type)) {
+            $types = array('v', 'f', 'sm'); // Validator, Filter, Smarty modifier.
+        } 
+
+        //  basedir
+        if (isset($opt_list['basedir'])) {
+            $basedir = realpath(end($opt_list['basedir']));
+        } else {
+            $basedir = getcwd();
+        }
+
+        //  no-ini file flag.
+        $no_ini = (isset($opt_list['noini'])) ? true : false; 
+
+        $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $no_ini, $plugin_name);
+        if (Ethna::isError($r)) {
+            printf("error occurred while generating plugin skelton. please see also error messages given above\n\n");
+            return $r;
+        }
+        printf("\nplugin skelton for [%s] is successfully generated at [%s]\n\n", $plugin_name, "$basedir/$plugin_name");
+        return true;
+    }
+    // }}}
+
+    // {{{ getDescription()
+    /**
+     *  @access public
+     */
+    function getUsage()
+    {
+        return <<<EOS
+ethna {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-n|--noini] plugin-name
+    type is as follows (separated by comma):
+        f = Filter,
+        v = Validator,
+        sb = Smarty block,
+        sf = Smarty function,
+        sm = Smarty modifier
+EOS;
+    }
+    // }}}
+
+    // {{{ getDescription()
+    /**
+     *  @access public
+     */
+    function getDescription()
+    {
+        return <<<EOS
+make plugin package:
+    {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-n|--noini] plugin-name
+EOS;
+    }
+    // }}}
+}
+// }}}
+?>
diff --git a/skel/plugin/skel.plugin.f.php b/skel/plugin/skel.plugin.f.php
new file mode 100644 (file)
index 0000000..9ccbf0a
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_Plugin_Filter_{$plugin_name}
+ *
+ *  @author     your name <yourname@example.com>
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna_Plugin
+ *  @version    $Id$
+ */
+
+// {{{ Ethna_Plugin_Filter_{$plugin_name}
+/**
+ *  Filter Plugin Class {$plugin_name}.
+ *
+ *  @author     yourname <yourname@example.com>
+ *  @access     public
+ *  @package    Ethna_Plugin 
+ */
+class Ethna_Plugin_Filter_{$plugin_name} extends Ethna_Plugin_Filter
+{
+    /**
+     *  filter before first processing.
+     *
+     *  @access public
+     */
+    function preFilter()
+    {
+    }
+
+    /**
+     *  filter BEFORE executing action.
+     *
+     *  @access public
+     *  @param  string  $action_name  Action name.
+     *  @return string  null: normal.
+     *                string: if you return string, it will be interpreted
+     *                        as Action name which will be executed immediately.
+     */
+    function preActionFilter($action_name)
+    {
+    }
+
+    /**
+     *  filter AFTER executing action.
+     *
+     *  @access public
+     *  @param  string  $action_name    executed Action name.
+     *  @param  string  $forward_name   return value from executed Action.
+     *  @return string  null: normal.
+     *                string: if you return string, it will be interpreted
+     *                        as Forward name.
+     */
+    function postActionFilter($action_name, $forward_name)
+    {
+    }
+
+    /**
+     *  filter which will be executed at the end.
+     *
+     *  @access public
+     */
+    function postFilter()
+    {
+    }
+}
+// }}}
+?>
diff --git a/skel/plugin/skel.plugin.ini b/skel/plugin/skel.plugin.ini
new file mode 100644 (file)
index 0000000..f353e1d
--- /dev/null
@@ -0,0 +1,35 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; {$plugin_name} - for Ethna Plugin Package.
+;;;
+;;; command line to get package tgz files:
+;;; > ethna make-plugin-package Package_Dir
+;;;
+;;; $Id$
+;;; 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+[plugin]
+name    = Ethna_Plugin_{$plugin_name}
+extlib  = true
+app_only = false
+
+[package]
+channel = __uri 
+summary = "your plugin summary"
+description = "your plugin description"
+
+[release]
+version = 1.0.0
+state   = stable
+notes   = "your plugin release note."
+
+[maintainers]
+role1   = lead
+name1   = your name 
+user1   = your handle name
+email1  = yourname@example.com
+active1 = yes
+
+[license]
+name    = The BSD License
+uri     = http://www.opensource.org/licenses/bsd-license.php
diff --git a/skel/plugin/skel.plugin.sb.php b/skel/plugin/skel.plugin.sb.php
new file mode 100644 (file)
index 0000000..44e7e50
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  {$plugin_name} Smarty block Plugin
+ *
+ *  @author     your name <yourname@example.com>
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna_Plugin
+ *  @version    $Id$
+ */
+
+function smarty_block_{$plugin_name}($params, $content, &$smarty, &$repeat)
+{
+}
+?>
diff --git a/skel/plugin/skel.plugin.sf.php b/skel/plugin/skel.plugin.sf.php
new file mode 100644 (file)
index 0000000..30ee80a
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  {$plugin_name} Smarty function Plugin
+ *
+ *  @author     your name <yourname@example.com>
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna_Plugin
+ *  @version    $Id$
+ */
+
+function smarty_function_{$plugin_name}($params, &$smarty)
+{
+}
+?>
diff --git a/skel/plugin/skel.plugin.sm.php b/skel/plugin/skel.plugin.sm.php
new file mode 100644 (file)
index 0000000..1aae5a5
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  {$plugin_name} Smarty modifier Plugin
+ *
+ *  @author     your name <yourname@example.com>
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna_Plugin
+ *  @version    $Id$
+ */
+
+function smarty_modifier_{$plugin_name}($string)
+{
+}
+?>
diff --git a/skel/plugin/skel.plugin.v.php b/skel/plugin/skel.plugin.v.php
new file mode 100644 (file)
index 0000000..f6ef3f6
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_Plugin_Validator_{$plugin_name}
+ *
+ *  @author     your name <yourname@example.com>
+ *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
+ *  @package    Ethna_Plugin
+ *  @version    $Id$
+ */
+
+// {{{ Ethna_Plugin_Validator_{$plugin_name}
+/**
+ *  Validator Plugin Class {$plugin_name}.
+ *
+ *  @author     yourname <yourname@example.com>
+ *  @access     public
+ *  @package    Ethna_Plugin 
+ */
+class Ethna_Plugin_Validator_{$plugin_name} extends Ethna_Plugin_Validator 
+{
+    /** @var    bool    配列を受け取るかフラグ */
+    var $accept_array = true;
+
+    // {{{ perform
+    /**
+     *  Validate something
+     *
+     *  @access public
+     *  @param  string  $name       フォームの名前
+     *  @param  mixed   $var        フォームの値
+     *  @param  array   $params     プラグインのパラメータ
+     */
+    function &validate($name, $var, $params)
+    {
+        //
+        //   sample
+        //
+        //$form_def = $this->getFormDef($name);
+        //var_dump($form_def['type']);
+        //if (empty($var)) {
+        //    return Ethna::raiseNotice("empty!");
+        //}
+        return true;
+    }
+    // }}}
+}
+// }}}
+?>