Plone 主题可以通过 ZMI 直接在后台进行修改,但是这也只能满足一部分需求,如果我们需要更多可定制的操作,那么就需要完全的创建新的主题,在 Plone 中要创建一个主题,很简单。

使用 paster 创建 Plone 主题

Plone 安装完成之后,在 {instance_path}/bin 目录中,就有 paster,通过它,我们可以创建许多东西,比如创建新的 content type,在这里,我们就使用它来创建新的 Plone 主题。

首先,进入 {instance_path}/src/ 目录:

cd /path/to/instance/src

之后运行下列命令:

../bin/paster create -t plone3_theme aitinetheme.aitine

然后脚本会询问你一些问题,你只需要按着你的实际情况以脚本提供的格式回复即可。脚本运行完成之后,就会在 ./src 目录中生成 aitinetheme.titine 目录,这就是新的 plone 主题目录,之后的所有操作都将在该目录中进行。

使用 sc.paster.theme 创建 plone 主题

本文重点将介绍使用 sc.paster.theme 这个工具来创建 plone 主题,虽然和 paster 有点像,但是我个人还是更喜欢这个工具。

安装 sc.paster.theme

该工具并没有默认提供,我们需要先安装它,使用 easy_install 命令即可,在这里,我们有一点需要记住,如果你的 Zope 服务器使用的是自带的 Python ,那么,你不能直接执行 easy_install ,因为这样会将其安装到全局的 Python 环境中,我们需要指出 Zope 服务器所使用的 Python 路径,比如:

/Applications/Plone/Python-2.6/bin/easy_install -U sc.paster.theme

安装需要 gcc 等工具,你需要先安装,如果你在 Mac OS X 下安装,那么需要安装 XCode 命令行工具集才行,如果你是在 Windows 下面安装,对不起,哥真不知道应该怎么整。

在 {instance_path}/bin 目录中创建 sc.paster.theme 脚本的快捷方式

sc.paster.theme 安装完成之后,进入 {instance_path}/bin 目录,创建 sc.paster.theme 的链接文件,我这里使用的是硬链接,当然一定要记住,你需要为其重新命名,因为 Plone 本身已经有了一个 paster 脚本了。

ln /Applications/Plone/Python-2.6/bin/paster ./sc_paster

使用 sc.paster.theme 创建 Plone 主题

与 paster 一样,先进入 src 目录,然后执行下面这行命令:

../bin/sc_paster create -t portal_theme aitine.theme.aitine

该命令同样会询问你一些问题,你一样需要一个一个回答,如果按我创建我的 aitine.theme.aitine这个主题来讲的话,整个命令的运行流程如下:

PanTao-Macbook-Pro:src pantao$ ../bin/sc_paster create -t portal_theme aitine.theme.aitine
Selected and implied templates:
sc.paster.theme#portal_theme Tema visual para projetos Plone 3
Variables:
egg: aitine.theme.aitine
package: aitinethemeaitine
project: aitine.theme.aitine
Expert Mode? (What question mode would you like? (easy/expert/all)?) ['easy']: all
Namespace Package Name (Namespace principal) ['aitine']:
Namespace 2 Package Name (Usualmente o nome do cliente) ['theme']:
Package Name (Nome do projeto) ['aitine']:
Description (One-line description of the project) ['']: A plone theme designed by aitine.com, for Aitine.
Creating template portal_theme
Creating directory ./aitine.theme.aitine
Recursing into +namespace_package+
Creating ./aitine.theme.aitine/aitine/
Recursing into +namespace_package2+
......
Copying LICENSE.GPL to ./aitine.theme.aitine/docs/LICENSE.GPL
Copying LICENSE.txt_tmpl to ./aitine.theme.aitine/docs/LICENSE.txt
Copying setup.cfg to ./aitine.theme.aitine/setup.cfg
Copying setup.py_tmpl to ./aitine.theme.aitine/setup.py
Running /Applications/Plone/Python-2.6/bin/python setup.py egg_info

中间很长一段信息已经被我省略了,之后,我们在 src 目录中,就会得到一个名为:@aitine.theme.aitine@ 的文件夹,它就是我们的主题。之后我们还需要将其添加到 buildout.cfg 文件中,添加方式如下:

eggs =
......
aitine.theme.aitine
zcml =
......
aitine.theme.aitine
develop =
......
src/aitine.theme.aitine

添加完成之后,我们需要更新我们的 instance,然后再以 fg 模工运行 Plone:

PanTao-Macbook-Pro:zinstance pantao$ ./bin/buildout
Develop: '/Applications/Plone/zinstance/src/aitine.theme.aitine'
Uninstalling zopeskel.
......
PanTao-Macbook-Pro:zinstance pantao$ ./bin/plonectl fg
instance: 2012-03-19 20:47:44 INFO ZServer HTTP server started at Mon Mar 19 20:47:44 2012
    Hostname: 0.0.0.0
    Port: 8080
2012-03-19 20:47:45 WARNING SecurityInfo Conflicting security declarations for "setText"
2012-03-19 20:47:45 WARNING SecurityInfo Class "ATTopic" had conflicting security declarations
2012-03-19 20:48:01 INFO Zope Ready to handle requests

当你看到 Zope Ready to handle requests 信息时,你的 Plone 已经以 fg 模式运行成功了,现在你需要进入你的开发站点,启用这个主题即可,以 fg 模式运行时,你对主题的修改能即时的展示在前端。

标签: none

评论已关闭