API Reference

Caution

Unless otherwise explicitly documented, the objects referenced here are documented solely for exploration purposes and do not feature stable APIs for public use.

Interfaces

Interfaces for rendering Nikola with chameleon.

The most important interface in this package for themes is IPageKind and its various subclasses. These function similarly to IBrowserLayer in a Zope 3 application, in that they are applied to the request variable when a template is rendered, and more specific templates or macros can be registered for the request based on that layer. Each request will only have one such interface applied to it.

Similarly, the ICommentKind (with its subclasses ICommentKindNone and ICommentKindAllowed and its various system types markers) will be applied to the view variable.

interface nti.nikola_chameleon.interfaces.IArchiveIndexPageKind

Extends: nti.nikola_chameleon.interfaces.IIndexPageKind, nti.nikola_chameleon.interfaces.IArchivePageKind

When archives are indexes.

ARCHIVES_ARE_INDEXES = True

interface nti.nikola_chameleon.interfaces.IArchivePageKind

Extends: nti.nikola_chameleon.interfaces.IListPageKind

An archive page

interface nti.nikola_chameleon.interfaces.IAuthorPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

The page for listing an author

interface nti.nikola_chameleon.interfaces.IAuthorsPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

The page for listing authors

interface nti.nikola_chameleon.interfaces.IBookPageKind

Extends: nti.nikola_chameleon.interfaces.IStoryPageKind

A book page. Note that this doesn’t actually have its own pagekinds value, it’s specified by setting ‘template:book.tmpl’ in the post metadata.

interface nti.nikola_chameleon.interfaces.ICommentKind

The type of comments for a given view.

interface nti.nikola_chameleon.interfaces.ICommentKindAllowed

Comments are allowed on this view.

interface nti.nikola_chameleon.interfaces.ICommentKindDisqus

Extends: nti.nikola_chameleon.interfaces.ICommentKindAllowed

Use disqus comments.

interface nti.nikola_chameleon.interfaces.ICommentKindFacebook

Extends: nti.nikola_chameleon.interfaces.ICommentKindAllowed

Use Facebook comments.

interface nti.nikola_chameleon.interfaces.ICommentKindNone

No comments are allowed on this view.

interface nti.nikola_chameleon.interfaces.IGallery

A gallery object.

photo_array

List Photo array (contains dicts with image data: url, url_thumb, title, size{w, h})

folders

List of folders (path, title)

thumbnail_size

THUMBNAIL_SIZE setting

enable_comments

Whether comments are enabled.

crumbs
post

Optionally the post for this gallery

interface nti.nikola_chameleon.interfaces.IGalleryPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

A gallery page

interface nti.nikola_chameleon.interfaces.IHtmlBodyContentFooterViewletManager

Extends: zope.viewlet.interfaces.IViewletManager

A viewlet that operates within a footer in the main content of the body (after the main content).

interface nti.nikola_chameleon.interfaces.IHtmlBodyContentHeaderViewletManager

Extends: zope.viewlet.interfaces.IViewletManager

A viewlet that operates within a header in the main content of the body (before the main content).

interface nti.nikola_chameleon.interfaces.IHtmlBodyContentViewletManager

Extends: zope.viewlet.interfaces.IViewletManager

A viewlet that operates anywhere within the main content of the body.

interface nti.nikola_chameleon.interfaces.IHtmlBodyFooterViewletManager

Extends: zope.viewlet.interfaces.IViewletManager

A viewlet that operates after the main body content, near the very end of the html <body> tag.

interface nti.nikola_chameleon.interfaces.IHtmlHeadViewletManager

Extends: zope.viewlet.interfaces.IViewletManager

A viewlet manager meant to be used in the <head>.

interface nti.nikola_chameleon.interfaces.IIndexPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

An index page

interface nti.nikola_chameleon.interfaces.IListPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

A page that is a list

interface nti.nikola_chameleon.interfaces.IListing

A listing object.

Link to the source file

files

List of files

code

The formatted HTML code.

folders

List of folders

crumbs

Breadcrum list

interface nti.nikola_chameleon.interfaces.IListingPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

A listing page

interface nti.nikola_chameleon.interfaces.IMainIndexPageKind

Extends: nti.nikola_chameleon.interfaces.IIndexPageKind

