mcms_pages 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/app/assets/images/layouts/one-column.png +0 -0
- data/app/assets/images/layouts/three-column.png +0 -0
- data/app/assets/images/layouts/two-column-with-left.png +0 -0
- data/app/assets/images/layouts/two-column-with-right.png +0 -0
- data/app/assets/images/mcms_pages/9.jpg +0 -0
- data/app/assets/images/mcms_pages/background.jpg +0 -0
- data/app/assets/images/mcms_pages/bamboo_love.jpg +0 -0
- data/app/assets/images/mcms_pages/branch-end.gif +0 -0
- data/app/assets/images/mcms_pages/branch-start.gif +0 -0
- data/app/assets/images/mcms_pages/branch.gif +0 -0
- data/app/assets/images/mcms_pages/content_bottom.jpg +0 -0
- data/app/assets/images/mcms_pages/icons/accept.png +0 -0
- data/app/assets/images/mcms_pages/icons/add.png +0 -0
- data/app/assets/images/mcms_pages/icons/ajax-loader.gif +0 -0
- data/app/assets/images/mcms_pages/icons/application_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/application_go.png +0 -0
- data/app/assets/images/mcms_pages/icons/arrow_left.png +0 -0
- data/app/assets/images/mcms_pages/icons/arrow_switch.png +0 -0
- data/app/assets/images/mcms_pages/icons/arrow_up.png +0 -0
- data/app/assets/images/mcms_pages/icons/bin.png +0 -0
- data/app/assets/images/mcms_pages/icons/bin_closed.png +0 -0
- data/app/assets/images/mcms_pages/icons/cancel.png +0 -0
- data/app/assets/images/mcms_pages/icons/cog_add.png +0 -0
- data/app/assets/images/mcms_pages/icons/cog_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/cross.png +0 -0
- data/app/assets/images/mcms_pages/icons/delete.png +0 -0
- data/app/assets/images/mcms_pages/icons/doc.png +0 -0
- data/app/assets/images/mcms_pages/icons/down.gif +0 -0
- data/app/assets/images/mcms_pages/icons/edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/email.png +0 -0
- data/app/assets/images/mcms_pages/icons/email_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/email_go.png +0 -0
- data/app/assets/images/mcms_pages/icons/email_open.png +0 -0
- data/app/assets/images/mcms_pages/icons/eye.png +0 -0
- data/app/assets/images/mcms_pages/icons/folder.png +0 -0
- data/app/assets/images/mcms_pages/icons/folder_open.png +0 -0
- data/app/assets/images/mcms_pages/icons/folder_page_white.png +0 -0
- data/app/assets/images/mcms_pages/icons/image_add.png +0 -0
- data/app/assets/images/mcms_pages/icons/image_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/img.png +0 -0
- data/app/assets/images/mcms_pages/icons/information.png +0 -0
- data/app/assets/images/mcms_pages/icons/layout_add.png +0 -0
- data/app/assets/images/mcms_pages/icons/layout_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/music.png +0 -0
- data/app/assets/images/mcms_pages/icons/page.png +0 -0
- data/app/assets/images/mcms_pages/icons/page_add.png +0 -0
- data/app/assets/images/mcms_pages/icons/page_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/page_white_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/page_white_gear.png +0 -0
- data/app/assets/images/mcms_pages/icons/page_white_put.png +0 -0
- data/app/assets/images/mcms_pages/icons/pdf.png +0 -0
- data/app/assets/images/mcms_pages/icons/ppt.png +0 -0
- data/app/assets/images/mcms_pages/icons/star.png +0 -0
- data/app/assets/images/mcms_pages/icons/tick.png +0 -0
- data/app/assets/images/mcms_pages/icons/up.gif +0 -0
- data/app/assets/images/mcms_pages/icons/user_add.png +0 -0
- data/app/assets/images/mcms_pages/icons/user_comment.png +0 -0
- data/app/assets/images/mcms_pages/icons/user_edit.png +0 -0
- data/app/assets/images/mcms_pages/icons/xls.png +0 -0
- data/app/assets/images/mcms_pages/icons/zip.png +0 -0
- data/app/assets/images/mcms_pages/icons/zoom.png +0 -0
- data/app/assets/images/mcms_pages/tab_off.jpg +0 -0
- data/app/assets/images/mcms_pages/tab_on.jpg +0 -0
- data/app/assets/javascripts/menuPage.js +45 -0
- data/app/assets/javascripts/pageFormAdmin.js +192 -0
- data/app/assets/stylesheets/mcms_pages/layout.css.scss +16 -0
- data/app/assets/stylesheets/mcms_pages/page_styles.css +95 -0
- data/app/assets/stylesheets/mcms_pages/pages.css.scss +172 -0
- data/app/controllers/admin/layouts_controller.rb +51 -0
- data/app/controllers/admin/pages_controller.rb +303 -0
- data/app/controllers/admin_controller.rb +22 -0
- data/app/controllers/application_controller.rb +20 -0
- data/app/controllers/pages_controller.rb +151 -0
- data/app/helpers/pages_helper.rb +118 -0
- data/app/models/ckeditor/asset.rb +8 -0
- data/app/models/ckeditor/attachment_file.rb +13 -0
- data/app/models/ckeditor/picture.rb +14 -0
- data/app/models/layout.rb +64 -0
- data/app/models/page.rb +152 -0
- data/app/models/page_part.rb +99 -0
- data/app/models/page_parts_page.rb +52 -0
- data/app/views/mcms_pages/admin/layouts/index.html.erb +54 -0
- data/app/views/mcms_pages/admin/pages/_action.html.erb +19 -0
- data/app/views/mcms_pages/admin/pages/_error_messages.html.erb +42 -0
- data/app/views/mcms_pages/admin/pages/_form.html.erb +90 -0
- data/app/views/mcms_pages/admin/pages/_form.js.erb +55 -0
- data/app/views/mcms_pages/admin/pages/_page.html.erb +63 -0
- data/app/views/mcms_pages/admin/pages/_page_part_edit_form.html.erb +140 -0
- data/app/views/mcms_pages/admin/pages/_page_part_form.html.erb +133 -0
- data/app/views/mcms_pages/admin/pages/_page_part_form_field.html.erb +21 -0
- data/app/views/mcms_pages/admin/pages/_page_part_page_form_field.html.erb +39 -0
- data/app/views/mcms_pages/admin/pages/add_page_part.js.erb +25 -0
- data/app/views/mcms_pages/admin/pages/edit.html.erb +15 -0
- data/app/views/mcms_pages/admin/pages/find_child.html.erb +15 -0
- data/app/views/mcms_pages/admin/pages/index.html.erb +26 -0
- data/app/views/mcms_pages/admin/pages/new.html.erb +15 -0
- data/app/views/mcms_pages/layouts/_footer.html.erb +16 -0
- data/app/views/mcms_pages/layouts/_header.html.erb +16 -0
- data/app/views/mcms_pages/layouts/_javascript.html.erb +22 -0
- data/app/views/mcms_pages/layouts/_stylesheets.html.erb +23 -0
- data/app/views/mcms_pages/layouts/mcms_layout.html.erb +39 -0
- data/app/views/mcms_pages/pages/_left_side_body.html.erb +16 -0
- data/app/views/mcms_pages/pages/_main_body.html.erb +16 -0
- data/app/views/mcms_pages/pages/_menu.html.erb +18 -0
- data/app/views/mcms_pages/pages/_menubar.html.erb +24 -0
- data/app/views/mcms_pages/pages/_one_column_layout.html.erb +14 -0
- data/app/views/mcms_pages/pages/_right_side_body.html.erb +16 -0
- data/app/views/mcms_pages/pages/_three_column_layout.html.erb +20 -0
- data/app/views/mcms_pages/pages/_two_column_layout.html.erb +27 -0
- data/app/views/mcms_pages/pages/home.html.erb +26 -0
- data/app/views/mcms_pages/pages/show.html.erb +34 -0
- data/config/routes.rb +57 -0
- data/db/migrate/20120605100629_create_pages.rb +17 -0
- data/db/migrate/20120605100650_create_page_parts.rb +10 -0
- data/db/migrate/20120606150655_create_mcms_assets.rb +26 -0
- data/db/migrate/20120606150656_add_title_position_to_page_parts.rb +5 -0
- data/db/migrate/20120609055514_add_parent_id_to_pages.rb +5 -0
- data/db/migrate/20120612054659_add_lft_rgt_to_mcms_pages.rb +6 -0
- data/db/migrate/20120614125619_create_layouts.rb +16 -0
- data/db/migrate/20120614131633_add_layout_id_to_mcms_pages.rb +5 -0
- data/db/migrate/20120614134343_add_foreign_key_to_page.rb +6 -0
- data/db/migrate/20120618060815_drop_column_permalink_from_mcms_pages.rb +10 -0
- data/db/migrate/20120618102226_add_slug_to_mcms_pages.rb +6 -0
- data/db/migrate/20120625063039_create_page_associations.rb +14 -0
- data/db/migrate/20120625112225_add_header_footer_to_mcms_layouts.rb +6 -0
- data/db/seeds.rb +175 -0
- data/lib/generators/mcms_pages/USAGE +8 -0
- data/lib/generators/mcms_pages/assets_generator.rb +79 -0
- data/lib/generators/mcms_pages/mcms_pages_generator.rb +101 -0
- data/lib/generators/mcms_pages/templates/asset_manager.rb +160 -0
- data/lib/generators/mcms_pages/templates/ckeditor.rb +18 -0
- data/lib/generators/mcms_pages/views_generator.rb +79 -0
- data/lib/mcms_pages/engine.rb +13 -0
- data/lib/mcms_pages/version.rb +3 -0
- data/lib/mcms_pages.rb +7 -0
- data/lib/tasks/mcms_pages_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/mcms_pages_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +360 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
@File Name : pages_helper.rb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-06-06
|
|
7
|
+
@Date Modified : 2012-06-15
|
|
8
|
+
@Last Modification Details : default_page_parts method changed
|
|
9
|
+
@Purpose : To have view related logic for pages view mainly.
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module PagesHelper
|
|
14
|
+
|
|
15
|
+
# @Parameters : integer(column count of a layout)
|
|
16
|
+
# @Return : Array
|
|
17
|
+
# @purpose : To give layout a name on the basis of parameter
|
|
18
|
+
def layout_name count
|
|
19
|
+
|
|
20
|
+
# using case statement to decide layout name
|
|
21
|
+
case count
|
|
22
|
+
|
|
23
|
+
when 2
|
|
24
|
+
|
|
25
|
+
return "two_column_layout"
|
|
26
|
+
|
|
27
|
+
when 3
|
|
28
|
+
|
|
29
|
+
return "three_column_layout"
|
|
30
|
+
|
|
31
|
+
when 1
|
|
32
|
+
|
|
33
|
+
return "one_column_layout"
|
|
34
|
+
|
|
35
|
+
else
|
|
36
|
+
|
|
37
|
+
return "default_layout"
|
|
38
|
+
|
|
39
|
+
end # end case statement
|
|
40
|
+
|
|
41
|
+
end #end method
|
|
42
|
+
|
|
43
|
+
# @params : none
|
|
44
|
+
# @return : boolean
|
|
45
|
+
# @purpose : To find
|
|
46
|
+
def deleteable?(page)
|
|
47
|
+
|
|
48
|
+
return page.deletable?
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# @param : Integer
|
|
54
|
+
# @return : Array
|
|
55
|
+
# @purpose : To find page parts according to param
|
|
56
|
+
def get_fragments(part, title)
|
|
57
|
+
|
|
58
|
+
#using case statement to get fragments
|
|
59
|
+
case part
|
|
60
|
+
|
|
61
|
+
when 0
|
|
62
|
+
|
|
63
|
+
if title == "header"
|
|
64
|
+
|
|
65
|
+
# get header fragment
|
|
66
|
+
part = PagePart.find_page_parts_with_title_header
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
when 1
|
|
71
|
+
|
|
72
|
+
# get footer fragment
|
|
73
|
+
part = PagePart.find_page_parts_with_title_footer
|
|
74
|
+
|
|
75
|
+
when 2
|
|
76
|
+
|
|
77
|
+
if title == "left body"
|
|
78
|
+
|
|
79
|
+
# get left body fragment
|
|
80
|
+
part = PagePart.find_page_parts_with_title_left_body
|
|
81
|
+
|
|
82
|
+
elsif title == "right body"
|
|
83
|
+
|
|
84
|
+
# get right body fragment
|
|
85
|
+
part = PagePart.find_page_parts_with_title_right_body
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
when 3
|
|
90
|
+
|
|
91
|
+
if title == "right body"
|
|
92
|
+
|
|
93
|
+
# get right body fragment
|
|
94
|
+
part = PagePart.find_page_parts_with_title_right_body
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end # end case
|
|
99
|
+
|
|
100
|
+
end # end method
|
|
101
|
+
|
|
102
|
+
# @param : Integer(part_index of page part)
|
|
103
|
+
# @return : Object
|
|
104
|
+
# @purpose : To build a form object for dynamic creating the page part
|
|
105
|
+
def build_page_part index
|
|
106
|
+
|
|
107
|
+
# create a PagePart object and assign it to a variable
|
|
108
|
+
page = PagePart.new
|
|
109
|
+
|
|
110
|
+
#make the page part form
|
|
111
|
+
builder = ActionView::Helpers::FormBuilder.new( "page[page_parts_attributes][#{index}]", page, self, {}, proc {})
|
|
112
|
+
|
|
113
|
+
#return form object
|
|
114
|
+
return builder
|
|
115
|
+
|
|
116
|
+
end # end method
|
|
117
|
+
|
|
118
|
+
end # end module
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Ckeditor::AttachmentFile < Ckeditor::Asset
|
|
2
|
+
has_attached_file :data,
|
|
3
|
+
:url => "/ckeditor_assets/attachments/:id/:filename",
|
|
4
|
+
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
|
|
5
|
+
|
|
6
|
+
validates_attachment_size :data, :less_than => 100.megabytes
|
|
7
|
+
validates_attachment_presence :data
|
|
8
|
+
|
|
9
|
+
def url_thumb
|
|
10
|
+
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class Ckeditor::Picture < Ckeditor::Asset
|
|
2
|
+
has_attached_file :data,
|
|
3
|
+
:url => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
|
|
4
|
+
:path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
|
|
5
|
+
:styles => { :content => '800>', :thumb => '118x100#' }
|
|
6
|
+
|
|
7
|
+
validates_attachment_size :data, :less_than => 2.megabytes
|
|
8
|
+
validates_attachment_presence :data
|
|
9
|
+
|
|
10
|
+
def url_content
|
|
11
|
+
url(:content)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
@File Name : layout.rb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-06-04
|
|
7
|
+
@Date Modified : 2012-06-15
|
|
8
|
+
@Last Modification Details :
|
|
9
|
+
@Purpose : To deal with database table "mcms_layouts" and all operations related to that table mainly.
|
|
10
|
+
It may deal with other tables and DB related operations.
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
#defining model class to interact with database. It inherits the rails's base class ActiveRecord::Base
|
|
14
|
+
class Layout < ActiveRecord::Base
|
|
15
|
+
|
|
16
|
+
#By default it access the table named "pages",
|
|
17
|
+
#so explicitly setting the table name to access required table
|
|
18
|
+
self.table_name = "mcms_layouts"
|
|
19
|
+
|
|
20
|
+
#definig the list of accessible attributes as required by rails
|
|
21
|
+
attr_accessible :column_count, :left, :main, :name, :right, :header, :footer
|
|
22
|
+
|
|
23
|
+
#Associating table "mcms_pages" with table "mcms_page_parts" using has_many relation
|
|
24
|
+
has_many :pages,
|
|
25
|
+
:foreign_key => :layout_id,
|
|
26
|
+
:class_name => 'Page',
|
|
27
|
+
:inverse_of => :layout,
|
|
28
|
+
:dependent => :destroy
|
|
29
|
+
|
|
30
|
+
# @param : None
|
|
31
|
+
# @return : Array
|
|
32
|
+
# @purpose : To find all layouts
|
|
33
|
+
def self.find_all_layouts
|
|
34
|
+
|
|
35
|
+
# finding all layouts from the DB and return the array
|
|
36
|
+
return self.select("id, name");
|
|
37
|
+
|
|
38
|
+
end # end method
|
|
39
|
+
|
|
40
|
+
# @param : integer(layout_id)
|
|
41
|
+
# @return : Array
|
|
42
|
+
# @purpose : To find the page parts in given layout
|
|
43
|
+
def self.find_page_parts layout_id
|
|
44
|
+
|
|
45
|
+
#initializing an array with some default value
|
|
46
|
+
page_part_array = []
|
|
47
|
+
|
|
48
|
+
# finding the layout with given id
|
|
49
|
+
layout = self.find_by_id(layout_id)
|
|
50
|
+
|
|
51
|
+
# check and include page part in page part array if page part value is
|
|
52
|
+
# true in DB
|
|
53
|
+
page_part_array << "header" if layout["header"]
|
|
54
|
+
page_part_array << "footer" if layout["footer"]
|
|
55
|
+
page_part_array << "left body" if layout["left"]
|
|
56
|
+
page_part_array << "right body" if layout["right"]
|
|
57
|
+
page_part_array << "main body" if layout["main"]
|
|
58
|
+
|
|
59
|
+
# return the array
|
|
60
|
+
return page_part_array
|
|
61
|
+
|
|
62
|
+
end # end method
|
|
63
|
+
|
|
64
|
+
end # end class
|
data/app/models/page.rb
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
@File Name : page.rb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-06-05
|
|
7
|
+
@Date Modified : 2012-06-15
|
|
8
|
+
@Last Modification Details : belongs_to layout added
|
|
9
|
+
@Purpose : To deal with database table "mcms_pages" and all operations related to that table mainly.
|
|
10
|
+
It may deal with other tables and DB related operations.
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
require 'friendly_id'
|
|
14
|
+
|
|
15
|
+
#defining model class to interact with database. It inherits the rails's base class ActiveRecord::Base
|
|
16
|
+
class Page < ActiveRecord::Base
|
|
17
|
+
|
|
18
|
+
# extending gem friendly_id
|
|
19
|
+
extend FriendlyId
|
|
20
|
+
|
|
21
|
+
# using title for custom url
|
|
22
|
+
friendly_id :title, use: :slugged
|
|
23
|
+
|
|
24
|
+
#By default it access the table named "pages",
|
|
25
|
+
#so explicitly setting the table name to access required table
|
|
26
|
+
self.table_name = "mcms_pages"
|
|
27
|
+
|
|
28
|
+
#definig the list of accessible attributes as required by rails
|
|
29
|
+
attr_accessible :link_url, :published, :show_in_menu, :title, :page_parts_attributes, :page_parts_pages_attributes,
|
|
30
|
+
:parent_id, :layout_id, :slug
|
|
31
|
+
|
|
32
|
+
#include rails standard validation for title
|
|
33
|
+
validates :title, :presence => true, :uniqueness => true
|
|
34
|
+
|
|
35
|
+
# Nested pages, i.e. page underneath another page
|
|
36
|
+
#acts_as_nested_set :dependent => :destroy
|
|
37
|
+
|
|
38
|
+
#Associating table "mcms_pages" with table "mcms_page_parts" using has_many relation
|
|
39
|
+
# has_many :page_parts,
|
|
40
|
+
# :foreign_key => :page_id,
|
|
41
|
+
# :class_name => 'PagePart',
|
|
42
|
+
# :inverse_of => :page,
|
|
43
|
+
# :dependent => :destroy
|
|
44
|
+
|
|
45
|
+
#defining has_many :through relationship
|
|
46
|
+
has_many :page_parts_pages, :class_name => 'PagePartsPage'
|
|
47
|
+
|
|
48
|
+
#defining has_many relation of page_parts to pages through page_part_pages
|
|
49
|
+
has_many :page_parts, :through => :page_parts_pages
|
|
50
|
+
|
|
51
|
+
# Associating table mcms_pages to itself. That is self referential has_many relationship using the key parent id
|
|
52
|
+
# Hence a page can have many pages
|
|
53
|
+
has_many :children,
|
|
54
|
+
:class_name => "Page",
|
|
55
|
+
:foreign_key => :parent_id,
|
|
56
|
+
:dependent => :destroy
|
|
57
|
+
|
|
58
|
+
# Hence a page can belongs to another page
|
|
59
|
+
belongs_to :parent, :class_name => "Page"
|
|
60
|
+
|
|
61
|
+
# A page will belongs to a layout
|
|
62
|
+
belongs_to :layout, :class_name => "Layout"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
#Save Parent and child form together by using association with dependents destroy
|
|
66
|
+
accepts_nested_attributes_for :page_parts_pages, :allow_destroy => true
|
|
67
|
+
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
|
68
|
+
|
|
69
|
+
# @params : None
|
|
70
|
+
# @return : Array
|
|
71
|
+
# @Purpose : To find title and id of all pages
|
|
72
|
+
def self.find_all_pages
|
|
73
|
+
|
|
74
|
+
#finding title and id of all pages
|
|
75
|
+
return self.select("id, title")
|
|
76
|
+
|
|
77
|
+
end # end method
|
|
78
|
+
|
|
79
|
+
# @param = integer
|
|
80
|
+
# @return = Array
|
|
81
|
+
# Helps to resolve the situation where you have a path and an id
|
|
82
|
+
# If page corresponding to path is not found then try finding page
|
|
83
|
+
# by id.
|
|
84
|
+
def self.find_by_slug_or_id(path, id)
|
|
85
|
+
|
|
86
|
+
# if path is present
|
|
87
|
+
if path.present?
|
|
88
|
+
|
|
89
|
+
# then call find_by_path method to find the page
|
|
90
|
+
find_by_path(path)
|
|
91
|
+
|
|
92
|
+
#if path is not present but ID is present,
|
|
93
|
+
elsif id.present?
|
|
94
|
+
|
|
95
|
+
# then call rails find method to find page by id
|
|
96
|
+
find_by_path(id)
|
|
97
|
+
|
|
98
|
+
end # end outer if
|
|
99
|
+
|
|
100
|
+
end # end method
|
|
101
|
+
|
|
102
|
+
# @params : string(path)
|
|
103
|
+
# @return : Array(page)
|
|
104
|
+
# @purpose : With slugs scoped to the parent page we need to find a page by its full path.
|
|
105
|
+
# For example with about/example we would need to find 'about' and then its child
|
|
106
|
+
# called 'example' otherwise it may clash with another page called /example.
|
|
107
|
+
def self.find_by_path(path)
|
|
108
|
+
|
|
109
|
+
# split the path param and assign it to a variable, and reject spliting if it is blank
|
|
110
|
+
split_path = path.to_s.split('/').reject(&:blank?)
|
|
111
|
+
|
|
112
|
+
# find page details using find_by_slug method and assign it to a variable
|
|
113
|
+
page = Page.find_by_slug(split_path.shift)
|
|
114
|
+
|
|
115
|
+
# find child page and then details of page using find_by_slug method and assign it to a variable
|
|
116
|
+
page = page.children.find_by_slug(split_path.shift) until page.nil? || split_path.empty?
|
|
117
|
+
|
|
118
|
+
# return page variable
|
|
119
|
+
page
|
|
120
|
+
|
|
121
|
+
end # end method
|
|
122
|
+
|
|
123
|
+
# @params : none
|
|
124
|
+
# @return : boolean
|
|
125
|
+
# @purpose : To check whther the page ios deletable or not
|
|
126
|
+
def deletable?
|
|
127
|
+
|
|
128
|
+
# if link url is / or /404 then page is not deletable
|
|
129
|
+
if link_url == '/' || link_url == '/404'
|
|
130
|
+
|
|
131
|
+
false
|
|
132
|
+
|
|
133
|
+
else
|
|
134
|
+
|
|
135
|
+
true
|
|
136
|
+
|
|
137
|
+
end # end if
|
|
138
|
+
|
|
139
|
+
end # end method
|
|
140
|
+
|
|
141
|
+
# @param : none
|
|
142
|
+
# @return : none
|
|
143
|
+
# @purpose : make nested url for child pages in the form of parent/child
|
|
144
|
+
def nested_url
|
|
145
|
+
|
|
146
|
+
# find the parent of the current page and convert the current page slug to nested url
|
|
147
|
+
[parent, to_param.to_s].compact.flatten
|
|
148
|
+
|
|
149
|
+
end # end method
|
|
150
|
+
|
|
151
|
+
end #end class
|
|
152
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
@File Name : page_part.rb
|
|
3
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
4
|
+
@Creator Name : Vikram Kumar Mishra
|
|
5
|
+
@Date Created : 2012-06-05
|
|
6
|
+
@Date Modified : 2012-06-08
|
|
7
|
+
@Last Modification Details : Title field validation added
|
|
8
|
+
@Purpose : To deal with database table "mcms_page_parts" and all operations related to that table mainly.
|
|
9
|
+
It may deal with other tables and DB related operations.
|
|
10
|
+
=end
|
|
11
|
+
|
|
12
|
+
#defining model class to interact with database. It inherits the rails's base class ActiveRecord::Base
|
|
13
|
+
class PagePart < ActiveRecord::Base
|
|
14
|
+
|
|
15
|
+
#By default it access the table named "page_parts",
|
|
16
|
+
#so explicitly setting the table name to access required table
|
|
17
|
+
self.table_name = "mcms_page_parts"
|
|
18
|
+
|
|
19
|
+
#defining has_many :through relationship
|
|
20
|
+
has_many :page_parts_pages, :class_name => 'PagePartsPage'
|
|
21
|
+
|
|
22
|
+
#defining has_many relation of page_parts to pages through page_part_pages
|
|
23
|
+
has_many :pages, :through => :page_parts_pages
|
|
24
|
+
|
|
25
|
+
#defining the list of accessible attributes as required by rails
|
|
26
|
+
attr_accessible :body, :page_id, :title, :page_parts_pages_attributes
|
|
27
|
+
|
|
28
|
+
#validating title field to have non-blank value
|
|
29
|
+
validates :title, :presence => true
|
|
30
|
+
|
|
31
|
+
# @param : none
|
|
32
|
+
# @return : array
|
|
33
|
+
# @purpose : To find all page_parts with title header
|
|
34
|
+
def self.find_page_parts_with_title_header
|
|
35
|
+
|
|
36
|
+
#find all page parts with title header and assign it to a variable
|
|
37
|
+
header_part = self.find_all_by_title("header")
|
|
38
|
+
|
|
39
|
+
# calling method to find unique pages and assigning them to an array
|
|
40
|
+
page_title = PagePartsPage.find_unique_page_parts_pages(header_part)
|
|
41
|
+
|
|
42
|
+
# returning the array
|
|
43
|
+
return page_title
|
|
44
|
+
|
|
45
|
+
end # end method
|
|
46
|
+
|
|
47
|
+
# @param : none
|
|
48
|
+
# @return : array
|
|
49
|
+
# @purpose : To find all page_parts with title header
|
|
50
|
+
def self.find_page_parts_with_title_footer
|
|
51
|
+
|
|
52
|
+
#find all page parts with title header and assign it to a variable
|
|
53
|
+
footer_part = self.find_all_by_title("footer")
|
|
54
|
+
|
|
55
|
+
# calling method to find unique pages and assigning them to an array
|
|
56
|
+
page_title = PagePartsPage.find_unique_page_parts_pages(footer_part)
|
|
57
|
+
|
|
58
|
+
# returning the array
|
|
59
|
+
return page_title
|
|
60
|
+
|
|
61
|
+
end # end method
|
|
62
|
+
|
|
63
|
+
# @param : none
|
|
64
|
+
# @return : array
|
|
65
|
+
# @purpose : To find all page_parts with title right body
|
|
66
|
+
def self.find_page_parts_with_title_right_body
|
|
67
|
+
|
|
68
|
+
#find all page parts with title header and assign it to a variable
|
|
69
|
+
right_body = self.find_all_by_title("right body")
|
|
70
|
+
|
|
71
|
+
# calling method to find unique pages and assigning them to an array
|
|
72
|
+
page_title = PagePartsPage.find_unique_page_parts_pages(right_body)
|
|
73
|
+
|
|
74
|
+
# returning the array
|
|
75
|
+
return page_title
|
|
76
|
+
|
|
77
|
+
end # end method
|
|
78
|
+
|
|
79
|
+
# @param : none
|
|
80
|
+
# @return : array
|
|
81
|
+
# @purpose : To find all page_parts with title left body
|
|
82
|
+
def self.find_page_parts_with_title_left_body
|
|
83
|
+
|
|
84
|
+
#find all page parts with title header and assign it to a variable
|
|
85
|
+
left_body = self.find_all_by_title("left body")
|
|
86
|
+
|
|
87
|
+
# calling method to find unique pages and assigning them to an array
|
|
88
|
+
page_title = PagePartsPage.find_unique_page_parts_pages(left_body)
|
|
89
|
+
|
|
90
|
+
# returning the array
|
|
91
|
+
return page_title
|
|
92
|
+
|
|
93
|
+
end # end method
|
|
94
|
+
|
|
95
|
+
def self.find_page_parts_with_title_main_body
|
|
96
|
+
return "main body"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end # end class
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
@File Name : page_parts_page.rb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-06-25
|
|
7
|
+
@Date Modified :
|
|
8
|
+
@Last Modification Details :
|
|
9
|
+
@Purpose : To deal many to many relationship for page and page_parts
|
|
10
|
+
=end
|
|
11
|
+
|
|
12
|
+
#defining model class to interact with database. It inherits the rails's base class ActiveRecord::Base
|
|
13
|
+
class PagePartsPage < ActiveRecord::Base
|
|
14
|
+
|
|
15
|
+
#By default it access the table named "pages",
|
|
16
|
+
#so explicitly setting the table name to access required table
|
|
17
|
+
self.table_name = "mcms_page_parts_pages"
|
|
18
|
+
|
|
19
|
+
#definig the list of accessible attributes as required by rails
|
|
20
|
+
attr_accessible :page_id, :page_part_id
|
|
21
|
+
|
|
22
|
+
# A page_parts_pages will belongs to pages
|
|
23
|
+
belongs_to :page, :foreign_key => :page_id
|
|
24
|
+
|
|
25
|
+
# A page_parts_pages will belongs to page_parts
|
|
26
|
+
belongs_to :page_part, :foreign_key => :page_part_id
|
|
27
|
+
|
|
28
|
+
# @params : Array
|
|
29
|
+
# @returns : Array
|
|
30
|
+
# @purpose : To find page_id from page_parts_pages table on the basis of unique page_part_id
|
|
31
|
+
def self.find_unique_page_parts_pages(parts)
|
|
32
|
+
|
|
33
|
+
#initialize an empty array
|
|
34
|
+
page_title = Hash.new
|
|
35
|
+
|
|
36
|
+
# for each parts
|
|
37
|
+
parts.each do |part|
|
|
38
|
+
|
|
39
|
+
#find first page id using the page_part part
|
|
40
|
+
page_parts_pages = self.find_by_page_part_id(part.id)
|
|
41
|
+
|
|
42
|
+
# insert page title in the array
|
|
43
|
+
page_title[page_parts_pages.page_part.id] = page_parts_pages.page.title if not page_parts_pages.nil?
|
|
44
|
+
|
|
45
|
+
end # end loop
|
|
46
|
+
|
|
47
|
+
# return array of page title
|
|
48
|
+
return page_title
|
|
49
|
+
|
|
50
|
+
end # end method
|
|
51
|
+
|
|
52
|
+
end # end class
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@File Name : admin/layouts/index.html.erb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-06-15
|
|
7
|
+
@Date Modified :
|
|
8
|
+
@Last Modification Details :
|
|
9
|
+
@Purpose : To display all the layouts and respective image and let the user choose the specific layout.
|
|
10
|
+
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
<h3> Click on the Image you want to choose as layout </h3>
|
|
14
|
+
|
|
15
|
+
<div id="layout-images-div">
|
|
16
|
+
|
|
17
|
+
<!--
|
|
18
|
+
looping through all the elements of @layouts array to
|
|
19
|
+
show preview images for all layouts
|
|
20
|
+
-->
|
|
21
|
+
<% @layouts.each do |layout| %>
|
|
22
|
+
|
|
23
|
+
<div class="layout-images">
|
|
24
|
+
|
|
25
|
+
<div class="layout-name">
|
|
26
|
+
|
|
27
|
+
<%= layout.name %>
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
<div class="layout-image">
|
|
31
|
+
|
|
32
|
+
<%= image_tag("layouts/#{layout.name.tr(' ', '-')}.png", :size => "400x400", :alt => "#{layout.name}", :title => "click to view large") %>
|
|
33
|
+
|
|
34
|
+
</div>
|
|
35
|
+
<div class="layout-link">
|
|
36
|
+
|
|
37
|
+
<!-- if parent_id is not 0 then send parent_id through url -->
|
|
38
|
+
<% if not @page_parent_id == 0 %>
|
|
39
|
+
|
|
40
|
+
<%= link_to("Use This Layout", new_admin_page_path(:layout_id => "#{layout.id}", :parent_id => "#{@page_parent_id}")) %>
|
|
41
|
+
|
|
42
|
+
<% else %>
|
|
43
|
+
|
|
44
|
+
<%= link_to("Use This Layout", new_admin_page_path(:layout_id => "#{layout.id}")) %>
|
|
45
|
+
|
|
46
|
+
<% end %>
|
|
47
|
+
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<% end %>
|
|
53
|
+
|
|
54
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@File Name : admin/pages/_mcms_action.html.erb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-06-09
|
|
7
|
+
@Date Modified : 2012-06-14
|
|
8
|
+
@Last Modification Details : 'mcms-' removed from css selectors
|
|
9
|
+
@Purpose : Application level action for admin pages will be defined here.
|
|
10
|
+
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
<section id="application-actions">
|
|
15
|
+
|
|
16
|
+
<%= link_to "Add a New Page", new_admin_page_path, :id => "page-new" %>
|
|
17
|
+
|
|
18
|
+
</section>
|
|
19
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@File Name : admin/pages/_error_messages.html.erb
|
|
4
|
+
@Company Name : Mindfire Solutions Private Limited
|
|
5
|
+
@Creator Name : Vikram Kumar Mishra
|
|
6
|
+
@Date Created : 2012-07-04
|
|
7
|
+
@Date Modified :
|
|
8
|
+
@Last Modification Details :
|
|
9
|
+
@Purpose : To display the form errors
|
|
10
|
+
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
<!-- check for occurences of any errors -->
|
|
14
|
+
<% if object.errors.any? %>
|
|
15
|
+
|
|
16
|
+
<div class="error-explanation" id="error-explanation">
|
|
17
|
+
|
|
18
|
+
<ul>
|
|
19
|
+
|
|
20
|
+
<% unless defined?(include_object_name) and include_object_name %>
|
|
21
|
+
|
|
22
|
+
<% object.errors.each do |key, value| %>
|
|
23
|
+
|
|
24
|
+
<li><%= value %></li>
|
|
25
|
+
|
|
26
|
+
<% end %>
|
|
27
|
+
|
|
28
|
+
<% else %>
|
|
29
|
+
|
|
30
|
+
<% object.errors.full_messages.each do |value| %>
|
|
31
|
+
|
|
32
|
+
<li><%= value %></li>
|
|
33
|
+
|
|
34
|
+
<% end %>
|
|
35
|
+
|
|
36
|
+
<% end %>
|
|
37
|
+
|
|
38
|
+
</ul>
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<% end %>
|