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.
Files changed (172) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/layouts/one-column.png +0 -0
  5. data/app/assets/images/layouts/three-column.png +0 -0
  6. data/app/assets/images/layouts/two-column-with-left.png +0 -0
  7. data/app/assets/images/layouts/two-column-with-right.png +0 -0
  8. data/app/assets/images/mcms_pages/9.jpg +0 -0
  9. data/app/assets/images/mcms_pages/background.jpg +0 -0
  10. data/app/assets/images/mcms_pages/bamboo_love.jpg +0 -0
  11. data/app/assets/images/mcms_pages/branch-end.gif +0 -0
  12. data/app/assets/images/mcms_pages/branch-start.gif +0 -0
  13. data/app/assets/images/mcms_pages/branch.gif +0 -0
  14. data/app/assets/images/mcms_pages/content_bottom.jpg +0 -0
  15. data/app/assets/images/mcms_pages/icons/accept.png +0 -0
  16. data/app/assets/images/mcms_pages/icons/add.png +0 -0
  17. data/app/assets/images/mcms_pages/icons/ajax-loader.gif +0 -0
  18. data/app/assets/images/mcms_pages/icons/application_edit.png +0 -0
  19. data/app/assets/images/mcms_pages/icons/application_go.png +0 -0
  20. data/app/assets/images/mcms_pages/icons/arrow_left.png +0 -0
  21. data/app/assets/images/mcms_pages/icons/arrow_switch.png +0 -0
  22. data/app/assets/images/mcms_pages/icons/arrow_up.png +0 -0
  23. data/app/assets/images/mcms_pages/icons/bin.png +0 -0
  24. data/app/assets/images/mcms_pages/icons/bin_closed.png +0 -0
  25. data/app/assets/images/mcms_pages/icons/cancel.png +0 -0
  26. data/app/assets/images/mcms_pages/icons/cog_add.png +0 -0
  27. data/app/assets/images/mcms_pages/icons/cog_edit.png +0 -0
  28. data/app/assets/images/mcms_pages/icons/cross.png +0 -0
  29. data/app/assets/images/mcms_pages/icons/delete.png +0 -0
  30. data/app/assets/images/mcms_pages/icons/doc.png +0 -0
  31. data/app/assets/images/mcms_pages/icons/down.gif +0 -0
  32. data/app/assets/images/mcms_pages/icons/edit.png +0 -0
  33. data/app/assets/images/mcms_pages/icons/email.png +0 -0
  34. data/app/assets/images/mcms_pages/icons/email_edit.png +0 -0
  35. data/app/assets/images/mcms_pages/icons/email_go.png +0 -0
  36. data/app/assets/images/mcms_pages/icons/email_open.png +0 -0
  37. data/app/assets/images/mcms_pages/icons/eye.png +0 -0
  38. data/app/assets/images/mcms_pages/icons/folder.png +0 -0
  39. data/app/assets/images/mcms_pages/icons/folder_open.png +0 -0
  40. data/app/assets/images/mcms_pages/icons/folder_page_white.png +0 -0
  41. data/app/assets/images/mcms_pages/icons/image_add.png +0 -0
  42. data/app/assets/images/mcms_pages/icons/image_edit.png +0 -0
  43. data/app/assets/images/mcms_pages/icons/img.png +0 -0
  44. data/app/assets/images/mcms_pages/icons/information.png +0 -0
  45. data/app/assets/images/mcms_pages/icons/layout_add.png +0 -0
  46. data/app/assets/images/mcms_pages/icons/layout_edit.png +0 -0
  47. data/app/assets/images/mcms_pages/icons/music.png +0 -0
  48. data/app/assets/images/mcms_pages/icons/page.png +0 -0
  49. data/app/assets/images/mcms_pages/icons/page_add.png +0 -0
  50. data/app/assets/images/mcms_pages/icons/page_edit.png +0 -0
  51. data/app/assets/images/mcms_pages/icons/page_white_edit.png +0 -0
  52. data/app/assets/images/mcms_pages/icons/page_white_gear.png +0 -0
  53. data/app/assets/images/mcms_pages/icons/page_white_put.png +0 -0
  54. data/app/assets/images/mcms_pages/icons/pdf.png +0 -0
  55. data/app/assets/images/mcms_pages/icons/ppt.png +0 -0
  56. data/app/assets/images/mcms_pages/icons/star.png +0 -0
  57. data/app/assets/images/mcms_pages/icons/tick.png +0 -0
  58. data/app/assets/images/mcms_pages/icons/up.gif +0 -0
  59. data/app/assets/images/mcms_pages/icons/user_add.png +0 -0
  60. data/app/assets/images/mcms_pages/icons/user_comment.png +0 -0
  61. data/app/assets/images/mcms_pages/icons/user_edit.png +0 -0
  62. data/app/assets/images/mcms_pages/icons/xls.png +0 -0
  63. data/app/assets/images/mcms_pages/icons/zip.png +0 -0
  64. data/app/assets/images/mcms_pages/icons/zoom.png +0 -0
  65. data/app/assets/images/mcms_pages/tab_off.jpg +0 -0
  66. data/app/assets/images/mcms_pages/tab_on.jpg +0 -0
  67. data/app/assets/javascripts/menuPage.js +45 -0
  68. data/app/assets/javascripts/pageFormAdmin.js +192 -0
  69. data/app/assets/stylesheets/mcms_pages/layout.css.scss +16 -0
  70. data/app/assets/stylesheets/mcms_pages/page_styles.css +95 -0
  71. data/app/assets/stylesheets/mcms_pages/pages.css.scss +172 -0
  72. data/app/controllers/admin/layouts_controller.rb +51 -0
  73. data/app/controllers/admin/pages_controller.rb +303 -0
  74. data/app/controllers/admin_controller.rb +22 -0
  75. data/app/controllers/application_controller.rb +20 -0
  76. data/app/controllers/pages_controller.rb +151 -0
  77. data/app/helpers/pages_helper.rb +118 -0
  78. data/app/models/ckeditor/asset.rb +8 -0
  79. data/app/models/ckeditor/attachment_file.rb +13 -0
  80. data/app/models/ckeditor/picture.rb +14 -0
  81. data/app/models/layout.rb +64 -0
  82. data/app/models/page.rb +152 -0
  83. data/app/models/page_part.rb +99 -0
  84. data/app/models/page_parts_page.rb +52 -0
  85. data/app/views/mcms_pages/admin/layouts/index.html.erb +54 -0
  86. data/app/views/mcms_pages/admin/pages/_action.html.erb +19 -0
  87. data/app/views/mcms_pages/admin/pages/_error_messages.html.erb +42 -0
  88. data/app/views/mcms_pages/admin/pages/_form.html.erb +90 -0
  89. data/app/views/mcms_pages/admin/pages/_form.js.erb +55 -0
  90. data/app/views/mcms_pages/admin/pages/_page.html.erb +63 -0
  91. data/app/views/mcms_pages/admin/pages/_page_part_edit_form.html.erb +140 -0
  92. data/app/views/mcms_pages/admin/pages/_page_part_form.html.erb +133 -0
  93. data/app/views/mcms_pages/admin/pages/_page_part_form_field.html.erb +21 -0
  94. data/app/views/mcms_pages/admin/pages/_page_part_page_form_field.html.erb +39 -0
  95. data/app/views/mcms_pages/admin/pages/add_page_part.js.erb +25 -0
  96. data/app/views/mcms_pages/admin/pages/edit.html.erb +15 -0
  97. data/app/views/mcms_pages/admin/pages/find_child.html.erb +15 -0
  98. data/app/views/mcms_pages/admin/pages/index.html.erb +26 -0
  99. data/app/views/mcms_pages/admin/pages/new.html.erb +15 -0
  100. data/app/views/mcms_pages/layouts/_footer.html.erb +16 -0
  101. data/app/views/mcms_pages/layouts/_header.html.erb +16 -0
  102. data/app/views/mcms_pages/layouts/_javascript.html.erb +22 -0
  103. data/app/views/mcms_pages/layouts/_stylesheets.html.erb +23 -0
  104. data/app/views/mcms_pages/layouts/mcms_layout.html.erb +39 -0
  105. data/app/views/mcms_pages/pages/_left_side_body.html.erb +16 -0
  106. data/app/views/mcms_pages/pages/_main_body.html.erb +16 -0
  107. data/app/views/mcms_pages/pages/_menu.html.erb +18 -0
  108. data/app/views/mcms_pages/pages/_menubar.html.erb +24 -0
  109. data/app/views/mcms_pages/pages/_one_column_layout.html.erb +14 -0
  110. data/app/views/mcms_pages/pages/_right_side_body.html.erb +16 -0
  111. data/app/views/mcms_pages/pages/_three_column_layout.html.erb +20 -0
  112. data/app/views/mcms_pages/pages/_two_column_layout.html.erb +27 -0
  113. data/app/views/mcms_pages/pages/home.html.erb +26 -0
  114. data/app/views/mcms_pages/pages/show.html.erb +34 -0
  115. data/config/routes.rb +57 -0
  116. data/db/migrate/20120605100629_create_pages.rb +17 -0
  117. data/db/migrate/20120605100650_create_page_parts.rb +10 -0
  118. data/db/migrate/20120606150655_create_mcms_assets.rb +26 -0
  119. data/db/migrate/20120606150656_add_title_position_to_page_parts.rb +5 -0
  120. data/db/migrate/20120609055514_add_parent_id_to_pages.rb +5 -0
  121. data/db/migrate/20120612054659_add_lft_rgt_to_mcms_pages.rb +6 -0
  122. data/db/migrate/20120614125619_create_layouts.rb +16 -0
  123. data/db/migrate/20120614131633_add_layout_id_to_mcms_pages.rb +5 -0
  124. data/db/migrate/20120614134343_add_foreign_key_to_page.rb +6 -0
  125. data/db/migrate/20120618060815_drop_column_permalink_from_mcms_pages.rb +10 -0
  126. data/db/migrate/20120618102226_add_slug_to_mcms_pages.rb +6 -0
  127. data/db/migrate/20120625063039_create_page_associations.rb +14 -0
  128. data/db/migrate/20120625112225_add_header_footer_to_mcms_layouts.rb +6 -0
  129. data/db/seeds.rb +175 -0
  130. data/lib/generators/mcms_pages/USAGE +8 -0
  131. data/lib/generators/mcms_pages/assets_generator.rb +79 -0
  132. data/lib/generators/mcms_pages/mcms_pages_generator.rb +101 -0
  133. data/lib/generators/mcms_pages/templates/asset_manager.rb +160 -0
  134. data/lib/generators/mcms_pages/templates/ckeditor.rb +18 -0
  135. data/lib/generators/mcms_pages/views_generator.rb +79 -0
  136. data/lib/mcms_pages/engine.rb +13 -0
  137. data/lib/mcms_pages/version.rb +3 -0
  138. data/lib/mcms_pages.rb +7 -0
  139. data/lib/tasks/mcms_pages_tasks.rake +4 -0
  140. data/test/dummy/README.rdoc +261 -0
  141. data/test/dummy/Rakefile +7 -0
  142. data/test/dummy/app/assets/javascripts/application.js +15 -0
  143. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  144. data/test/dummy/app/controllers/application_controller.rb +3 -0
  145. data/test/dummy/app/helpers/application_helper.rb +2 -0
  146. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  147. data/test/dummy/config/application.rb +59 -0
  148. data/test/dummy/config/boot.rb +10 -0
  149. data/test/dummy/config/database.yml +25 -0
  150. data/test/dummy/config/environment.rb +5 -0
  151. data/test/dummy/config/environments/development.rb +37 -0
  152. data/test/dummy/config/environments/production.rb +67 -0
  153. data/test/dummy/config/environments/test.rb +37 -0
  154. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  155. data/test/dummy/config/initializers/inflections.rb +15 -0
  156. data/test/dummy/config/initializers/mime_types.rb +5 -0
  157. data/test/dummy/config/initializers/secret_token.rb +7 -0
  158. data/test/dummy/config/initializers/session_store.rb +8 -0
  159. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  160. data/test/dummy/config/locales/en.yml +5 -0
  161. data/test/dummy/config/routes.rb +58 -0
  162. data/test/dummy/config.ru +4 -0
  163. data/test/dummy/log/development.log +0 -0
  164. data/test/dummy/public/404.html +26 -0
  165. data/test/dummy/public/422.html +26 -0
  166. data/test/dummy/public/500.html +25 -0
  167. data/test/dummy/public/favicon.ico +0 -0
  168. data/test/dummy/script/rails +6 -0
  169. data/test/integration/navigation_test.rb +10 -0
  170. data/test/mcms_pages_test.rb +7 -0
  171. data/test/test_helper.rb +15 -0
  172. metadata +360 -0
