Description

dm-cutie-extras is a pack of extra stuff for dm-cutie and dm-cutie-ui.

Usage

require 'dm-core'
require 'dm-cutie'
require 'dm-cutie-extras'

DataMapper::Cutie::Extras.load :mysql_query_plan

DataMapper::Cutie.start(true)

Creating Views

If your hook includes a DataMapper model and you are writing a view, the view name should be the plural of your model name

Writing Tracker Hooks

See documentation @ http://github.com/coryodaniel/dm-cutie/

Adding Custom Columns to Views

The partial 'grid' takes three keys to create its local variables: :columns, :records, :adhoc_columns (discussed next)

Columns should be respond to #each, it will generally be a DataMapper PropertySet. Each element in columns will be used in a #send method call on each of the elements in records. That means instead of doing the standard partial :grid, :locals => { :columns => MyModel.properties, :records => @my_collection}

You can add any other columns you want as long as there is a method that a 'record' will respond to. For example, every object has a 'class' method, so you could do partial :grid, :locals => { :columns => MyModel.properties.to_a + [:class], :records => @my_collection }

This would cause the class name to be output in a column (pretty useless), but you can add any method you want to the class and simply add its name to the set of elements being passed to :columns

As an alternative method you can pass a column name to a proc in the :adhoc_columns parameter partial :grid, :locals => { :columns => MyModel.properties, :records => @my_collection, :adhoc_columns => { :my_cool_class_name => lambda{|my_record| my_record.class } } }

This would result in a column named 'my_cool_class_name' with a value of 'MyModel'. Obviously you can be more creative :)

Note: the proc should accept one parameter, the specific record from the collection of items passed to :records

IMPORTANT NOTE: Remember, if you are adding additional columns to the grid, make sure you pass the column names to the 'menu' partial if you want the ability to hide that column.