<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog::2310 &#187; Net Commons</title>
	<atom:link href="http://blog.2310.net/archives/category/net_commons/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.2310.net</link>
	<description>2310</description>
	<lastBuildDate>Sat, 06 Aug 2011 23:40:52 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>NetCommonsモジュールを(無理矢理)作成</title>
		<link>http://blog.2310.net/archives/380</link>
		<comments>http://blog.2310.net/archives/380#comments</comments>
		<pubDate>Thu, 01 Jan 2009 12:11:24 +0000</pubDate>
		<dc:creator>2310</dc:creator>
				<category><![CDATA[Net Commons]]></category>

		<guid isPermaLink="false">http://blog.2310.net/?p=380</guid>
		<description><![CDATA[最近NetCommonsにちょっとずつ触れています。 使い方も内容もまだほとんど分かりませんが、手探りで非常に簡単なモジュールを作ってみようと思います。 無理矢理モジュールディレクトリを作成する モジュールは html/webapp/modules/ ディレクトリの下に配置されています。 そこで、ここに無理矢理testというディレクトリを作成します。モジュールはtestです。 install.iniを作成する 次にbbsとかmenuとかのモジュールを見ると、トップディレクトリに「install.ini」が含まれていますのでそれを参考にします。 以下がinstall.iniの内容になります。2行です。 version = "1.0.0.0" action_name = "test_view_main" versionは適当で良いと思います。action_nameはおそらくtestモジュールのデフォルトのアクセス先になるんだと思います。 アクションクラスファイルを作成する 上の例だと最初のアクセス先は html/webapp/modules/test/view/main/Main.class.php となるようです。modules以降のディレクトリは上のaction_nameの中の&#8217;_'を&#8217;/'に置換したものとなっています。 Main.class.phpは最後の&#8221;test_view_main&#8221;のmainの最初を大文字にしたものですが、これで無いといけないのかどうか分かりません。 ただ他のモジュールは皆このルールに従っているようです。 アクションクラスを編集する さて、Main.class.phpの中でaction用のクラスをこしらえます。クラスの名前はTest_View_Mainであり、Actionを継承しなければなりません。 また、executeメソッドは必須です。 &#60;?php // html/webapp/modules/test/view/main/Main.class.php の内容 class Test_View_Main extends Action { function execute() { return 'success'; } } maple.iniを作成する Mapleはmaple.iniという動作設定ファイルで様々な制御を行なっていきます。 html/webapp/modules/test/view/main/maple.ini を作成して、内容を [View] success = "main.html" とします。Test_View_Mainクラスにアクセスがあり、executeが&#8217;success&#8217;を返すとこのmaple.iniの内容に従ってテンプレート&#8217;main.html&#8217;が呼び出されます。 テンプレートを作成する このテンプレートの場所はMaple標準だとwebapp/templatesになるらしいです。NetCommonsだと html/webapp/modules/test/templates/default/main.html となるようです。main.htmlの中は適当に、 [...]]]></description>
			<content:encoded><![CDATA[<p>最近<a href="http://www.netcommons.org/" title="NetCommons2公式サイト - ホーム">NetCommons</a>にちょっとずつ触れています。</p>

<p>使い方も内容もまだほとんど分かりませんが、手探りで非常に簡単なモジュールを作ってみようと思います。</p>

<p><span id="more-380"></span></p>

<h4>無理矢理モジュールディレクトリを作成する</h4>

<p>モジュールは html/webapp/modules/ ディレクトリの下に配置されています。
そこで、ここに無理矢理testというディレクトリを作成します。モジュールはtestです。</p>

<h4>install.iniを作成する</h4>

<p>次にbbsとかmenuとかのモジュールを見ると、トップディレクトリに「install.ini」が含まれていますのでそれを参考にします。
以下がinstall.iniの内容になります。2行です。</p>

<pre><code>version = "1.0.0.0"
action_name = "test_view_main"
</code></pre>

<p>versionは適当で良いと思います。action_nameはおそらくtestモジュールのデフォルトのアクセス先になるんだと思います。</p>

<h4>アクションクラスファイルを作成する</h4>

<p>上の例だと最初のアクセス先は</p>

<pre><code>html/webapp/modules/test/view/main/Main.class.php
</code></pre>

<p>となるようです。modules以降のディレクトリは上のaction_nameの中の&#8217;_'を&#8217;/'に置換したものとなっています。
Main.class.phpは最後の&#8221;test_view_main&#8221;のmainの最初を大文字にしたものですが、これで無いといけないのかどうか分かりません。
ただ他のモジュールは皆このルールに従っているようです。</p>

<h4>アクションクラスを編集する</h4>

<p>さて、Main.class.phpの中でaction用のクラスをこしらえます。クラスの名前はTest_View_Mainであり、Actionを継承しなければなりません。
また、executeメソッドは必須です。</p>

<pre><code>&lt;?php // html/webapp/modules/test/view/main/Main.class.php の内容
class Test_View_Main extends Action
{
    function execute()
    {
        return 'success';
    }
}
</code></pre>

<h4>maple.iniを作成する</h4>

<p><a href="http://kunit.jp/maple/wiki/index.php" title="Maple Wiki">Maple</a>はmaple.iniという動作設定ファイルで様々な制御を行なっていきます。</p>

<pre><code>html/webapp/modules/test/view/main/maple.ini
</code></pre>

<p>を作成して、内容を</p>

<pre><code>[View]
success = "main.html"
</code></pre>

<p>とします。Test_View_Mainクラスにアクセスがあり、executeが&#8217;success&#8217;を返すとこのmaple.iniの内容に従ってテンプレート&#8217;main.html&#8217;が呼び出されます。</p>

<h4>テンプレートを作成する</h4>

<p>このテンプレートの場所は<a href="http://kunit.jp/maple/wiki/index.php" title="Maple Wiki">Maple</a>標準だと<a href="http://kunit.jp/maple/wiki/index.php?%A5%C1%A5%E5%A1%BC%A5%C8%A5%EA%A5%A2%A5%EB%2F%A5%AF%A5%A4%A5%C3%A5%AF%A5%B9%A5%BF%A1%BC%A5%C8">webapp/templatesになるらしいです</a>。<a href="http://www.netcommons.org/" title="NetCommons2公式サイト - ホーム">NetCommons</a>だと</p>

<pre><code>html/webapp/modules/test/templates/default/main.html
</code></pre>

<p>となるようです。main.htmlの中は適当に、</p>

<pre><code>&lt;{strip}&gt;
&lt;{* 表示用テンプレート *}&gt;
  Hello,World
&lt;{/strip}&gt;
</code></pre>

<p>としておきます。&lt;{strip}&gt;〜&lt;{/strip}&gt;は<a href="http://sunset.freespace.jp/smarty/SmartyManual_2-6-7J_html/language.function.strip.html">smartyの関数</a>らしいです。
タグ間の改行などを取り除きを一行で出力するみたいです。いずれにしても<a href="http://www.smarty.net/manual/ja/">smarty</a>の勉強も必要ということです。</p>

<h4>モジュール情報を作成する</h4>

<p>最後にモジュールの情報を</p>

<pre><code>html/webapp/modules/test/language/japanese/modinfo.ini
</code></pre>

<p>に書き込みます。</p>

<pre><code>module_name = "Hello, World"
</code></pre>

<p>とモジュール名を設定します。</p>

<h4>終了</h4>

<p>…最も簡単なモジュールが完成しました。管理者としてログインしモジュール管理からインストールしてみます。インストールして分かるのは、</p>

<ul>
<li>移動するコンテナにするにはまだ別の仕組みが必要らしい</li>
</ul>

<p>ということです。</p>

<h4>スタイルシートを作成する</h4>

<p>main.htmlにスタイルシートを適用したい場合は、上のmaple.iniに</p>

<pre><code>[HeaderInc]
test_css = "test:{$temp_name}/style.css"
</code></pre>

<p>を追加します。こうすることによって</p>

<pre><code>html/webapp/modules/test/files/css/default/style.css
</code></pre>

<p>がスタイルシートとして読み込まれます。ただしstyle.cssへの直リンクではなく、システムが各モジュールのcssをかきあつめて表示しているみたいです。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.2310.net/archives/380/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

