Grok framework

Description

Using Grok framework in Plone programming. Grok provides Dont-Repeat-Yourself API to create Zope 3 components easier.

Introduction

Grok is a project to give sane, easy to use, API to Zope 3 systems. It exists as standalone, but Plone compatible port five.grok is available for Plone 3.3 and onwards.

Benefits over using pure Zope 3 APIs

  • No ZCML files or XML sit-ups needed (except bootstrapping one configure.zcml file)
  • More things are automatic and less explicit hand-written code needed. E.g. template file and view class are automatically matched.
  • Less code generation

Grok will automatically scan all .py files in your product and run registration code in them. This way you can use Python decorators and magical classes to perform tasks which before needed to have hand written registration code.

More info

Using Grok in your package

To enabled grok'ing for your package

  • Top level configure.zcml must include grok namespace and five.grok directive. You do not need to put this directive subpackages. This directive scans your package source tree recursively for grok'ed files.
  • The package must be loaded using setup.py auto include, NOT using zcml = section in buildout.cfg. Otherwise templates are not loaded.
  • Optionally, add templates and static folders to your package root.
  • You still need to include subpackages for old-fashioned zcml configurations

Example:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:five="http://namespaces.zope.org/five"
    xmlns:cmf="http://namespaces.zope.org/cmf"
    xmlns:i18n="http://namespaces.zope.org/i18n"
    xmlns:grok="http://namespaces.zope.org/grok"
    i18n_domain="plonetheme.xxx">

  <include package="five.grok" />

  <five:registerPackage package="." initialize=".initialize" />

  <!-- Grok the package to initialise schema interfaces and content classes -->
  <grok:grok package="." />

  <include package=".browser" />

</configure>

More info

Tutorials

Steps

  • Add dependency in your setup.py
  • Edit buildout.cfg to include good known version set
  • Add grok ZCML directive to configure.zcml

Table Of Contents

About Plone

This is documentation for Plone®. Plone is a popular, open source, content management system written in Python programming language.




Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to Grok framework on GitHub.
  2. Press Fork and edit this file button.
  3. Edit file contents using GitHub's text editor in your web browserm
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on Github.

For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.