车把
collective.handlebars的Python项目详细描述
这个包的目的是为plone提供handlebars.js支持。 它是一个开发人员插件,提供了 利用handlebars.js的browserview、portlet、viewlet和tile 模板而不是好未来。它可以用来优化工作流 在设计师和plone开发者之间。
该产品是用plone 5开发和测试的,但可能可以工作 旧版本也一样。
本产品不做任何与用户相关的事情! 它不能作为plone插件安装。它所做的是提供一个api 开发人员可以将另一个模板引擎集成到plone中。
功能
prodcut提供以下视图组件,并支持把手:
- BrowserView
- Plone template
- Tile
- Persistent Tile
因为Portlet和Viewlet在 模板化并返回 渲染器的渲染方法它们也受支持。
示例
一把棕色车把:
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" />
车把扑通声模板:
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>
车把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')
车把瓷砖:
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', }
或者一个持久的车把牌:
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”文件夹中找到。
安装
通过将collective.handlebars添加到您的构建:
[buildout] ... eggs = collective.handlebars
然后运行bin/buildout
贡献
1.4.1(2018-10-22)
- 将div元素添加到包装器以支持只提供文本的情况 (否则,plone.protect可能会失败) [汤姆格罗斯]
1.4(2018-09-10)
- 将瓷砖包裹起来,以便与新版本的马赛克配合使用 [汤姆格罗斯]
1.3(2018-04-26)
- 为平铺设置HTML/正文括号 [汤姆格罗斯]
1.2(2016-10-31)
- 显式设置响应中的utf-8编码 [汤姆格罗斯]
1.1(2016-10-28)
- 添加对助手的支持 [汤姆格罗斯]
1.0(2016-10-28)
- 添加永久磁贴包装 [汤姆格罗斯]
- 统一名字。现在是handlebarshile [汤姆格罗斯]
1.0RC1(2016-08-29)
- 为模板添加注册表 [汤姆格罗斯]
- 修复i18n翻译测试 [汤姆格罗斯]
1.0b1(2016-07-25)
- 初次发布。 [汤姆格罗斯]