Path: | README.rdoc |
Last Update: | Fri Dec 23 00:23:14 +0000 2016 |
Easily build timelines, much like GitHub‘s news feed.
TimelineFu requires you to have a TimelineEvent model. The simplest way is to use the generator.
$ script/generate timeline_fu && rake db:migrate exists db/migrate create db/migrate/20090333222034_create_timeline_events.rb create app/models/timeline_event.rb # Migration blabber...
Next step is to determine what generates an event in your various models.
class Post < ActiveRecord::Base #... belongs_to :author, :class_name => 'Person' fires :new_post, :on => :create, :actor => :author end
You can add ‘fires’ statements to as many models as you want on as many models as you want.
They are hooked for you after standard ActiveRecord events. In the previous example, it‘s an after_create on Posts.
You can supply a few parameters to fires, two of them are mandatory.
The rest all fit neatly in an options hash.
Here‘s another example:
class Comment < ActiveRecord::Base #... belongs_to :commenter, :class_name => 'Person' belongs_to :post fires :new_comment, :on => :create, :actor => :commenter, #implicit :subject => self, :secondary_subject => 'post', :if => lambda { |comment| comment.commenter != comment.post.author } end
The ActiveRecord event hook will automatically instantiate a TimelineEvent instance for you. It will receive the following parameters in create!
The generated model stores most of its info as polymorphic relationships.
class TimelineEvent < ActiveRecord::Base belongs_to :actor, :polymorphic => true belongs_to :subject, :polymorphic => true belongs_to :secondary_subject, :polymorphic => true end
To get your timeline you‘ll probably have to create your own finder SQL or scopes (if your situation is extremely simple).
TimelineFu is not currently providing anything to generate your timeline because different situations will have wildly different requirements. Like access control issues and actually just what crazy stuff you‘re cramming in that timeline.
We‘re not saying it can‘t be done, just that we haven‘t done it yet. Contributions are welcome :-)
timeline_fu can be used as a plugin:
$ script/plugin install git://github.com/giraffesoft/timeline_fu.git
or as a gem plugin:
config.gem "giraffesoft-timeline_fu", :lib => "timeline_fu", :source => "http://gems.github.com"
Copyright (c) 2008 James Golick, released under the MIT license