How to Write an Extension (work in progress)
Since I need a calendar of events component for a project I am working on, I'll make it reusable for future projects. Use this "how to" as a reference to create your own extension.
I've gathered this information from my own investigation as well as the Radiant mailing list (starting from this post which is coincidentally associated with a Calendar extension). If you know of a better way to do something please correct my mistakes.
Step 1: Generate the Extension
Execute the following command in the root directory of your Radiant app.
ruby script/generate extension calendar
This will create an extension skeleton in ./vendor/extensions/calendar/ with familiar Rails folders (app, db, lib, test) and generated Ruby code.
Step 2: Edit the Extension class
Open calendar_extension.rb in the extension folder. It should contain something close to the following:
class CalendarExtension < Radiant::Extension
version "1.0"
description "Calendar"
url "http://calendar.com"
define_routes do |map|
#map.connect 'admin/calendar/:action', :controller => 'admin/calendar'
end
def activate
#admin.tabs.add "Calendar", "/admin/calendar", :after => "Layouts", :visibility => [:all]
end
def deactivate
#admin.tabs.remove "Calendar"
end
end
Uncomment the relevant code if you want this extension to have an associated tab in the Radiant Admin area.
If you want to have a page in your site that uses the same name as your extension, try using this in your define_routes function:
map.resources :testimonials, :path_prefix => "/admin"
Step 3: Create Models
There's probably an easier way to do this but to leverage the Rails model generator I generated my Models from the app root and copied them and all of their associated migrations, tests, etc to the extension folder.
NOTE: Avoid having a Model with the same name as your Extension - it may cause migration conflicts
