Created
September 15, 2012 13:22
-
-
Save batako/3727831 to your computer and use it in GitHub Desktop.
Kwartz : コンバート
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 第一引数をコンマ区切りで配列に変換 | |
STRING=${1##*/} | |
ary=( `echo $STRING | tr -s '.' ' '`) | |
# コンバート後のファイルの保存ディレクトリ | |
DIR="./" | |
# ディレクトリ指定がある場合はパスにシュラッシュを付加して代入 | |
if [ $# -gt 1 ] ; then | |
# 保存先のディレクトリが存在するかチェック | |
if [ -d $2 ] ; then | |
DIR=`echo $2 | sed -e 's/^\(.*\)\/$/\1/'`/ | |
else | |
echo -e "\tErr - $2 does not exist." | |
exit | |
fi | |
fi | |
# 第一引数が「ファイル名.ファイルの種類」となっていない | |
if [ 2 != ${#ary[*]} ] ; then | |
echo -e "\tErr - illegal args" | |
exit | |
fi | |
# コンバート対象のファイルがある絶対パス | |
if [ -d ${1%/*} ] ; then | |
TAGE_DIR=`cd ${1%/*};pwd`/ | |
else | |
TAGE_DIR=`pwd`/ | |
fi | |
# ロジックファイルなし | |
if [ ! -f $1.plogic ] ; then | |
echo -e "\tErr - $1.plogic does not exist." | |
exit; | |
fi | |
# レイアウトファイルなし | |
if [ ! -f $TAGE_DIR${ary[0]}.html ] ; then | |
echo -e "\tErr - ${ary[0]}.html does not exist." | |
exit | |
fi | |
# コンバートタイプ指定 | |
case ${ary[1]} in | |
"eruby" ) TYPE="eruby" ;; | |
"rb" ) TYPE="ruby" ;; | |
"pierubis" ) TYPE="pierubis" ;; | |
"php" ) TYPE="php" ;; | |
"jstl" ) TYPE="jstl" ;; | |
"eperl" ) TYPE="eperl" ;; | |
* ) echo -e "\tErr - illegal extension : ${ary[1]}"; exit ;; | |
esac | |
# コンバート | |
kwartz -l $TYPE -p $TAGE_DIR${ary[0]}.${ary[1]}.plogic $TAGE_DIR${ary[0]}.html > $DIR${ary[0]}.${ary[1]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment