Radiant is a no-fluff, open source content management system designed for small teams.
Radiant is a no-fluff, open source content management system designed for small teams.






$ script/generate extension foo
$ script/generate extension foo
create vendor/extensions/foo/app/controllers
create vendor/extensions/foo/app/helpers
create vendor/extensions/foo/app/models
create vendor/extensions/foo/app/views
create vendor/extensions/foo/db/migrate
create vendor/extensions/foo/lib/tasks
create vendor/extensions/foo/test/functional
create vendor/extensions/foo/test/unit
create vendor/extensions/foo/README
create vendor/extensions/foo/Rakefile
create vendor/extensions/foo/foo_extension.rb
create vendor/extensions/foo/db/migrate/001_create_foo_extension_schema.rb
create vendor/extensions/foo/lib/tasks/foo_extension_tasks.rake
create vendor/extensions/foo/test/test_helper.rb
create vendor/extensions/foo/test/functional/foo_extension_test.rb
class FooExtension < Radiant::Extension version "1.0" description "Describe your extension here" url "http://foo.com" # define_routes do |map| # map.connect 'admin/foo/:action', :controller => 'admin/asset' # end def activate # admin.tabs.add "Foo", "/admin/foo", :after => "Layouts", :visibility => [:all] end def deactivate # admin.tabs.remove "Foo" end end
class FooExtension < Radiant::Extensionversion "1.0" description "Describe your extension here" url "http://foo.com"# define_routes do |map| # map.connect 'admin/foo/:action', :controller => 'admin/asset' # end def activate # admin.tabs.add "Foo", "/admin/foo", :after => "Layouts", :visibility => [:all] end def deactivate # admin.tabs.remove "Foo" end end
Extension "properties"
class FooExtension < Radiant::Extension version "1.0" description "Describe your extension here" url "http://foo.com"# define_routes do |map| # map.connect 'admin/foo/:action', :controller => 'admin/asset' # enddef activate # admin.tabs.add "Foo", "/admin/foo", :after => "Layouts", :visibility => [:all] end def deactivate # admin.tabs.remove "Foo" end end
Custom routes - just like routes.rb
class FooExtension < Radiant::Extension version "1.0" description "Describe your extension here" url "http://foo.com" # define_routes do |map| # map.connect 'admin/foo/:action', :controller => 'admin/asset' # enddef activate # admin.tabs.add "Foo", "/admin/foo", :after => "Layouts", :visibility => [:all] enddef deactivate # admin.tabs.remove "Foo" end end
Things to do on activation - add admin tabs, etc
class FooExtension < Radiant::Extension version "1.0" description "Describe your extension here" url "http://foo.com" # define_routes do |map| # map.connect 'admin/foo/:action', :controller => 'admin/asset' # end def activate # admin.tabs.add "Foo", "/admin/foo", :after => "Layouts", :visibility => [:all] enddef deactivate # admin.tabs.remove "Foo" endend
Things to do on deactivation - remove tabs, etc
*ActiveLDAP wouldn't work with Novell
class LdapSystem #... def search(options = {}) options.symbolize_keys!.reverse_merge! :base_dn => base_dn, :filter => "(objectClass=*)", :scope => LDAP::LDAP_SCOPE_SUBTREE, :attrs => ["dn", "givenName", "sn", "mail"], :sort => "sn" if options[:attrs].is_a? String options[:attrs] = options[:attrs].split(",").collect(&:strip) end connection.simple_bind(bind_user, bind_password) unless connection.bound?results = connection.search2(options[:base_dn], options[:scope], options[:filter], options[:attrs]) rescue []results.collect { |r| dearrayify(r) } end end
class LdapQuery < ActiveRecord::Base # ... def execute attrs = attributes.reject { |k,v| v.blank? or k.to_s == 'name' }.symbolize_keys LdapSystem.search(attrs) end # ... end
tag "directory:query" do |tag| name = tag.attr['name'] base, filter, attrs = tag.attr['base'], tag.attr['filter'], tag.attr['attrs'] if name and query = LdapQuery.find_by_name(name) tag.locals.results = query.execute tag.expand unless tag.locals.results.empty? elsif filter query = LdapQuery.new :base_dn => base, :filter => filter, :attrs => attrs tag.locals.results = query.execute tag.expand unless tag.locals.results.empty? else raise TagError, "Must specify at least a filter on directory queries." end end
<r:directory:query name="Everyone"> ... </r:directory:query>
truncate_and_strip_tags for Search# We need to process the page everytime, so that we can send the email! def cache? false end
Page#process method to handle POSTdef process(request, response) @request, @response = request, response @form_name, @form_error = nil, nil if request.post? @form_name = request.parameters[:mailer_name] @form_data = request.parameters[:mailer] @form_conf = config['mailers'][form_name].symbolize_keys || {} # If there are recipients defined, send email... if form_conf.has_key? :recipients if send_mail and form_conf.has_key? :redirect_to response.redirect( form_conf[:redirect_to] ) else super(request, response) end else @form_error = "Email wasn't sent because no recipients are defined" super(request, response) end else super(request, response) end end
tag "calendar" do |tag| name = tag.attr["name"].strip old_calendar = tag.locals.calendar old_events = tag.locals.events tag.locals.calendar = Calendar.find_by_name(name) if old_calendar old_events ||= old_calendar.events.find(:all, :order => "start_date asc, start_time asc") new_events = tag.locals.calendar.events.find(:all, :order => "start_date asc, start_time asc") tag.locals.events = new_events & old_events end tag.expand end
(Event habtm :calendars)
Page#find_by_url# Allows URLs to direct to the virtual course listing subpage def find_by_url(url, live = true, clean = false) url = clean_url(url) if clean if url =~ %r{#{self.url}(\w+)} prefix = $1 children.find_by_class_name 'SyllabiCoursesPage' else super end end
def render lazy_initialize_parser_and_context @context.globals.prefix = Prefix.find_by_prefix(get_prefix_from_url) super end private def request_uri request.request_uri unless request.nil? end def get_prefix_from_url $1 if request_uri =~ %r{#{parent.url}/?(\w+)/?$} end
See: http://radiantcms.org/blog/2006/11/24/how-to-write-time-sensitive-or-expiring-content/