@@ -0,0 +1,172 @@
1
+ /*
2
+
3
+ * @File Name : pages.css.scss
4
+ * @Company Name : Mindfire Solutions Private Limited
5
+ * @Creator Name : Vikram Kumar Mishra
6
+ * @Date Created : 2012-06-06
7
+ * @Date Modified : 2012-06-09
8
+ * @Last Modification Details : Styles added for some elements
9
+ * @Purpose : Place all the styles related to the pages controller here.
10
+
11
+ */
12
+
13
+
14
+ li{
15
+ list-style-type: none;
16
+ display:inline;
17
+ }
18
+
19
+ .even
20
+ {
21
+ background-color: aquamarine;
22
+ }
23
+
24
+ .pages-clearfix:after {
25
+ clear: both;
26
+ content: ".";
27
+ display: block;
28
+ height: 0;
29
+ visibility: hidden;
30
+ }
31
+
32
+ .pages-clearfix {
33
+ display: block;
34
+ }
35
+
36
+ #application-actions{
37
+ float: right;
38
+ padding-left: 15px;
39
+ padding-top: 0;
40
+ width: 30.7%;
41
+ }
42
+
43
+
44
+ #pages-records {
45
+
46
+ float: left;
47
+ width: 67.7%;
48
+ border: 1px solid red;
49
+
50
+ #page-sortable-list {
51
+ margin-top: 6px;
52
+
53
+ li{
54
+ padding: 4px 0 0 40px;
55
+
56
+ div{
57
+ width: 100%;
58
+
59
+ span.page-icon{
60
+ background: url("icons/page.png") no-repeat scroll center center transparent;
61
+ display: block;
62
+ float: left;
63
+ height: 16px;
64
+ margin: 3px 3px 0 0;
65
+ width: 16px;
66
+ }
67
+
68
+ span.page-icon.page-toggle.page-expanded{
69
+ background-image: url("icons/folder_open.png");
70
+ }
71
+
72
+ span.page-icon.page-toggle{
73
+ background-image: url("icons/folder_open.png");
74
+ }
75
+
76
+ .page-title{
77
+ width:80%;
78
+ text-align:left;
79
+ }
80
+
81
+ .page-actions{
82
+ display: inline;
83
+ line-height: 28px;
84
+ float: right;
85
+ position:relative;
86
+ top: 3px;
87
+ width: 120px;
88
+ text-align: right;
89
+
90
+ a{
91
+ margin: 3px 3px 0;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ #pages-records.pages-tree ul li, .pages-tree ul li {
100
+ background: url("branch.gif") no-repeat scroll 15px 0 transparent;
101
+ margin: 0;
102
+ padding: 4px 0 0 40px;
103
+ }
104
+
105
+ #pages-records.pages-tree li {
106
+ line-height: 25px;
107
+ }
108
+
109
+ #pages-records > ul li{
110
+ line-height: 35px;
111
+ list-style: none outside none;
112
+ margin-bottom: 2px;
113
+ padding: 0 5px;
114
+ position: relative;
115
+ vertical-align: top;
116
+ }
117
+
118
+ #pages-records.pages-tree ul li.pages-tree-start, .pages-tree ul li.pages-tree-start {
119
+ background-image: url("branch-start.gif");
120
+ }
121
+
122
+ #pages-records.pages-tree ul li, .pages-tree ul li {
123
+ background: url("branch.gif") no-repeat scroll 15px 0 transparent;
124
+ margin: 0;
125
+ padding: 4px 0 0 40px;
126
+ }
127
+
128
+ .pages-clearfix {
129
+ display: block;
130
+ }
131
+
132
+ #pages-records.pages-tree ul li.pages-tree-end, .pages-tree ul li.pages-tree-end {
133
+ background-image: url("branch-end.gif");
134
+ }
135
+
136
+ #pages-records.pages-tree li.pages-record ul {
137
+ margin-left: 0;
138
+ }
139
+
140
+ #pages-records.pages-tree ul li ul, .pages-tree ul li ul {
141
+ padding: 0;
142
+ }
143
+
144
+ .error-explanation
145
+ {
146
+ color: red;
147
+ text-align: left;
148
+ }
149
+
150
+ .pages-menu {
151
+
152
+ width: 100%;
153
+ float: left;
154
+ text-align: right;
155
+ margin-bottom: 10px;
156
+
157
+ }
158
+
159
+ .pages-menu-li{
160
+
161
+ list-style-type: none;
162
+ float: left;
163
+ margin-left: 10px;
164
+ }
165
+
166
+ .pages-menu-li ul {display: none; }
167
+
168
+ .notice {
169
+ color: green;
170
+ font-size: 16px;
171
+ }
172
+
@@ -0,0 +1,51 @@
1
+ =begin
2
+
3
+ @File Name : admin/layouts_controller.rb
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 setup the communication between layout model and views related to layouts under namespace admin.
10
+
11
+ =end
12
+
13
+ class Admin::LayoutsController < AdminController
14
+
15
+ before_filter :load_assets
16
+
17
+ # GET /layouts
18
+ # GET /layouts.json
19
+ # To find all layouts and display it to the user to choose one
20
+ def index
21
+
22
+ # find all layouts
23
+ @layouts = Layout.all
24
+
25
+ # find parent_id of page if child page is being created
26
+ # if parent_id is not there i.e. child page is not being created,
27
+ # use parent_id as 0
28
+ @page_parent_id = (params[:parent_id]) ? params[:parent_id] : 0
29
+
30
+ # send data in different format
31
+ respond_to do |format|
32
+ format.html{render :template => 'mcms_pages/admin/layouts/index'}# index.html.erb
33
+ format.json { render json: @pages }
34
+ end # end respond_to
35
+
36
+ end # end action
37
+
38
+ #defining controller specific method as protected
39
+ protected
40
+
41
+ #calling library class AssetManager's methods to include specific js and css files
42
+ def load_assets
43
+
44
+ # class method call to include css files
45
+ AssetManager.include_css ["mcms_pages/layout"]
46
+
47
+ end # end method
48
+
49
+
50
+ end # end class
51
+
@@ -0,0 +1,303 @@
1
+ =begin
2
+
3
+ @File Name : admin/pages_controller.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-08
8
+ @Last Modification Details : Page part saved successfully
9
+ @Purpose : To setup the communication between page model and views related to pages under namespace admin.
10
+
11
+ =end
12
+
13
+ class Admin::PagesController < AdminController
14
+
15
+ #includes helper file
16
+ include PagesHelper
17
+
18
+ # loading controller specific assets
19
+ before_filter :load_assets
20
+
21
+ # GET /pages
22
+ # GET /pages.json
23
+ # finds all pages created so far and displays it
24
+ # It may change in future
25
+ def index
26
+
27
+ # find all pages
28
+ @pages = Page.all
29
+
30
+ # send data in different format
31
+ respond_to do |format|
32
+ format.html{render :template => 'mcms_pages/admin/pages/index'}# index.html.erb
33
+ format.json { render json: @pages }
34
+ end # end respond_to
35
+
36
+ end # end action
37
+
38
+ # GET /pages/new
39
+ # GET /pages/new.json
40
+ # renders the form for new page and also page part
41
+ # to save page and page part together successfully
42
+ def new
43
+
44
+ # check if params[:layout_id] is present
45
+ if not params[:layout_id]
46
+
47
+ # if not redirect to layout page
48
+ redirect_to admin_layouts_path(:parent_id => params[:parent_id])
49
+
50
+ else # params[:layout_id] is present
51
+
52
+ #initializing an empty object
53
+ @page = Page.new
54
+
55
+ #retrieve parent_id parameter
56
+ @page.parent_id = params[:parent_id]
57
+
58
+ #retrieving layout id from params and assigning to a variable
59
+ @layout = params[:layout_id]
60
+
61
+ # calling method to find all pages and page parts
62
+ find_pages_and_parts(@layout)
63
+
64
+ #calling method to build page parts
65
+ build_page_parts(@parts)
66
+
67
+ #sends data in different formats
68
+ respond_to do |format|
69
+
70
+ format.html{render :template => 'mcms_pages/admin/pages/new'}# new.html.erb
71
+ format.json { render json: @page }
72
+
73
+ end # end respond_to block
74
+
75
+ end # end if
76
+
77
+ end # end action
78
+
79
+ # GET /pages/1/edit
80
+ # finds the page with given ID and displays the
81
+ # fields with value to edit, i.e. edit form
82
+ def edit
83
+
84
+ # find page with given ID
85
+ #@page = Page.find(params[:id])
86
+ @page = Page.find_by_slug_or_id(params[:path], params[:id])
87
+
88
+ #retrieving layout id from params and assigning to a variable
89
+ @layout = @page["layout_id"]
90
+
91
+ # calling method to find all pages and page parts
92
+ find_pages_and_parts(@layout)
93
+
94
+ # calling method to define parts of the page
95
+ define_parts
96
+
97
+ #sends data in different formats
98
+ respond_to do |format|
99
+
100
+ format.html{render :template => 'mcms_pages/admin/pages/edit'}# edit.html.erb
101
+ format.json { render json: @page }
102
+
103
+ end # end respond_to block
104
+
105
+ end # end action
106
+
107
+ # POST /pages
108
+ # POST /pages.json
109
+ # saves page with page parts and redirects to the
110
+ # current created page
111
+ def create
112
+
113
+ # retrieve page part attributes from params and assign it to a variable
114
+ page_parts = params[:page][:page_parts_attributes]
115
+
116
+ # sort the page_parts and reassign it to the params
117
+ params[:page][:page_parts_attributes] = Hash[page_parts.sort]
118
+
119
+ #creating the page object with its own and child attributes
120
+ @page = Page.new(params[:page])
121
+
122
+ #retrieving layout id from params and assigning to a variable
123
+ @layout = params[:page][:layout_id]
124
+
125
+ # calling method to find all pages and page parts
126
+ find_pages_and_parts(@layout)
127
+
128
+ # sends the data in different formats
129
+ respond_to do |format|
130
+
131
+ if @page.save #page saved successfully
132
+
133
+ format.html { redirect_to admin_pages_path, notice: 'Page was successfully created.' }
134
+ format.json { render json: @page, status: :created, location: @page }
135
+
136
+ else #page saving failed, re-render the form
137
+
138
+ format.html { render action: "new" }
139
+ format.json { render json: @page.errors, status: :unprocessable_entity }
140
+
141
+ end # end if
142
+
143
+ end # end respond_to block
144
+
145
+ end # end action
146
+
147
+ # PUT /pages/1
148
+ # PUT /pages/1.json
149
+ # Gets the ID via put method and updates the field
150
+ # and redirects to current edited page
151
+ def update
152
+
153
+ #find the page with given id
154
+ @page = Page.find(params[:id])
155
+
156
+ #retrieving layout id from params and assigning to a variable
157
+ @layout = @page[:layout_id]
158
+
159
+ # calling method to find all pages and page parts
160
+ find_pages_and_parts(@layout)
161
+
162
+ # calling method to define parts of the page
163
+ define_parts
164
+
165
+ #sends in data in different format
166
+ respond_to do |format|
167
+
168
+ if @page.update_attributes(params[:page]) #page updated successfully
169
+ format.html { redirect_to admin_pages_path, notice: 'Page was successfully updated.' }
170
+ format.json { head :no_content }
171
+ else #page saving failed, re-renders edit template
172
+ format.html { render action: "edit" }
173
+ format.json { render json: @page.errors, status: :unprocessable_entity }
174
+
175
+ end # end if
176
+
177
+ end # end respond_to block
178
+
179
+ end # end action
180
+
181
+ # DELETE /pages/1
182
+ # DELETE /pages/1.json
183
+ # destroys the page on the basis of ID
184
+ # and redirects to all pages path
185
+ def destroy
186
+
187
+ # find the page with with
188
+ @page = Page.find(params[:id])
189
+
190
+ #destroy the page
191
+ @page.destroy
192
+
193
+ #sends in data in different format to index action
194
+ respond_to do |format|
195
+
196
+ format.html { redirect_to admin_pages_url }
197
+ format.json { head :no_content }
198
+
199
+ end # end respond_to block
200
+
201
+ end # end action
202
+
203
+
204
+ # @param : None
205
+ # @return : None
206
+ # @purpose : To find a child page
207
+ def find_child
208
+
209
+ @page = Page.find_by_slug(params[:path])
210
+
211
+ logger.debug @page
212
+ render :layout => false
213
+
214
+ end
215
+
216
+ # @param : Object(as a string)
217
+ # @return : None
218
+ # @purpose : To render a page part dynamically
219
+ def add_page_part
220
+
221
+ #retrieve parameters and assign these to instance variables
222
+ @title = params[:title]
223
+ @index = params[:index]
224
+
225
+ # render js.erb
226
+ respond_to do |format|
227
+
228
+ format.js{render :template => 'mcms_pages/admin/pages/add_page_part'}
229
+
230
+ end # end respond_to
231
+
232
+ end # end method
233
+
234
+
235
+ #defining controller specific method as protected
236
+ protected
237
+
238
+ #calling library class AssetManager's methods to include specific js and css files
239
+ def load_assets
240
+
241
+ # class method call to include js files
242
+ AssetManager.include_local_library [:application, :pageFormAdmin, "ckeditor/init"]
243
+
244
+ # class method call to include css files
245
+ AssetManager.include_css ["mcms_pages/pages", "mcms_pages/page_styles"]
246
+
247
+ end # end method
248
+
249
+ # @param : Array
250
+ # @return : None
251
+ # @purpose : To build page parts for a page
252
+ def build_page_parts(parts)
253
+
254
+ #renders the form field for each part of layout
255
+ parts.each_with_index do |page_part, index|
256
+
257
+ fragment = get_fragments(index, page_part)
258
+
259
+ # check if same type of fragment is already created
260
+ if fragment.nil? or fragment.blank? or fragment.empty?
261
+
262
+ # if not then build child pages for all parts of the layout
263
+ @page.page_parts.build(:title => page_part)
264
+
265
+ else
266
+
267
+ # if yes then build child form for page_part_pages
268
+ @page.page_parts_pages.build
269
+
270
+ end # end if
271
+
272
+ end # end loop
273
+
274
+ end # end method
275
+
276
+ def find_pages_and_parts layout
277
+
278
+ #calling find_all_pages method from Page model
279
+ @pages = Page.find_all_pages
280
+
281
+ # storing the array returned by helper method to
282
+ # decide the page parts in a layout
283
+ @parts = Layout.find_page_parts(layout)
284
+
285
+ end
286
+
287
+ def define_parts
288
+
289
+ # declare an empty hash
290
+ @part_title = Hash.new
291
+
292
+ # loop through each part of the page
293
+ @parts.each_with_index do |part,index|
294
+
295
+ # retrieve the id of page parts of the page based on title and store it as a hash element
296
+ @part_title[part] = @page.page_parts.select("mcms_page_parts.id").find_by_title(part).id
297
+
298
+ end # end loop
299
+
300
+ end
301
+
302
+ end #end class
303
+
@@ -0,0 +1,22 @@
1
+ =begin
2
+
3
+ @File Name : admin_controller.rb
4
+ @Company Name : Mindfire Solutions Private Limited
5
+ @Creator Name : Vikram Kumar Mishra
6
+ @Date Created : 2012-06-05
7
+ @Date Modified :
8
+ @Last Modification Details :
9
+ @Purpose : To check current user's access, It is yet to implement.
10
+
11
+ =end
12
+
13
+ class AdminController < ApplicationController
14
+
15
+ #admin part
16
+ layout "mcms_pages/layouts/mcms_layout"
17
+
18
+ prepend_before_filter :authenticate_user!
19
+ load_and_authorize_resource
20
+
21
+ end
22
+
@@ -0,0 +1,20 @@
1
+ =begin
2
+
3
+ @File Name : application_controller.rb
4
+ @Company Name : Mindfire Solutions Private Limited
5
+ @Creator Name : Vikram Kumar Mishra
6
+ @Date Created : 2012-06-05
7
+ @Date Modified :
8
+ @Last Modification Details :
9
+ @Purpose : To navigate between different controllers throughout the application.
10
+ Its the backbone of the application.
11
+
12
+ =end
13
+
14
+ class ApplicationController < ActionController::Base
15
+
16
+ #calling rails standard method to request forgery protection for non-GET, HTML/JAVASCRIPT requests
17
+ protect_from_forgery
18
+
19
+ end # end class
20
+
@@ -0,0 +1,151 @@
1
+ =begin
2
+
3
+ @File Name : pages_controller.rb
4
+ @Company Name : Mindfire Solutions Private Limited
5
+ @Creator Name : Vikram Kumar Mishra
6
+ @Date Created : 2012-06-05
7
+ @Date Modified :
8
+ @Last Modification Details :
9
+ @Purpose : To setup the communication between page model and views related to pages for users,
10
+ It's yet to be implemented.
11
+
12
+ =end
13
+
14
+ class PagesController < ApplicationController
15
+
16
+ # loading controller specific assets
17
+ before_filter :load_assets
18
+ layout "mcms_pages/layouts/mcms_layout"
19
+
20
+ #finding page based on url
21
+ before_filter :get_page, :except => [:preview]
22
+
23
+ # GET / or GET /home
24
+ # @params : none
25
+ # return : none
26
+ # @purpose : To show the home page
27
+ def home
28
+
29
+ respond_to do |format|
30
+
31
+ format.html{ render :template => 'mcms_pages/pages/home'}# home.html.erb
32
+ format.json { render json: @page }
33
+
34
+ end # end respond_to block
35
+
36
+ end # end action
37
+
38
+ # GET /1 or GET /page-title
39
+ # GET /1.json or GET /page-title.json
40
+ # @params : integer or string through url
41
+ # return : none
42
+ # @purpose : To show the page with custom url to the user
43
+ def show
44
+
45
+ # if page is not publeshed
46
+ if not @page.published?
47
+
48
+ # show page 404
49
+ page_404_error
50
+
51
+ # if link_url is present for page
52
+ elsif @page.link_url.present? and @page.link_url != '/404'
53
+
54
+ # redirect to given link url
55
+ redirect_to @page.link_url
56
+
57
+ else
58
+
59
+ # send data in different format
60
+ respond_to do |format|
61
+
62
+ format.html{ render :template => 'mcms_pages/pages/show'}# show.html.erb
63
+ format.json { render json: @page }
64
+
65
+ end # end respond_to block
66
+
67
+ end # end if
68
+
69
+ end # end action
70
+
71
+ # GET /pages/1 or GET /pages/page-title
72
+ # GET /pages/1.json or GET /pages/page-title.json
73
+ # @params : integer or string through url
74
+ # return : none
75
+ # @purpose : To show the page preview with custom url to admin
76
+ def preview
77
+
78
+ if get_page(page_not_found = false)
79
+
80
+ # Preview existing pages
81
+ @page.attributes = params[:page]
82
+
83
+ elsif params[:page]
84
+
85
+ # Preview a non-persisted page
86
+ @page = Page.new(params[:page])
87
+
88
+ end # end if
89
+
90
+ # send data in different format
91
+ respond_to do |format|
92
+
93
+ format.html{ render :template => 'mcms_pages/pages/show'}
94
+ format.json { render json: @page }
95
+
96
+ end # end respond_to block
97
+
98
+ end # end method preview
99
+
100
+ #defining controller specific method as protected
101
+ protected
102
+
103
+ #calling library class AssetManager's methods to include specific js and css files
104
+ def load_assets
105
+
106
+ # class method call to include css files
107
+ AssetManager.include_css ["mcms_pages/pages", "mcms_pages/page_styles"]
108
+
109
+ end # end method
110
+
111
+ # @param : boolean(optional)
112
+ # @return : none
113
+ # @purpose : To find a page if it exists or show the page not found error
114
+ def get_page(page_not_found = true)
115
+
116
+ @menu_pages = Page.where(:published => true)
117
+
118
+ # case statement based on current action and assign the result to instance variable
119
+ case action_name
120
+
121
+ # when action is home
122
+ when "home"
123
+
124
+ # find page bbased on link url
125
+ @page = Page.where(:link_url => '/').first
126
+
127
+ # when action is show or preview
128
+ when "show", "preview"
129
+
130
+ # find page using path or id of page
131
+ @page = Page.find_by_slug_or_id(params[:path], params[:id])
132
+
133
+ end # end case statement
134
+
135
+ # return page or page not found error
136
+ @page || ( page_404_error if page_not_found)
137
+
138
+ end # end method
139
+
140
+ # @param : none
141
+ # @return : none
142
+ # @purpose : To show custom 404 page if page with given ID does not exist
143
+ def page_404_error
144
+
145
+ # find page based on link_url and assign it to an instance variable
146
+ @page = Page.where(:link_url => "/404").first
147
+
148
+ end # end method
149
+
150
+ end #end class
151
+