The main index

interface nti.nikola_chameleon.interfaces.IMathJaxPost

Extends: nti.nikola_chameleon.interfaces.IPost, nti.nikola_chameleon.interfaces.INeedsMathJax

A post that uses MathJax.

interface nti.nikola_chameleon.interfaces.IMathJaxPostList

Extends: nti.nikola_chameleon.interfaces.IPostList, nti.nikola_chameleon.interfaces.INeedsMathJax

A list of posts at least one of which needs mathjax.

interface nti.nikola_chameleon.interfaces.INeedsMathJax

A context object that needs MathJax support to render.

interface nti.nikola_chameleon.interfaces.IPageKind

The type of page being rendered.

Specific types of pages will have a more specific interface.

This is similar to IBrowserLayer concept in Zope 3.

interface nti.nikola_chameleon.interfaces.IPagePageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

A page

interface nti.nikola_chameleon.interfaces.IPost

A post.

interface nti.nikola_chameleon.interfaces.IPostList

Extends: zope.interface.common.sequence.IReadSequence

A list of posts.

interface nti.nikola_chameleon.interfaces.IPostPage

Extends: nti.nikola_chameleon.interfaces.IPost, nti.nikola_chameleon.interfaces.IPageKind

A page being rendered for a post.

interface nti.nikola_chameleon.interfaces.IPostPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

A blog post

interface nti.nikola_chameleon.interfaces.IRootPage

The page that forms the root of the site, e.g., index.html.

The context takes this interface on when it specifies the custom metadata field nti-extra-page-kind as "root".

interface nti.nikola_chameleon.interfaces.ISlide

A slide page.

slides_content

A list of strings of image paths

carousel_id

The string id

interface nti.nikola_chameleon.interfaces.IStoryPageKind

Extends: nti.nikola_chameleon.interfaces.IPagePageKind

A story page. You must still manually opt-in to using the story template in the post metadata or site configuration.

interface nti.nikola_chameleon.interfaces.ITagPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

The page for listing a tag

interface nti.nikola_chameleon.interfaces.ITagsPageKind

Extends: nti.nikola_chameleon.interfaces.IPageKind

The page for listing tags

Templating

Templating support for Chameleon under Nikola.

class nti.nikola_chameleon.template.MessagesTranslate(messages)

Bases: object

Implements the translation function for Chameleon in terms of the messages object provided by Nikola.

The Nikola messages object is a dictionary from language to a dictionary of message ids to strings. Note that it doesn’t support domains or mapping substitutions (mappings are included in the msgid as a format string, but nikola itself is expected to do the formatting).

If it is called, it accepts the message id key as the first argument, and a ‘lang’ parameter as the optional second argument. If the lang is not given or is None, then it is defaulted to the “current language”.

New in version 0.0.1a2.

class nti.nikola_chameleon.template.NikolaPageFileTemplate(template_file, path=None, **kwargs)

Bases: z3c.pt.pagetemplate.ViewPageTemplateFile

ZPT file templates for use with Nikola.

This does a few things:

  1. Sets up the load expression to work.
  2. Restores the import and structure expression types.
  3. Provides a translate function based on Nikola’s messages dictionary that will enable Chameleon’s default I18N support.
builtins

Restores the loader needed for load expressions

render(target_language=None, **context)

Render template to string.

If providd, the encoding argument overrides the template default value.

Additional keyword arguments are passed as template variables.

In addition, some also have a special meaning:

translate

This keyword argument will override the default template translate function.

target_language

This will be used as the default argument to the translate function if no i18n:target value is provided.

If not provided, the translate function will need to negotiate a language based on the provided context.

class nti.nikola_chameleon.template.TemplateFactory(path, contentType, macro=None)

Bases: z3c.template.template.TemplateFactory

Adapters

Adapters for various object types.

class nti.nikola_chameleon.adapters.FormattedDatePathAdapter(context)

Bases: object

Lets us access the formatted date function in tales expressions.

post/formatted_date:webiso post/formatted_date:?date_format

New in version 0.0.1a2.

class nti.nikola_chameleon.adapters.MetaPathAdapter(context)

Bases: object

Lets us access the meta object in path expressions.

post/meta:link post/meta:keywords

Feeds

The Chameleon ZPT plugin for nikola.

