plone的静态文件
plone.resource的Python项目详细描述
简介
plone.resource 通过zpublisher发布静态文件目录。 这些目录可以位于zodb(作为ofs文件夹和文件)中,也可以位于文件系统中。
每个资源目录都有一个类型和一个名称。合并后,它们用于遍历到资源目录。 例如:
/++theme++mytheme/<subpath> /++sitelayout++mylayout/<subpath> /++templatelayout++mylayout<subpath>
存储资源的位置
遍历器可以在几个不同的位置找到资源目录内容。 按顺序尝试下列位置。
安装 plone.resource 会创建一个名为 portal\u resources 的zope文件夹。 它可以用来持久地存储资源目录。 按惯例:
- 此文件夹下的顶级文件夹对应于资源类型,
- 第二级文件夹对应于资源目录名。
因此,可在 /+theme++mytheme/myfile 处遍历的文件可以物理地位于 某些站点/+etc++site/resources/theme/mytheme
python发行版中的文件
python发行版中的文件夹(例如e g g)可以使用 plone:static zcml指令注册为特定类型和名称的资源目录。 例如,这会将名为"theme"的目录注册为名为"mytheme"的"theme"类型的资源目录。 它可以在 +theme++mytheme访问
<plone:static directory="theme" type="theme" name="mytheme" /> .. note:: You must do ``<include package="plone.resource" file="meta.zcml"/>`` before you can use the plone:static directive.
资源目录的名称默认为包的名称,因此可以省略。 例如,名为"mytheme"的包中的以下指令将导致与上述相同的注册:
<plone:static directory="resources" type="theme" />
由于安全原因,不支持使用 在目录路径中向上遍历。 因为它可能允许不需要的文件访问。
最小zcml配置示例
<configure xmlns:plone="http://namespaces.plone.org/plone"> <include package="plone.resource" file="meta.zcml"/> <plone:static directory="resources" type="theme" name="myproject" /> </configure> ..
中央资源目录中的文件
如果 plone:static 指令是从 site.zcml 使用的(即,在zcml导入上下文中没有活动包)。 然后它可以指定到顶级资源目录的绝对路径。
此目录应具有与上述相同的子目录结构(在zodb resources目录中):
- 此文件夹下的顶级文件夹对应于资源类型,
- 第二级文件夹对应于资源目录名。
此外,为了使资源可用,顶级目录需要注册一个遍历器!
例如, site.zcml 中的以下内容在构建根目录中注册给定的路径:
<plone:static directory="/path/to/buildout/resources" />
为了在构建时实现自动化,recipe有一个选项 resources 。 它通过指定如下选项将上述zcml片段插入到 site.zcml 中:
[instance] ... resources = ${buildout:directory}/resources ...<示例: 使用 plone.app.theming -它提供 +theme++ 遍历器-给定位于文件系统中的图像文件:
${buildout:directory}/resources/theme/my.project/logo.png``
这可以在这样的url上进行遍历:
http://localhost:8080/Plone/++theme++my.project/logo.png
附加遍历器
自定义遍历器可以通过zcml使用如下适配器进行注册:
<adapter name="demo" for="* zope.publisher.interfaces.IRequest" provides="zope.traversing.interfaces.ITraversable" factory="my.project.traversal.MyTraverser" />
具有相应的简单工厂定义:
/++theme++mytheme/<subpath> /++sitelayout++mylayout/<subpath> /++templatelayout++mylayout<subpath>0
如果再加上上面中央资源目录中的文件的配置,则意味着资源位于:
/++theme++mytheme/<subpath> /++sitelayout++mylayout/<subpath> /++templatelayout++mylayout<subpath>1
可以在这样的url上进行遍历:
/++theme++mytheme/<subpath> /++sitelayout++mylayout/<subpath> /++templatelayout++mylayout<subpath>2