Class: Radiant::AdminUI::RegionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/radiant/admin_ui/region_set.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ RegionSet

Returns a new instance of RegionSet.

Yields:

  • (_self)

Yield Parameters:



3
4
5
6
7
8
# File 'lib/radiant/admin_ui/region_set.rb', line 3

def initialize
  @regions = Hash.new do |h,k|
    h[k] = []
  end
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/radiant/admin_ui/region_set.rb', line 27

def method_missing(method, *args, &block)
  if args.empty?
    self[method]
  else
    super
  end
end

Instance Method Details

#[](region) ⇒ Object



10
11
12
# File 'lib/radiant/admin_ui/region_set.rb', line 10

def [](region)
  @regions[region.to_sym]
end

#add(region = nil, partial = nil, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/radiant/admin_ui/region_set.rb', line 14

def add(region=nil, partial=nil, options={})
  raise ArgumentError, "You must specify a region and a partial" unless region and partial
  if options[:before]
    index = @regions[region].empty? ? 0 : (@regions[region].index(options[:before]) || @regions[region].size)
    self[region].insert(index, partial)
  elsif options[:after]
    index = @regions[region].empty? ? 0 : (@regions[region].index(options[:after]) || @regions[region].size - 1)
    self[region].insert(index + 1, partial)
  else
    self[region] << partial
  end
end