Module: PagesHelper

Included in:
Admin::LayoutsController, Admin::PagesController
Defined in:
app/helpers/pages_helper.rb

Overview

@File Name : pages_helper.rb

@Company Name              : Mindfire Solutions Private Limited
@Creator Name              : Vikram Kumar Mishra
@Date Created              : 2012-06-06
@Date Modified             : 2012-06-15
@Last Modification Details : default_page_parts method changed
@Purpose                   : To have view related logic for pages view mainly.

Instance Method Summary collapse

Instance Method Details

#arrange_page_part(page) ⇒ Object

Returns : Hash.

Parameters:

  • :

    Array(page array to be arranged)

Returns:

  • : Hash



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/helpers/pages_helper.rb', line 101

def arrange_page_part page

  # find the length of page_parts of current page
  part_length = page.page_parts.length

  # create an empty hash
  part_pages = Hash.new

  #loop through the length of page_part
  for i in 0..part_length-1

    #find each page_part array and assign it in a variable
    part = page.page_parts[i]

    #assign page_part array to hash
    part_pages[part.title] = part

  end # end loop

  # return hash
  part_pages

end

#build_page_part(index) ⇒ Object

Returns : Object.

Parameters:

  • :

    Integer(part_index of page part)

Returns:

  • : Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/pages_helper.rb', line 69

def build_page_part index

  # create a PagePart object and assign it to a variable
  page = PagePart.new

  #make the page part form
  builder = ActionView::Helpers::FormBuilder.new( "page[page_parts_attributes][#{index}]", page, self, {}, proc {})

  #return form object
  return builder

end

#build_page_part_page(index) ⇒ Object

Returns : Object.

Parameters:

  • :

    Integer(part_index of page part)

Returns:

  • : Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/helpers/pages_helper.rb', line 85

def build_page_part_page index

  # create a PagePart object and assign it to a variable
  page = PagePartsPage.new

  #make the page part pages form
  builder = ActionView::Helpers::FormBuilder.new( "page[page_parts_pages_attributes][#{index}]", page, self, {}, proc {})

  #return form object
  return builder

end

#deleteable?(page) ⇒ Boolean

Returns : boolean.

Returns:

  • (Boolean)

    : boolean



46
47
48
49
50
# File 'app/helpers/pages_helper.rb', line 46

def deleteable?(page)

  return page.deletable?

end

#get_fragments(title) ⇒ Object

Returns : Array.

Parameters:

  • :

    Integer

Returns:

  • : Array



55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/pages_helper.rb', line 55

def get_fragments title

   if title != "main body"

     # get page body fragment with title
     part = PagePart.find_page_parts_with_title(title)

   end

end

#layout_name(count) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/pages_helper.rb', line 18

def layout_name count

  # using case statement to decide layout name
  case count

    when 2

      return "two-column"

    when 3

      return "three-column"

    when 1

      return "one-column"

    else

      return "default"

  end # end case statement

end

#layout_partsObject

Returns : Hash.

Parameters:

  • :

    None

Returns:

  • : Hash



128
129
130
131
132
133
134
# File 'app/helpers/pages_helper.rb', line 128

def layout_parts

  layout_parts = ["header","footer","left","right","main"]

  layout_parts

end