require_dependency 'application' class DefaultPagePartsExtension < Radiant::Extension version "0.2.1" description "With this extension you can create a page of DefaultPageParts type and specify the default parts of all its children." url "http://gravityblast.com/projects/radiant-page-utilities/" def activate DefaultPagePartsPage Admin::PageController.class_eval do def new @page = request.get? ? Page.new_with_defaults(config) : Page.new @page.slug = params[:slug] @page.breadcrumb = params[:breadcrumb] @page.parent = Page.find_by_id(params[:parent_id]) if settings_page = @page.ancestors.find{|p| p.class_name == 'DefaultPagePartsPage'} config = settings_page.config default_filter = config["filter"].to_s.camelize filter = ["SmartyPants", "Markdown", "Textile"].include?(default_filter) ? "#{default_filter}" : nil if config["parts"].is_a?(Array) && config["parts"].size > 0 @page.parts = [] config["parts"].each do |name| @page.parts << PagePart.new(:name => name, :filter_id => filter) end end end render :action => :edit if handle_new_or_edit_post end end end def deactivate end end