spina cms 的theme


创建了spina app后,第一件事就是配置你的theme。 初始化的theme放在: config/initalizers/themes/default.rb

有下面几个配置项:
Parts, 局部
View templates ,视图模板
Custom page, 自定义页面
Resources, 资源
Navigations, 导航
Layout parts, 布局
Plugins, 插件

Parts 局部
parts是Spina内容模型的核心。所有的页面内容都是通过parts构成的。
Spina有一组很棒的parts提供了灵活性,所有包含的parts都是POROs(Plain Old Ruby Objects)文本ruby对象,包含AttrJson::Model 模块,所有的内容通过JSON存储而且AttrJson可以启用他们。

很容易增加你自己的可以定义的parts,但是几乎不需要。确认你的自定义parts能够作为JSON存储就满足自定义要求了。

在你的theme的配置中,把所有的parts你将用的theme.parts 数组。我们将在下面参考这些parts。

例如:
theme.parts = [
{name: 'text', title: "Body", part_type: "Spina::Parts::Text"},
{name: 'image', title: "Image", part_type: "Spina::Parts::Image"}
]
参考链接the docs to learn about all configuration options for the included parts.

  • Spina::Parts::Line
  • Spina::Parts::MultiLine
  • Spina::Parts::Text
  • Spina::Parts::Image
  • Spina::Parts::ImageCollection
  • Spina::Parts::Repeater
  • Spina::Parts::Option

View templates
Spina的每页都有个view template用来定义哪一个parts可用在本页上。这种方式非常简单的去包含一个页面的局部而不需要其它部分。
例如:

theme.view_templates = [
{name: 'homepage', title: 'Homepage', parts: %w(text)},
{name: 'show', title: 'Page', description: 'Default page template', parts: %w(image text)}
]

这个view template 名字这个匹配actual view template 位于app/views/[your_temem]/pages/. 这个描述key是用来显示终端用户,一个view template 能够被用来干啥。 增加一个description到你的view templates 是可选的,但是推荐使用。

自定义pages
有些页面非常特殊,最明显的例子是你的首页,页面pages定义在theme.custom_pages 会自动生成当设置你的website,能够通过这些名字调用。

Example
theme.custom_pages = [
{name: 'homepage', title: 'Homepage', deletable: false, view_template: 'homepage'}
]
在这个例子中,我们确保homepage是不可删除的,确保页面使用homepage 的view template. 当一个non-deletable的自定义页面使用一个particular局部view template, 那个view template将不可用于其它页面。用户为同一个网站建立额外的homepages没有意义。


Navigation 导航
非常简单的websites(个人网站只要5个页面)通过一个列表简单的渲染所有的页面作为导航。大多数网站需要复杂点的控制渲染和排序。你可以为你的theme定义多个导航.你可以有一个主导航在顶部和另外一个导航在底部。
例如
theme.navigations = [
{name: 'main', label: 'Main navigation'},
{name: 'footer', label: 'Footer navigation'}
]
另外,删除和排序entries在导航里面发生在Spina' UI.你不需要在theme config文件里面处理

Layout parts
页面有内容,划分成多个parts,有时候你想去编辑的内容不属于单个页面,就用layout替代。像taglines, copyright notices or USPs. 你可以再theme.layout_parts里面定义。

例如:
theme.layout_parts = ["copyright", "usps"]
你只需要设置你想用的这个parts的名字,确保你只是增加parts你已经再theme.parts里面定义过,先在theme.parts里面定义,然后在theme.layout_parts里面使用。

Resources 资源
资源是重要的工具图organise页面。他们是独立的页面集合。你想管理多个文章(好比你正在读的文章),我们可以创建一个resource called articles.
Example

theme.resources = [
{name: 'articles', label: "Articles", view_template: "articles", slug: "articles"}
]

在Spina's UI 你现在有能力去创建文章在 Articles Collections。前端获得所有的文章变得容易: Spina::Resource.find_by(name: "articles").pages

在resources里面的页面会自动排序, 在Spina's UI你可以切换 between a number of different sorting options, 包括手动排序。


Plugins插件
如果你用Spina plugins你能够启用哪些for your theme 通过引用them在theme.plugins.
例如:
theme.plugins = ['reviews']
你不是必须要做这些,所有可用的插件默认都是启用的。

阅读量: 414
发布于:
修改于: