Module: Enjoy::RailsAdminGroupPatch

Defined in:
lib/enjoy/rails_admin_ext/group_patch.rb

Class Method Summary collapse

Class Method Details

.enjoy_cms_group(config, fields = {}) ⇒ Object



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
# File 'lib/enjoy/rails_admin_ext/group_patch.rb', line 3

def enjoy_cms_group(config, fields = {})
  return unless fields

  if fields.is_a?(Array)
    fields.each do |_group|
      config.group (_group[:name] || "") do
        active (_group[:active] || false)
        (_group[:fields] || {}).each_pair do |name, type|
          if type.blank?
            field name
          else
            if type.is_a?(Array)
              field name, type[0], &type[1]
            else
              field name, type
            end
          end
        end
      end
    end

  else
    fields.each_pair do |name, type|
      if type.nil?
        config.field name
      else
        if type.is_a?(Array)
          config.field name, type[0], &type[1]
        else
          config.field name, type
        end
      end
    end
  end
end