Sha256: 2b0547e7549aefd07656fd9a8fae849806d3fc4e499d48827b99d517165bfc43

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'sugar-high/arguments'

module Cream::View
  module Role
    # for users WITH the given roles create a div area
    # with optional class given in options hash and render block
    # within this div  
    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   
    alias_method :area_for_role, :area_for_roles

    # for users WITHOUT the given roles create a div area
    # with optional class given in options hash and render block
    # within this div  
    def area_not_for_roles(*user_roles, &block)
      options = last_option(user_roles)
      not_for_roles user_roles do             
        clazz = options[:class] || 'special'
        area(clazz, &block)
      end
    end  
    alias_method :area_not_for_role, :area_not_for_roles
    
    def area(options=nil, &block)
      content = yield #with_output_buffer(&block)
      content_tag :div, content, options
    end    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cream-0.5.7 lib/cream/view/role_area.rb
cream-0.5.6 lib/cream/view/role_area.rb