class nti.nikola_chameleon.feeds.Feeds(context, request)

Bases: nti.nikola_chameleon.view.BaseView

Helpers for feeds.

feed_translations_head(classification=None, kind='index', feeds=True, other=True, rss_override=True, has_no_feeds=False)

Produce the links in the head.

class nti.nikola_chameleon.feeds.HTMLFeedLinkViewlet(context, request, view, manager)

Bases: zope.viewlet.viewlet.ViewletBase

A viewlet to render one or more feed links into html.

You must subclass this to set the name of the classification attribute to find in the request options dictionary in the classification_name attribute. This is usually done in ZCML:

<browser:viewlet
   name="feed_content_header"
   manager=".interfaces.IHtmlBodyContentHeaderViewletManager"
   class=".feeds.HTMLFeedLinkViewlet"
   layer=".interfaces.IAuthorPageKind"
   permission="zope.Public"
   weight="1"
   classification_name="author"
   />

Macros

Supporting code for z3c.macro.

class nti.nikola_chameleon.macro.NamedMacroView(context, request)

Bases: object

Provides a generic @@macros view for finding a z3c.macro registration on a context different than the current context.

The object that it was traversed from will become the context variable during executing of the macro. E.g., in metal:use-macro="post/@@macros/a_macro", the registered macro a_macro will be looked up with post as its context and will execute with post as its context variable.

Request

Request objects.

View

View objects.

These objects will typically provide chunks of functionality that are ugly to write and/or test in templates. They will be registered in ZCML against specific (context, request) pairs (as specific as needed). They (and their attributes, methods and templates) can then be easily accessed in a template by traversal: context/@@view_name/method.

class nti.nikola_chameleon.view.BaseView(context, request)

Bases: object

All views provide the context and request attributes.

class nti.nikola_chameleon.view.ConditionalViewletManager(context, request, view)

Bases: zope.viewlet.manager.ConditionalViewletManager

A viewlet manager that respects the weight and available attributes.

class nti.nikola_chameleon.view.PostCssKindView(context, request)

Bases: nti.nikola_chameleon.view.BaseView

For getting various strings useful in CSS.

New in version 0.0.1a3.

pagekind_class

Returns a class name suitable for use in CSS.

class nti.nikola_chameleon.view.PostTextView(context, request)

Bases: nti.nikola_chameleon.view.BaseView

For getting the text of a post, while respecting teasers.

New in version 0.0.1a2.

content

The full text or teaser text of the post, as appropriate, in an index.

content_kind

Either ‘summary’ or ‘content’. Intended to be used in CSS class names in indices.

embedded_content

The teaser for a post, stripped of html. Works regardless of index status.

preview

The string ‘post-preview’ if the content is a teaser.

teaser

The string ‘teaser’ if the content is a teaser in an index, otherwise None.

class nti.nikola_chameleon.view.View(context, request, templates)

Bases: nti.nikola_chameleon.view.BaseView

The default view when we begin rendering a template.

It may have “layers” applied to it to adjust the rendering conditions.

Plugin

The Chameleon ZPT plugin for nikola.

class nti.nikola_chameleon.plugin.ChameleonTemplates

Bases: nikola.plugin_categories.TemplateSystem

An implementation of the TemplateSystem plugin using Chameleon and zope.component.

get_deps(template_name)

Returns filenames which are dependencies for a template.

inject_directory(directory)

Injects the directory with the lowest priority in the template search mechanism.

render_template(template_name, output_name, context)

Renders template to a file using context.

This must save the data to output_name and return it so that the caller may do additional processing.

render_template_to_string(template, context)

Renders template to a string using context.

set_directories(directories, cache_folder)

Sets the list of folders where templates are located and cache.

template_deps(template_name)

Returns filenames which are dependencies for a template.

nti.nikola_chameleon.plugin.getViewTemplate(name, view, request, context)

Find the IContentTemplate of the given name for the given view, request and context (in that order).

If no such template is found, drop the context and try to find a template just for the view and request.

ZCML

ZCML directives.

New in version 0.0.1a2.

interface nti.nikola_chameleon.zcml.IViewletManagerDirective

Creates a new viewlet manager interface in the nti.nikola_chameleon.viewlets package.

id

The class name of the interface