Developer FAQ

molpe edited this page Sep 13, 2010 · 18 revisions
  1. Add comments to your models
  2. Add ratings to your models
  3. Add your own observer
  4. Create ‘report abuse’ links
  5. Include my own javascripts in template header
  6. Run tests for a given plugin
  7. Fulfill dependencies to run test


h2. Add comments to your models

Tog uses acts_as_commentable, so, first make your model commentable:

class Conversatio::Post < ActiveRecord::Base
  acts_as_commentable
  ...

And now make the following include in your view (substitute @post for your commentable instance):

  <%= render :partial => "shared/comments", :locals => { :commentable => @post } %>

And, for the notification email, your model needs to tell who is it’s owner, so have to repond to “owner” (as a method or a relationship), returning an instance of User

   belongs_to :user
   ...
   def owner
        user
   end
   ...

Done. You have comments with permalinks, for registered and anonymous users, with antispam, denounced as abuse and much more.


h2. Add ratings to your models

Tog uses acts_as_rateable, so, first make your model rateable:

class Conversatio::Post < ActiveRecord::Base
  acts_as_rateable :average => true
  ...

And now make the following include in your view (substitute @post for your commentable instance):

  <%= render :partial => "shared/rating", :locals => { :rateable => @post } %>

Done. This implementation doesn’t make use of ajax or stars to so the current rating for a given object, but you can do it easily overwriting that view and tog_core’s Member::RatesController controller.


h2. Add your own observer

Observers are not supported by tog_plugins anymore, so you will need to declare them in your application as in any oher app.


h2. Create ‘report abuse’ links

tog_core comes with a helper method for easy links creation:

report_abuse_link(object, text, options)

Example:

<%= report_abuse_link(@comment, 'Report abuse', :class => 'abuse_link') -%>


h2. Include my own javascripts in template header

If one of your plugins uses an specific javascript, you can add it automatically to the template header using the following helper method in your view:

<% include_javascript "vault/admin" %>

Add the following in your template header to include all this files:

<%= inject_js %>

The same is valid for CSS using

   <% include_stylesheet "vault/styles" %>
   ...
   <%= inject_css %>


h2. Run tests for a given plugin

rake tog:plugins:test PLUGIN=plugin_name

For example:

rake tog:plugins:test PLUGIN=tog_conclave


h2. Fulfill dependencies to run test

You have to fulfill these three dependecies:

thoughtbot-factory_girl
thoughtbot-shoulda
mocha