Module: Hancock::RailsAdminGroupPatch

Defined in:
lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb

Class Method Summary collapse

Class Method Details

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



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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb', line 4

def hancock_cms_group(config, fields = {})
  return unless fields
  if fields.is_a?(Proc)
    return config.group :default, &fields
  end

  if fields.is_a?(Array)
    fields.reject { |f| f.empty? }.each do |_group|
      _name_default = :default
      _name = _group.delete(:name) || _group.delete(:group) || _name_default
      _active_default = _name == :default
      _group[:active] ||= _active_default
      _fields_default = {}
      _group_fields = (_group.delete(:fields) || _fields_default)

      if _group_fields.is_a?(Proc)
        config.group _name, &_group_fields

      else
        config.group _name do
          _group.each_pair do |name, val|

            # TODO: find more logical solution
            begin
              begin
                send name, val
              rescue
                send name
              end
            end
          end

          _group_fields.each_pair do |name, type|
            next if type == false
            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
    end

  else
    fields.each_pair do |name, type|
      next if type == false
      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