Module: Cream::View::Role

Defined in:
lib/cream/view/role_area.rb,
lib/cream/configure/after_init/role_config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.roles_availableObject



3
4
5
6
7
8
9
# File 'lib/cream/configure/after_init/role_config.rb', line 3

def self.roles_available
  begin
    return Cream::Role.available if defined? Cream::Role
  rescue
  end
  [:guest, :admin]
end

Instance Method Details

#area(options = nil, &block) ⇒ Object



33
34
35
36
# File 'lib/cream/view/role_area.rb', line 33

def area(options=nil, &block)
  content = yield #with_output_buffer(&block)
   :div, content, options
end

#area_for_roles(*user_roles, &block) ⇒ Object Also known as: area_for_role

for users WITH the given roles create a div area with optional class given in options hash and render block within this div



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cream/view/role_area.rb', line 8

def area_for_roles(*user_roles, &block)
  options = last_option(user_roles)

  return area(&block) if user_roles.empty?
  
  not_for_roles(user_roles, &block) if user_roles.first == false
  
  for_roles user_roles do
    area(options, &block)
  end
end

#area_not_for_roles(*user_roles, &block) ⇒ Object Also known as: area_not_for_role

for users WITHOUT the given roles create a div area with optional class given in options hash and render block within this div



24
25
26
27
28
29
30
# File 'lib/cream/view/role_area.rb', line 24

def area_not_for_roles(*user_roles, &block)
  options = last_option(user_roles)
  not_for_roles user_roles do             
    clazz = options[:class] || 'special'
    area(:class => clazz, &block)
  end
end