Karesansui に Hello World ページを新しく追加する手順です。
開発ドキュメントの開発環境を作ってみるを参照し、開発環境を構築します。
以下の流れで新規ページを作成します。
templates/default/host/host.html ファイルを次のように編集します。
これにより Karesansui のホスト画面に、Hello タブが追加されます。
# cat templates/default/host/host.html | grep -e "<li class" -e "tab-left" -e "</li>"
<li class="top-tab">
<a class="tab-left" href="#" id="${ctx.homepath}/host.part"><span class="tab-right">${_('Summary')}</span></a>
</li>
<li class="top-tab">
<a class="tab-left" href="#" id="${ctx.homepath}/user.part"><span class="tab-right">${_('User')}</span></a>
</li>
<li class="top-tab">
<a class="tab-left" href="#" id="${ctx.homepath}/job.part"><span class="tab-right">${_('Job')}</span></a>
</li>
<li class="top-tab">
<a class="tab-left" href="#" id="${ctx.homepath}/tag.part"><span class="tab-right">${_('Tag')}</span></a>
</li>
<li class="top-tab">
<a class="tab-left" href="#" id="${ctx.homepath}/hello.part"><span class="tab-right">${_('Hello')}</span></a>
</li>
urls.py ファイルを次のように編集します。これにより、URL マッピングが行われるようになります。
# grep hello /git/karesansui.git/karesansui/urls.py
import karesansui.gadget.hello
+ karesansui.gadget.hello.urls \
gadget/hello.py ファイルを次のように作成します。
Notice: gadget ファイルを変更・作成した場合は、Web サーバーの再起動が必要となります。
# cat << 'EOS' > /git/karesansui.git/karesansui/gadget/hello.py
# -*- coding: utf-8 -*-
from karesansui.lib.rest import Rest, auth
class Hello(Rest):
@auth
def _GET(self, *param, **params):
return True
@auth
def _POST(self, *param, **params):
return True
urls = (
'/hello/?(\.part)$', Hello,
)
EOS
templates/default/hello/hello.part ファイルを次のように作成します。
# rm -rf /git/karesansui.git/karesansui/templates/default/hello
# mkdir /git/karesansui.git/karesansui/templates/default/hello
# cat << 'EOS' > /git/karesansui.git/karesansui/templates/default/hello/hello.part
<%inherit file="../include/common.part" />
<script type="text/javascript">
<!--
$(document).ready(function(){
$("#tool_renew").click(function(){
renew_msg(true);
});
});
-->
</script>
<div id="hello">
<div classs="alert"></div>
<div id="action" >
<div class="left"></div>
<div class="right">
<a href="#" class="tool-link" >
<div class="tool-mid">
<img src="${ctx.homepath}/static/images/reload.gif" alt="renew" id="tool_renew"/>
</div>
</a>
</div>
</div>
<br style="clear: both;"/>
<div class="space"/>
<div id="view">
<div class="hello-contents">
<br>
<div align="center">Hello World</div>
<br>
</div>
</div>
<br style="clear: both;"/>
</div>
EOS
static/css/style.css を次のように編集し、static/css/hello.css ファイルを作成します。
# grep hello /git/karesansui.git/karesansui/static/css/style.css
@import url('./hello.css');
# cat << 'EOS' > /git/karesansui.git/karesansui/static/css/hello.css
.hello-contents{
background-color:#FFFFFF;
border-color:#BCBCBC;
border-style:solid;
border-width:1px 1px 1px;
color:#000000;
font-size:12px;
margin-bottom:15px;
padding-bottom:5px;
padding-top:6px;
width:99.8%;
}
EOS
今回作成したファイルを、kss グループから読み込みできるように設定します。
# chown root:kss /git/karesansui.git/karesansui/gadget/hello.py # chown root:kss /git/karesansui.git/karesansui/static/css/hello.css # chown -R root:kss /git/karesansui.git/karesansui/templates/default/hello
次のコマンドで開発 Web サーバーを起動します。
既に起動している場合は、再起動を行ってください。
# su -s /bin/bash wwwhde -c "KARESANSUI_CONF=/etc/opt/karesansui/application.conf SEARCH_PATH=/opt/karesansui/lib/python:/opt/hde/lib/python:/opt/pysilhouette/lib/python /opt/karesansui/bin/karesansui.fcgi"
開発 Web サーバーに接続し、今回作成した Hello World ページが正常に表示されるかを確認してください。
最後に新しいページを作るにあたって、注意する点としては以下があります。
今回新しく作成した gadget ファイルを読み込めない場合に発生します。
ファイル属性の確認を行ってください。
今回新しく作成した template ファイルを読み込めない場合に発生します。
ファイル属性の確認を行ってください。