Radiant Plugin System
Purpose
The Radiant Plugin System v2 (RPS2) allows developers to more easily and safely extend Radiant core features. Behaviors will be replaced by RPS2.
Classes
There are two new distinct classes:
class Radiant::Plugin::Base
...
end
class Page::Base < ActiveRecord::Base
...
module ControllerHelper
# render_*(), parse_*() and define_tag() methods
...
end
end
The class Page::Base replaces Behaviors. RPS2 features a cleaner solution to behaviors because it eliminates duplicate code design and it removes nearly all of previous delegation spaghetti code.
Example: My Handy Dandy Page Extension
class MyHandyDandyPage < Page::Base
...
module ControllerHelper
define_tag 'my_handy_dandy_partial_tag' do |tag|
render_to_string(:partial => "views/my_handy_dandy_partial_01")
end
def render_page
add_tags # make tags available to render methods in the parser
render(:text => 'render my handy dandy page') # render() method comes from ActionController::*Helper.
end
...
end
end
MyHandyDandyPage ships as part of a plugin called MyHandyDandyPlugin.
Plugin activates Page Extension
require 'my_handy_dandy_page'
class MyHandyDandyPlugin < Radiant::Plugin::Base
register "My Handy Dandy Plugin"
depends_on :your_plugin, :another_plugin
def activate
routes.my_route "my/route", :controller => "my_controller", :action => "my_action"
admin.tabs.add "My Handy Dandy Plugin", my_route_url
page_classes.activate "My Handy Dandy Page"
end
def deactivate
admin.tabs.remove "My Handy Dandy Plugin"
routes.remove "my/route"
page_classes.deactivate "My Handy Dandy Page"
end
end
RPS2 File Structure
plugins/
my_handy_dandy_plugin/
app/
controllers/
models/
my_handy_dandy_page.rb
views/
_my_handy_dandy_partial_01.rhtml
lib/
my_handy_dandy_plugin.rb
patches/ #monkey patches for Radiant or Rails
db/
migrations/
01_create_comments_table.rb
02_create_reviews_table.rb
...
schema.rb
vendor/
init.rb
setup.rb
init.rb
require "my_handy_dandy_plugin" MyHandyDandyPlugin.init
setup.rb
require "my_handy_dandy_plugin" MyHandyDandyPlugin.setup
Refactor Code
controllers/page_controller.rb snippet
class PageController < ApplicationController
def show_page
response.headers.delete('Cache-Control')
url = params[:url].to_s
if cache.response_cached?(url)
cache.update_response(url, response)
else
show_uncached_page(url)
cache.cache_response(url, response) if @page.cache? and live?
end
end
private
def show_uncache_page(url)
@page = find_page(url)
if @page.nil?
render :template => 'site/not_found', :status => 404
else
update_response
end
rescue Page::MissingRootPageError
redirect_to(:controller => 'admin/welcome')
end
def update_response
extend(@page.class::ControllerHelper)
render_page
end
end
Page Class
class Page < Page::Base
# match current <#Page> methods
end
OLD LINKS:
