Fork me on GitHub

virtual classes

An article by Gaspard Bucher

also referred to as “klass”

See also property and roles.

introduction

With Virtual Classes you can create your own kind of objects. For example, if you are a musician, you might want to create an “Album” object. If you are an architect you might want to create “Houses” and so on. Virtual classes behave like real classes: you can search for them, display them in fancy ways and create custom relations to other objects.

Creating a class

When logged in as admin, click on your username, then find “classes” in the menu on the left.
The page will show a table with the predefined classes.

classes_de

Editing classes in german

To add a new class, click on the icon that appears in the last line while hovering over the first column.

properties

This page allows you add properties (the virtual fields or columns) to your virtual classes.

roles

On the “classes” page you can also create and attach “roles” to the classes. For these roles you can then define a set of properties on the “properties” page. The role properties are then available for the class and all its decendents.

planning

Deciding whether using class properties for something, or creating nodes of a separate class and using link relations, makes a better model for your application may be done, based on the Indexing and Searching that you need.

fetching and classifying nodes

To render a comma separated list of all the houses in the current section:

<r:houses from='section' do='each' join=', ' do='link'/>

You can test if nodes are an instance of a virtual class or actually have at least one of a role’s properties (play this role), using kind_of?(RoleOrClassName) from rubyless, or a simple <r:RoleOrClassName?> block in zafu templates.