seancribbs / radiant-templates-extension

An extension for Radiant CMS to create page "templates" or "inner layouts" that constrain the structure and editing UI of a page.

This URL has Read+Write access

radiant-templates-extension / templates_extension.rb
100644 48 lines (45 sloc) 1.732 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Uncomment this if you reference any of your controllers in activate
begin
  require_dependency 'application_controller'
rescue MissingSourceFile
  require_dependency 'application'
end
class TemplatesExtension < Radiant::Extension
  version "1.3"
  description "Imposes structure on pages via content templates"
  url "http://github.com/seancribbs/radiant-templates-extension/tree/master"
 
  define_routes do |map|
    map.namespace :admin do |admin|
      admin.resources :templates, :member =>
                      { :move_higher => :post, :move_lower => :post,
                       :move_to_top => :post, :move_to_bottom => :post}
      admin.resources :part_types, :path_prefix => "/admin/templates"
    end
  end
 
  def activate
    begin
      FileSystem::MODELS << "PartType" << "Template"
    rescue NameError, LoadError
    end
    Page.class_eval do
      include Templates::Associations
      include Templates::Tags
      include Templates::PageExtensions
    end
    Admin::PagesController.class_eval do
      include Templates::ControllerExtensions
      helper Templates::Helper
    end
    admin.tabs.add "Templates", "/admin/templates", :before => "Layouts", :visibility => [:developer, :admin]
    # Admin UI customization
    admin.page.edit.add :extended_metadata, 'switch_templates'
    admin.page.edit.add :form, 'edit_template', :before => 'edit_page_parts'
    admin.page.edit.form.delete 'edit_page_parts'
    admin.page.index.add :bottom, 'index_add_child_popup'
    admin.page.index.add :node, 'type_column', :before => 'status_column'
    admin.page.index.add :sitemap_head, 'type_column_header', :before => 'status_column_header'
  end
 
  def deactivate
    admin.tabs.remove "Templates"
  end
end