設定プロダクトの準備 [Plone4.0]
設定プロダクトの準備
プロダクトの用意
Ploneインスタンスディレクトリ(/usr/local/Plone/zinstance/ など)で次のように実行し、プロダクトのひな形を作成する。
# bin/paster create -t plone Products.PloneEngSettings
Expert Mode? (What question mode would you like? (easy/expert/all)?) ['easy']:
Version (Version number for project) ['1.0']:
Description (One-line description of the project) ['']:
Register Profile (Should this package register a GS Profile) [False]: True
翻訳の設定
翻訳の追加や修正を行えるようにする。設定プロダクト内に locales/ja/LC_MESSAGES ディレクトリを作成し plone.po ファイルを次のように作成する。
msgid ""
msgstr ""
"Project-Id-Version: Products.PloneEngSettings\n"
"PO-Revision-Date: 2012-06-21 11:35+0900\n"
"Last-Translator: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0\n"
"Language-Code: ja\n"
"Language-Name: Japanese\n"
"Preferred-Encodings: utf-8 latin1\n"
"Domain: plone\n"
msgid "KyotoUniv"
msgstr "学内利用者"
次にコンパイルを行う。
$ msgfmt -o plone.mo plone.po
最後に locales ディレクトリが読み込まれるようにする。設定プロダクトのルートに次のように追記すれば良い。
<i18n:registerTranslations directory="locales" />
browser ディレクトリの作成
プロダクトのルートに browser ディレクトリを次のような構成として作成する。
/
|--configure.zcml
|--browser/ |--__init__.py |--configure.zcml |--interfaces.py
- __init__.py
空のファイルとして作成しておく。
- configure.zcml
<configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser" xmlns:plone="http://namespaces.plone.org/plone"> </configure>
- interfaces.py
from plone.theme.interfaces import IDefaultPloneLayer class IThemeSpecific(IDefaultPloneLayer): """Marker interface that defines a Zope 3 skin layer bound to a Skin Selection in portal_skins. """
プロダクトのルートの configure.zcml に上記で作成した browser ディレクトリを読み込むよう次のように追記しておく。
<include package=".browser" />
スキンの準備
スキンの作成
Plone ではスキンは機能毎に細かく分かれていて、Layers 欄の上のフォルダ内から順番に探して、一番最初に見つかったものが利用される。変更点のみ custom フォルダ内で行ってもよいが、新たにスキンを定義しておく。作成したスキンは portal_skins の Properties で選択することができる。
まず テンプレート等の格納フォルダとして ZMI 上で portal_skins 内に univ_skins フォルダを作成する。この変更を設定プロダクトで行うには、設定プロダクトのルートに skins/univ_skins ディレクトリを追加し、__init__.py に次のように追記すれば良い。
from Products.CMFCore.DirectoryView import registerDirectory
GLOBALS = globals()
registerDirectory('skins', GLOBALS)
次に新しくスキンを作成する。portal_skins の Properties タブを開き Add a new skin より新しくスキンを追加する。Layers の custom 直下に新しく作ったフォルダを書くことで、このフォルダに作成すると custom の次に優先して適用されることになる。
Name : School Skin xx Layers : custom univ_skins : 以下 Sunburst Theme の Layers と同じ
プロダクトで変更するには profiles/default/skins.xml を次のように作成する。
<?xml version="1.0"?>
<object name="portal_skins">
<object name="univ_skins" meta_type="Filesystem Directory View"
directory="PloneEngSettings/skins/univ_skins"/>
<skin-pathname="My Theme" based-on="Sunburst Theme">
<layer name="univ_skins" insert-after="custom" />
</skin-path>
</object>
configure.zcmlの設定
プロダクトの browser ディレクトリの configure.zcml ファイルを次のように編集する。
+ <interface + interface=".interfaces.IThemeSpecific" + type="zope.publisher.interfaces.browser.IBrowserSkinType" + name="My Theme" + />
スタイルシートの追加・削除
独自のスタイルシートファイルを作成するには portal_css に登録することで利用できる。
portal_css の Add a new stylesheet より、次の設定を追加する。ここで登録する CSS ファイル kyotouniv.css は、あらかじめスキンフォルダに作成しておく。
ID : kyotouniv.css Title : Kyoto Univ CSS CSS Media : all
自動的に ploneCustom.css の次に優先される CSS となるが、これは順番を入れ替えることで設定できる。
これをプロダクトで変更するには profiles/default/cssregistry.xml を次のように作成する。
<?xml version="1.0"?>
<object name="portal_css" meta_type="Stylesheets Registry" autogroup="False">
<stylesheet title="Kyoto Univ CSS" cacheable="True" compression="safe"
cookable="True" enabled="on" expression="" id="kyotouniv.css" media="all"
rel="stylesheet" rendering="import"/>
</objecy>
逆に CSSの登録を解除するには、 portal_css で該当の CSSのチェックを外せばよい。たとえば mobile.css のチェックを外すと、モバイル用の CSSの登録を解除できる。
mobile.css : OFF
これをプロダクトで変更するには profiles/default/cssregistry.xml を次のように変更する。
<?xml version="1.0"?>
<object name="portal_css" meta_type="Stylesheets Registry" autogroup="False">
<stylesheet title="" cacheable="True" compression="safe"
conditionalcomment="" cookable="True" enabled="False" expression=""
id="mobile.css" media="handheld" rel="stylesheet" rendering="import"/>
</objecy>
Javascriptの追加
独自のJavascriptファイルを作成するには portal_javascript に登録することで利用できる。
portal_javascript の Add a new scriptより、次の設定を追加する。ここで登録する JSファイル kyotouniv.js は、あらかじめスキンフォルダに作成しておく。
ID/URL : kyotouniv.js
これをプロダクトで変更するには profiles/default/jsregistry.xml を次のように作成する。
<?xml version="1.0"?>
<object name="portal_javascripts" meta_type="JavaScripts Registry">
<javascript authenticated="False" cacheable="True" compression="safe"
conditionalcomment="" cookable="True" enabled="True" expression=""
id="kyotouniv.js" inline="False"/>
</object>