/
site_theme_extension.rb
64 lines (53 loc) · 2.15 KB
/
site_theme_extension.rb
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Uncomment this if you reference any of your controllers in activate
require_dependency 'application_controller'
# Going to need this to add regions to the extension interface
require 'ostruct'
class SiteThemeExtension < Radiant::Extension
version "1.0"
description "Custom themes for Radiant Sites"
url ""
define_routes do |map|
map.namespace :admin, :member => { :remove => :get } do |admin|
admin.resources :skins
end
map.activate_skin 'admin/skins/activate/:id', :controller => 'admin/skins', :action => 'activate'
map.deactivate_skin 'admin/skins/deactivate/:id', :controller => 'admin/skins', :action => 'deactivate'
map.search 'admin/skins/search', :controller => 'admin/skins', :action => 'search_skins'
end
def activate
admin.nav[:content] << admin.nav_item("Look & Feel", "/admin/skins")
admin.nav[:content].reverse!
UserActionObserver.instance.send :add_observer!, Skin
# Include custom tags
Page.send :include, SiteSkinTags
# This adds information to the Radiant interface.
Radiant::AdminUI.class_eval do
attr_accessor :skins
end
# initialize regions for skin (which was created above)
admin.skins = load_default_skin_regions
# Provide the ability to replace regions...
# Don't like how the regions are setup? Hack it without changing this extension's code
# Be forewarned, this allows you to completely change the UI
Radiant::AdminUI::RegionSet.class_eval do
def replace(region=nil, partial=nil)
raise ArgumentError, "You must specify a region and a partial" unless region and partial
self[region].replace([partial])
end
end
end
private
# Define the regions to be used in the views and partials
def load_default_skin_regions
returning OpenStruct.new do |skin|
skin.index = Radiant::AdminUI::RegionSet.new do |index|
index.main.concat %w{skin_list}
index.sidebar.concat %w{sidebar_boxes}
end
skin.search_skins = Radiant::AdminUI::RegionSet.new do |search_skins|
search_skins.main.concat %w{skin_list}
search_skins.sidebar.concat %w{sidebar_boxes}
end
end
end
end