跳转到主要内容

Plone的Handlebars

项目描述

https://travis-ci.org/collective/collective.handlebars.svg?branch=master https://coveralls.io/repos/github/collective/collective.handlebars/badge.svg?branch=master

该软件包的目的是为Plone提供handlebars.js支持。它是一个开发人员插件,提供BrowserView、Portlet、Viewlet和Tile的附加变体,这些变体使用handlebars.js模板而不是TAL。它可以用于优化设计师和Plone开发人员之间的工作流程。

该产品是在Plone 5上进行开发和测试的,但也可能与旧版本兼容。

该产品本身不执行任何与用户相关的操作!它不能作为Plone插件安装。它所做的是为开发人员提供一个API,以便将替代模板引擎集成到Plone中。

功能

该产品提供以下具有handlebars支持的视图组件

  • BrowserView

  • Plone模板

  • Tile

  • 持久Tile

由于portlets和viewlets对模板没有假设,并返回Renderer的render方法的全部内容,因此它们也得到支持。

示例

handlebars BrowserView

from collective.handlebars.browser.views import HandlebarsBrowserView

class HBSBrowserView(HandlebarsBrowserView):

    def get_contents(self):
        return {'msg': u'Hello World!'}

相应的configure.zcml

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    i18n_domain="mydomain">

  <browser:page
       name="carousel_view"
       for="*"
       class=".views.HBSBrowserView"
       template="helloworld.hbs"
       permission="zope2.View"
       />

handlebar Plone模板

from collective.handlebars.browser.views import HandlebarsPloneView

class CarouselView(HandlebarsPloneView):

    def get_contents(self):
        images = self.context.listFolderContents(
            contentFilter={'portal_type': ['Image', ]})

         slides = [{'title': safe_unicode(img.Title()),
                    'category': safe_unicode(img.Description()),
                    'link': img.remoteUrl,
                    'image': scale(img)} for img in images]

         return {'slides': slides, }}

相应的configure.zcml

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    i18n_domain="mydomain">

  <browser:page
       name="carousel_view"
       for="*"
       class=".views.CarouselView"
       template="carousel.hbs"
       permission="zope2.View"
       />

</configure>

handlebars portlet

from collective.handlebars.browser.views import HandlebarsMixin
from plone.app.multilingual.browser.selector import LanguageSelectorViewlet

class LanguageSwitcherRenderer(base.Renderer, HandlebarsMixin):
    """ Render a language switcher portlet
    """

    def get_contents(self):
        """ Get available and current site language
        :return: dictonary ()
        """
        viewlet = LanguageSelectorViewlet(self.context, self.request, self, None)
        viewlet.update()
        result = []
        for lang in viewlet.languages():
            result.append(
                {"lang": lang['code'].upper(),
                 "url": lang['url'],
                 "active": lang['selected'] and 'is_active' or ''})

        return {"languages": result}

    def render(self):
        return self.hbs_snippet(filename='langswitcher.hbs')

handlebars tile

class ContactPersonTile(HandlebarsTile):

    def get_contents(self):
        """ Get CMS data and put it in a JSON format
        """

        return {
            'fullname': u'George Miller',
            'phone': '+1 50 206 67 99',
            'email': 'george@example.com',
        }

或者持久handlebars tile

class ContactPersonTile(HandlebarsPersistentTile):

    def get_contents(self):
        """ Get CMS data and put it in a JSON format
        """

        return {
            'fullname': u'George Miller',
            'phone': '+1 50 206 67 99',
            'email': 'george@example.com',
        }

相应的configure.zcml

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="fhnw.contentwidgets">

  <include package="plone.app.mosaic" />

  <plone:tile
      name="myproduct.contactpersontile"
      title="ContactPerson"
      description="A card of a person"
      add_permission="cmf.ModifyPortalContent"
      class=".tiles.ContactPersonTile"
      for="*"
      permission="zope.Public"
      schema=".tiles.ContactPersonTile"
      template="contactperson.hbs"
  />
</configure>

文档

完整用户文档可以在“docs”文件夹中找到。

安装

通过将其添加到您的buildout中安装collective.handlebars

[buildout]

...

eggs =
    collective.handlebars

然后运行 bin/buildout

贡献

许可证

本项目遵循GPLv2许可协议。

贡献者

变更日志

1.5 (2021-08-28)

  • Python 3 / Plone 5.2 兼容性 [adrianschulz, tomgross]

  • 更新依赖项

  • 迁移至Github CI

  • 应用black格式化 [tomgross]

1.4.1 (2018-10-22)

  • 在包装器中添加div元素以支持仅提供文本的情况(否则plone.protect可能会失败) [tomgross]

1.4 (2018-09-10)

  • 包装拼图以与新版本的Mosaic一起使用 [tomgross]

1.3 (2018-04-26)

  • 为拼图设置html/body括号 [tomgross]

1.2 (2016-10-31)

  • 在响应中显式设置UTF-8编码 [tomgross]

1.1 (2016-10-28)

  • 添加对辅助函数的支持 [tomgross]

1.0 (2016-10-28)

  • 添加持久化拼图包装器 [tomgross]

  • 统一名称。现在为 HandlebarsTile [tomgross]

1.0rc1 (2016-08-29)

  • 添加模板注册 [tomgross]

  • 修复i18n翻译测试 [tomgross]

1.0b1 (2016-07-25)

  • 初始版本。 [tomgross]

项目详情


下载文件

下载适合您平台文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

collective.handlebars-1.5.tar.gz (21.8 kB 查看哈希值)

上传时间

由以下机构支持