Class: Governor::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/governor/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Plugin

Returns a new instance of Plugin.



4
5
6
7
8
9
10
# File 'lib/governor/plugin.rb', line 4

def initialize(name)
  @name = name
  @migrations = []
  @resources = {}
  @partials = {}
  @mimes = []
end

Instance Attribute Details

#migrationsObject (readonly)

Returns the value of attribute migrations.



3
4
5
# File 'lib/governor/plugin.rb', line 3

def migrations
  @migrations
end

#mimesObject (readonly)

Returns the value of attribute mimes.



3
4
5
# File 'lib/governor/plugin.rb', line 3

def mimes
  @mimes
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/governor/plugin.rb', line 3

def name
  @name
end

Returns the value of attribute navigation_hook.



3
4
5
# File 'lib/governor/plugin.rb', line 3

def navigation_hook
  @navigation_hook
end

#resourcesObject (readonly)

Returns the value of attribute resources.



3
4
5
# File 'lib/governor/plugin.rb', line 3

def resources
  @resources
end

#routesObject (readonly)

Returns the value of attribute routes.



3
4
5
# File 'lib/governor/plugin.rb', line 3

def routes
  @routes
end

Instance Method Details

#add_migration(path) ⇒ Object



12
13
14
# File 'lib/governor/plugin.rb', line 12

def add_migration(path)
  @migrations << path
end

#add_to_navigation(&block) ⇒ Object

Adds the given block to the Governor navigation header in GovernorApplicationHeader#governor_header.

Example:

plugin.add_to_navigation do
  concat(link_to("Rod's favorite movie?", 'http://www.imdb.com/title/tt0031679/'))
end

This would add a link to Rod’s favorite movie in the Governor navigation header. You’re responsible for wrapping any content you want included with concat().



117
118
119
# File 'lib/governor/plugin.rb', line 117

def add_to_navigation(&block)
  @navigation_hook = block
end

#include_in_controller(base) ⇒ Object

:nodoc:



57
58
59
# File 'lib/governor/plugin.rb', line 57

def include_in_controller(base) #:nodoc:
  instance_exec(base, &@controller_callback) if @controller_callback
end

#include_in_model(base) ⇒ Object

:nodoc:



53
54
55
# File 'lib/governor/plugin.rb', line 53

def include_in_model(base) #:nodoc:
  instance_exec(base, &@model_callback) if @model_callback
end

#partial_for(type) ⇒ Object

:nodoc:



49
50
51
# File 'lib/governor/plugin.rb', line 49

def partial_for(type) #:nodoc:
  @partials[type.to_sym]
end

#register_controller_callback(&block) ⇒ Object



81
82
83
# File 'lib/governor/plugin.rb', line 81

def register_controller_callback(&block)
  @controller_callback = block
end

#register_model_callback(&block) ⇒ Object

Evaluates the block in the scope of the model. This is the equivalent of creating a mixin, including it within your article class and implementing self.included.

Example:

thinking_sphinx = Governor::Plugin.new('thinking_sphinx')
thinking_sphinx.register_model_callback do |base|
  base.define_index do
    indexes title
    indexes description
    indexes post
    has created_at
    set_property :delta => true
  end
end


77
78
79
# File 'lib/governor/plugin.rb', line 77

def register_model_callback(&block)
  @model_callback = block
end

#register_partial(type, path) ⇒ Object

Specifies that this plugin will display a partial of the given type, at the given path. This path is relative to the views directory underneath your app; it’s expected that there will be a governor directory underneath views as well.

DOCUMENTME I need to indicate which types are supported.

Example:

comments.register_partial :after_article_whole, 'articles/comments'


45
46
47
# File 'lib/governor/plugin.rb', line 45

def register_partial(type, path)
  @partials[type.to_sym] = path
end

#responds_to(*mimes) ⇒ Object

Defines mime types that this plugin responds to. These mime types will be passed on to the controller.

Example:

plugin.responds_to :xml, :json

Specifies that this plugin can deliver a view for XML documents as well as JSON.

Any arguments that can be passed to respond_to in the controller can be passed here:

plugin.responds_to :atom, :only => :index

This specifies that the :index action responds to :atom, but no others.



101
102
103
# File 'lib/governor/plugin.rb', line 101

def responds_to(*mimes)
  @mimes << mimes
end

#set_routes(&block) ⇒ Object

Adds routes for articles. These can add member or collection routes to articles, or even nested resources.

Example:

comments = Governor::Plugin.new('comments')
comments.set_routes do
  resources :comments do
    member do
      put 'mark_spam', 'not_spam'
    end
  end
end


30
31
32
# File 'lib/governor/plugin.rb', line 30

def set_routes(&block)
  @routes = block
end