1 class Radiant::AdminUI::RegionSet
2
3 def initialize
4 @regions = Hash.new do |h,k|
5 h[k] = []
6 end
7 yield self if block_given?
8 end
9
10 def [](region)
11 @regions[region.to_sym]
12 end
13
14 def add(region=nil, partial=nil, options={})
15 raise ArgumentError, "You must specify a region and a partial" unless region and partial
16 if options[:before]
17 index = @regions[region].empty? ? 0 : (@regions[region].index(options[:before]) || @regions[region].size)
18 self[region].insert(index, partial)
19 elsif options[:after]
20 index = @regions[region].empty? ? 0 : (@regions[region].index(options[:after]) || @regions[region].size - 1)
21 self[region].insert(index + 1, partial)
22 else
23 self[region] << partial
24 end
25 end
26
27 def method_missing(method, *args, &block)
28 if args.empty?
29 self[method]
30 else
31 super
32 end
33 end
34
35 en