lib/governor/plugin.rb in governor-0.2.1 vs lib/governor/plugin.rb in governor-0.2.2
- old
+ new
@@ -1,8 +1,8 @@
module Governor
class Plugin
- attr_reader :name, :migrations, :resources, :helpers
+ attr_reader :name, :migrations, :routes, :resources, :helpers
def initialize(name)
@name = name
@migrations = []
@helpers = []
@resources = {}
@@ -11,26 +11,26 @@
def add_migration(path)
@migrations << path
end
- # Adds a nested resource. Any options are passed directly to the router.
- # Any member or collection routes can be passed in as a block.
+ # Adds routes for articles. These can add member or collection routes to
+ # articles, or even nested resources.
#
# Example:
#
# comments = Governor::Plugin.new('comments')
- # comments.add_child_resource :comments do
- # member do
- # put 'mark_spam', 'not_spam'
+ # comments.set_routes do
+ # resources :comments do
+ # member do
+ # put 'mark_spam', 'not_spam'
+ # end
# end
# end
#
- def add_child_resource(name, options={}, &block)
- options[:block] = block if block_given?
- @resources[:child_resources] ||= {}
- @resources[:child_resources][name] = options
+ def set_routes(&block)
+ @routes = block
end
# 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
@@ -44,17 +44,11 @@
#
def register_partial(type, path)
@partials[type.to_sym] = path
end
- # Returns the path associated with the given partial type.
- #
- # Example:
- #
- # comments.partial_for(:after_article_whole) # => 'articles/comments'
- #
- def partial_for(type)
+ def partial_for(type) #:nodoc:
@partials[type.to_sym]
end
# Associates a helper for this plugin, to be included into the controller
# and view.
@@ -65,8 +59,32 @@
#
# comments.add_helper "GovernorCommentsHelper"
#
def add_helper(mod)
@helpers << mod
+ end
+
+ def include_in_model(base) #:nodoc:
+ instance_exec(base, &@model_callback) if @model_callback
+ end
+
+ # 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
+ def register_model_callback(&block)
+ @model_callback = block
end
end
end
\ No newline at end of file