Module: ActiveAdmin::Cms::Recipes::SectionHelper::SectionContainer

Included in:
ActiveAdmin::Cms::Recipe, ActiveAdmin::Cms::Recipe::Section
Defined in:
lib/active_admin/cms.rb,
lib/active_admin/cms/recipes/section_helper.rb

Defined Under Namespace

Classes: Ingredient, Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 15

def method_missing(method, *args, &block)
  
  begin
    klass = "ActiveAdmin::Cms::ContentTypes::#{method.to_s.camelcase}".constantize
  rescue NameError
  end

  begin
    klass = "::ContentTypes::#{method.to_s.camelcase}".constantize
  rescue NameError
  end

  if klass && klass.new.kind_of?(ActiveAdmin::Cms::ContentType)
    args[2] = args[1]
    args[1] = klass
    ingredient *args
  else
    super
  end
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



13
14
15
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 13

def parent
  @parent
end

Instance Method Details

#add_fields_to(formtastic_form) ⇒ Object

Adds formatastic fields to the specified form



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 37

def add_fields_to(formtastic_form)
    fields = {}
    formtastic_form.inputs admin_fieldset_title do
      ingredients.each do |i_id, i|
        page = formtastic_form.object
        content = page.content_for i.content_key
        #debugger
        fields[i.content_key] = formtastic_form.fields_for(content) do |i_form|     
            i_form.input :text
        end
        #i.add_fields_to(formtastic_form) if i.kind_of? ActiveAdmin::Cms::Recipe::Ingredient
      end
    end
    sections.each do |s_id, s|
      fields[s_id] = s.add_fields_to(formtastic_form) if s.kind_of? ActiveAdmin::Cms::Recipe::Section
    end
  
  #debugger
  
  formtastic_form.inputs
  
end

#admin_fieldset_titleObject



60
61
62
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 60

def admin_fieldset_title
  section_id.to_s.humanize
end

#ingredient(ingredient_id, type, opts = {}) ⇒ Object



64
65
66
67
68
69
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 64

def ingredient(ingredient_id, type, opts={})
  @ingredients ||= {}
  @ingredients[ingredient_id] = Ingredient.new(ingredient_id, type, opts)
  @ingredients[ingredient_id].section = self
  @ingredients[ingredient_id]
end

#ingredientsObject



71
72
73
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 71

def ingredients
  @ingredients ||= {}
end

#section(section_id, opts = {}, &block) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 75

def section(section_id, opts={}, &block)
  
  s = Section.new(section_id, opts, &block)
  @sections ||= {}
  @sections[section_id] = s
  s
end

#section_idObject



87
88
89
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 87

def section_id
  self.id
end

#section_keyObject



91
92
93
94
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 91

def section_key
  return "#{@parent.section_key}:#{section_id.to_s}" if @parent
  section_id.to_s
end

#sectionsObject



83
84
85
# File 'lib/active_admin/cms/recipes/section_helper.rb', line 83

def sections
  @sections ||= {}
end