page_engine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +74 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/images/page_engine/add.png +0 -0
  5. data/app/assets/images/page_engine/bullet_add.png +0 -0
  6. data/app/assets/images/page_engine/bullet_go.png +0 -0
  7. data/app/assets/images/page_engine/delete.png +0 -0
  8. data/app/assets/images/page_engine/page_add.png +0 -0
  9. data/app/assets/images/page_engine/page_copy.png +0 -0
  10. data/app/assets/images/page_engine/page_delete.png +0 -0
  11. data/app/assets/images/page_engine/page_edit.png +0 -0
  12. data/app/assets/images/page_engine/page_gear.png +0 -0
  13. data/app/assets/images/page_engine/page_green.png +0 -0
  14. data/app/assets/images/page_engine/page_hidden.png +0 -0
  15. data/app/assets/images/page_engine/page_lightning.png +0 -0
  16. data/app/assets/images/page_engine/page_line.jpg +0 -0
  17. data/app/assets/images/page_engine/page_red.png +0 -0
  18. data/app/assets/images/page_engine/pencil.png +0 -0
  19. data/app/assets/images/page_engine/waiting.gif +0 -0
  20. data/app/assets/images/page_engine/zoom.png +0 -0
  21. data/app/assets/javascripts/markitup/sets/css/set.js +52 -0
  22. data/app/assets/javascripts/markitup/sets/html/set.js +64 -0
  23. data/app/assets/javascripts/markitup/sets/javascript/set.js +6 -0
  24. data/app/assets/javascripts/markitup/sets/markdown/set.js +53 -0
  25. data/app/assets/javascripts/markitup/sets/textile/set.js +57 -0
  26. data/app/assets/javascripts/page_engine.js +189 -0
  27. data/app/assets/stylesheets/jquery-ui/smoothness/jquery-ui-1.8.15.custom.css +307 -0
  28. data/app/assets/stylesheets/markitup/sets/css/style.css +69 -0
  29. data/app/assets/stylesheets/markitup/sets/html/style.css +58 -0
  30. data/app/assets/stylesheets/markitup/sets/javascript/style.css +0 -0
  31. data/app/assets/stylesheets/markitup/sets/markdown/style.css +49 -0
  32. data/app/assets/stylesheets/markitup/sets/textile/style.css +58 -0
  33. data/app/assets/stylesheets/markitup/skins/markitup/style.css +147 -0
  34. data/app/assets/stylesheets/markitup/skins/simple/style.css +118 -0
  35. data/app/assets/stylesheets/page_engine.css +231 -0
  36. data/app/controllers/admin/page_snippets_controller.rb +64 -0
  37. data/app/controllers/admin/pages_controller.rb +167 -0
  38. data/app/controllers/pages_controller.rb +20 -0
  39. data/app/helpers/pages_helper.rb +234 -0
  40. data/app/models/page.rb +233 -0
  41. data/app/models/page_part.rb +35 -0
  42. data/app/models/page_role.rb +15 -0
  43. data/app/models/page_snippet.rb +30 -0
  44. data/app/views/admin/page_snippets/_form.html.haml +10 -0
  45. data/app/views/admin/page_snippets/destroy.js.erb +3 -0
  46. data/app/views/admin/page_snippets/edit.html.haml +6 -0
  47. data/app/views/admin/page_snippets/index.html.haml +20 -0
  48. data/app/views/admin/page_snippets/new.html.haml +6 -0
  49. data/app/views/admin/page_snippets/show.html.erb +20 -0
  50. data/app/views/admin/pages/_form.html.haml +56 -0
  51. data/app/views/admin/pages/_page.html.haml +19 -0
  52. data/app/views/admin/pages/_page_list.html.haml +2 -0
  53. data/app/views/admin/pages/_page_part_fields.html.haml +9 -0
  54. data/app/views/admin/pages/destroy.js.erb +1 -0
  55. data/app/views/admin/pages/duplicate.js.erb +5 -0
  56. data/app/views/admin/pages/edit.html.haml +9 -0
  57. data/app/views/admin/pages/index.html.haml +10 -0
  58. data/app/views/admin/pages/new.html.haml +10 -0
  59. data/app/views/admin/pages/show.html.erb +100 -0
  60. data/app/views/admin/pages/sort.js.erb +3 -0
  61. data/app/views/layouts/admin.html.haml +20 -0
  62. data/app/views/pages/_nav_item.html.haml +10 -0
  63. data/app/views/pages/_navigation.html.haml +11 -0
  64. data/app/views/pages/index.html.erb +2 -0
  65. data/app/views/pages/show.html.erb +2 -0
  66. data/config/routes.rb +23 -0
  67. data/db/migrate/20110814185929_create_page_engine.rb +77 -0
  68. data/db/seed.rb +8 -0
  69. data/lib/generators/page_engine/page_engine_generator.rb +59 -0
  70. data/lib/page_engine/class_methods.rb +4 -0
  71. data/lib/page_engine/defaults.rb +5 -0
  72. data/lib/page_engine/engine.rb +4 -0
  73. data/lib/page_engine/exceptions.rb +4 -0
  74. data/lib/page_engine/extensions.rb +24 -0
  75. data/lib/page_engine/helpers.rb +10 -0
  76. data/lib/page_engine/instance_methods.rb +82 -0
  77. data/lib/page_engine/routes_finder.rb +23 -0
  78. data/lib/page_engine.rb +41 -0
  79. data/lib/tasks/page_engine_tasks.rake +4 -0
  80. metadata +192 -0
@@ -0,0 +1,147 @@
1
+ /* -------------------------------------------------------------------
2
+ // markItUp! Universal MarkUp Engine, JQuery plugin
3
+ // By Jay Salvat - http://markitup.jaysalvat.com/
4
+ // ------------------------------------------------------------------*/
5
+ .markItUp * {
6
+ margin:0px; padding:0px;
7
+ outline:none;
8
+ }
9
+ .markItUp a:link,
10
+ .markItUp a:visited {
11
+ color:#000;
12
+ text-decoration:none;
13
+ }
14
+ .markItUp {
15
+ width:700px;
16
+ margin:5px 0 5px 0;
17
+ border:5px solid #F5F5F5;
18
+ }
19
+ .markItUpContainer {
20
+ border:1px solid #3C769D;
21
+ background:#FFF url(/assets/markitup/skins/markitup/bg-container.png) repeat-x top left;
22
+ padding:5px 5px 2px 5px;
23
+ font:11px Verdana, Arial, Helvetica, sans-serif;
24
+ }
25
+ .markItUpEditor {
26
+ font:12px 'Courier New', Courier, monospace;
27
+ padding:5px 5px 5px 35px;
28
+ border:3px solid #3C769D;
29
+ width:643px;
30
+ height:320px;
31
+ background:#FFF url(/assets/markitup/skins/markitup/bg-editor.png) no-repeat;
32
+ clear:both;
33
+ line-height:18px;
34
+ overflow:auto;
35
+ }
36
+ .markItUpPreviewFrame {
37
+ overflow:auto;
38
+ background-color:#FFFFFF;
39
+ border:1px solid #3C769D;
40
+ width:99.9%;
41
+ height:300px;
42
+ margin:5px 0;
43
+ }
44
+ .markItUpFooter {
45
+ width:100%;
46
+ cursor:n-resize;
47
+ }
48
+ .markItUpResizeHandle {
49
+ overflow:hidden;
50
+ width:22px; height:5px;
51
+ margin-left:auto;
52
+ margin-right:auto;
53
+ background-image:url(/assets/markitup/skins/markitup/handle.png);
54
+ cursor:n-resize;
55
+ }
56
+ /***************************************************************************************/
57
+ /* first row of buttons */
58
+ .markItUpHeader ul li {
59
+ list-style:none;
60
+ float:left;
61
+ position:relative;
62
+ }
63
+ .markItUpHeader ul li ul{
64
+ display:none;
65
+ }
66
+ .markItUpHeader ul li:hover > ul{
67
+ display:block;
68
+ }
69
+ .markItUpHeader ul .markItUpDropMenu {
70
+ background:transparent url(/assets/markitup/skins/markitup/menu.png) no-repeat 115% 50%;
71
+ margin-right:5px;
72
+ }
73
+ .markItUpHeader ul .markItUpDropMenu li {
74
+ margin-right:0px;
75
+ }
76
+ .markItUpHeader ul .markItUpSeparator {
77
+ margin:0 10px;
78
+ width:1px;
79
+ height:16px;
80
+ overflow:hidden;
81
+ background-color:#CCC;
82
+ }
83
+ .markItUpHeader ul ul .markItUpSeparator {
84
+ width:auto; height:1px;
85
+ margin:0px;
86
+ }
87
+ /* next rows of buttons */
88
+ .markItUpHeader ul ul {
89
+ display:none;
90
+ position:absolute;
91
+ top:18px; left:0px;
92
+ background:#F5F5F5;
93
+ border:1px solid #3C769D;
94
+ height:inherit;
95
+ }
96
+ .markItUpHeader ul ul li {
97
+ float:none;
98
+ border-bottom:1px solid #3C769D;
99
+ }
100
+ .markItUpHeader ul ul .markItUpDropMenu {
101
+ background:#F5F5F5 url(/assets/markitup/skins/markitup/submenu.png) no-repeat 100% 50%;
102
+ }
103
+ /* next rows of buttons */
104
+ .markItUpHeader ul ul ul {
105
+ position:absolute;
106
+ top:-1px; left:150px;
107
+ }
108
+ .markItUpHeader ul ul ul li {
109
+ float:none;
110
+ }
111
+ .markItUpHeader ul a {
112
+ display:block;
113
+ width:16px; height:16px;
114
+ text-indent:-10000px;
115
+ background-repeat:no-repeat;
116
+ padding:3px;
117
+ margin:0px;
118
+ }
119
+ .markItUpHeader ul ul a {
120
+ display:block;
121
+ padding-left:0px;
122
+ text-indent:0;
123
+ width:120px;
124
+ padding:5px 5px 5px 25px;
125
+ background-position:2px 50%;
126
+ }
127
+ .markItUpHeader ul ul a:hover {
128
+ color:#FFF;
129
+ background-color:#3C769D;
130
+ }
131
+ /***************************************************************************************/
132
+ .html .markItUpEditor {
133
+ background-image:url(/assets/markitup/skins/markitup/bg-editor-html.png);
134
+ }
135
+ .markdown .markItUpEditor {
136
+ background-image:url(/assets/markitup/skins/markitup/bg-editor-markdown.png);
137
+ }
138
+ .textile .markItUpEditor {
139
+ background-image:url(/assets/markitup/skins/markitup/bg-editor-textile.png);
140
+ }
141
+ .bbcode .markItUpEditor {
142
+ background-image:url(/assets/markitup/skins/markitup/bg-editor-bbcode.png);
143
+ }
144
+ .wiki .markItUpEditor,
145
+ .dotclear .markItUpEditor {
146
+ background-image:url(/assets/markitup/skins/markitup/bg-editor-wiki.png);
147
+ }
@@ -0,0 +1,118 @@
1
+ /* -------------------------------------------------------------------
2
+ // markItUp! Universal MarkUp Engine, JQuery plugin
3
+ // By Jay Salvat - http://markitup.jaysalvat.com/
4
+ // ------------------------------------------------------------------*/
5
+ .markItUp * {
6
+ margin:0px; padding:0px;
7
+ outline:none;
8
+ }
9
+ .markItUp a:link,
10
+ .markItUp a:visited {
11
+ color:#000;
12
+ text-decoration:none;
13
+ }
14
+ .markItUp {
15
+ width:700px;
16
+ margin:5px 0 5px 0;
17
+ }
18
+ .markItUpContainer {
19
+ font:11px Verdana, Arial, Helvetica, sans-serif;
20
+ }
21
+ .markItUpEditor {
22
+ font:12px 'Courier New', Courier, monospace;
23
+ padding:5px;
24
+ width:690px;
25
+ height:320px;
26
+ clear:both;
27
+ line-height:18px;
28
+ overflow:auto;
29
+ }
30
+ .markItUpPreviewFrame {
31
+ overflow:auto;
32
+ background-color:#FFF;
33
+ width:99.9%;
34
+ height:300px;
35
+ margin:5px 0;
36
+ }
37
+ .markItUpFooter {
38
+ width:100%;
39
+ }
40
+ .markItUpResizeHandle {
41
+ overflow:hidden;
42
+ width:22px; height:5px;
43
+ margin-left:auto;
44
+ margin-right:auto;
45
+ background-image:url(/assets/markitup/skins/simple/handle.png);
46
+ cursor:n-resize;
47
+ }
48
+ /***************************************************************************************/
49
+ /* first row of buttons */
50
+ .markItUpHeader ul li {
51
+ list-style:none;
52
+ float:left;
53
+ position:relative;
54
+ }
55
+ .markItUpHeader ul li:hover > ul{
56
+ display:block;
57
+ }
58
+ .markItUpHeader ul .markItUpDropMenu {
59
+ background:transparent url(/assets/markitup/skins/simple/menu.png) no-repeat 115% 50%;
60
+ margin-right:5px;
61
+ }
62
+ .markItUpHeader ul .markItUpDropMenu li {
63
+ margin-right:0px;
64
+ }
65
+ /* next rows of buttons */
66
+ .markItUpHeader ul ul {
67
+ display:none;
68
+ position:absolute;
69
+ top:18px; left:0px;
70
+ background:#FFF;
71
+ border:1px solid #000;
72
+ }
73
+ .markItUpHeader ul ul li {
74
+ float:none;
75
+ border-bottom:1px solid #000;
76
+ }
77
+ .markItUpHeader ul ul .markItUpDropMenu {
78
+ background:#FFF url(/assets/markitup/skins/simple/submenu.png) no-repeat 100% 50%;
79
+ }
80
+ .markItUpHeader ul .markItUpSeparator {
81
+ margin:0 10px;
82
+ width:1px;
83
+ height:16px;
84
+ overflow:hidden;
85
+ background-color:#CCC;
86
+ }
87
+ .markItUpHeader ul ul .markItUpSeparator {
88
+ width:auto; height:1px;
89
+ margin:0px;
90
+ }
91
+ /* next rows of buttons */
92
+ .markItUpHeader ul ul ul {
93
+ position:absolute;
94
+ top:-1px; left:150px;
95
+ }
96
+ .markItUpHeader ul ul ul li {
97
+ float:none;
98
+ }
99
+ .markItUpHeader ul a {
100
+ display:block;
101
+ width:16px; height:16px;
102
+ text-indent:-10000px;
103
+ background-repeat:no-repeat;
104
+ padding:3px;
105
+ margin:0px;
106
+ }
107
+ .markItUpHeader ul ul a {
108
+ display:block;
109
+ padding-left:0px;
110
+ text-indent:0;
111
+ width:120px;
112
+ padding:5px 5px 5px 25px;
113
+ background-position:2px 50%;
114
+ }
115
+ .markItUpHeader ul ul a:hover {
116
+ color:#FFF;
117
+ background-color:#000;
118
+ }
@@ -0,0 +1,231 @@
1
+ /*
2
+ *= require markitup/skins/simple/style
3
+ *= require markitup/sets/html/style
4
+ *= require markitup/sets/textile/style
5
+ *= require markitup/sets/markdown/style
6
+ *= require markitup/sets/css/style
7
+ *= require markitup/sets/javascript/style
8
+ */
9
+
10
+ .js .hidden {
11
+ display: none;
12
+ }
13
+
14
+ .icon, nav.pagination .first a, nav.pagination .prev a, nav.pagination .next a, nav.pagination .last a {
15
+ display: -moz-inline-box;
16
+ -moz-box-orient: vertical;
17
+ display: inline-block;
18
+ vertical-align: middle;
19
+ *vertical-align: auto;
20
+ height: 16px;
21
+ width: 16px;
22
+ text-indent: -119988px;
23
+ overflow: hidden;
24
+ text-align: left;
25
+ background-image: url(/assets/page_engine/ruby.png);
26
+ background-repeat: no-repeat;
27
+ background-position: 50% 50%;
28
+ vertical-align: middle;
29
+ cursor: pointer;
30
+ background-repeat: no-repeat;
31
+ background-position: center center;
32
+ }
33
+
34
+ .icon, nav.pagination .first a, nav.pagination .prev a, nav.pagination .next a, nav.pagination .last a {
35
+ *display: inline;
36
+ }
37
+
38
+ .icon.add {
39
+ background-image: url(/assets/page_engine/add.png);
40
+ }
41
+
42
+ .icon.delete {
43
+ background-image: url(/assets/page_engine/delete.png);
44
+ }
45
+
46
+ .icon.edit {
47
+ background-image: url(/assets/page_engine/pencil.png);
48
+ }
49
+
50
+ .icon.show {
51
+ background-image: url(/assets/page_engine/zoom.png);
52
+ }
53
+
54
+
55
+ .icon.waiting {
56
+ background-image: url(/assets/page_engine/waiting.gif);
57
+ }
58
+
59
+ form.button_to {
60
+ display: inline;
61
+ }
62
+
63
+ form.button_to * {
64
+ display: inline;
65
+ }
66
+
67
+ ol#page_engine,
68
+ ol#page_engine ol {
69
+ margin: 0;
70
+ padding: 0 0 0 16px;
71
+ border-left: solid white 1px;
72
+ }
73
+
74
+ ol#page_engine li.page {
75
+ background: white;
76
+ }
77
+
78
+ ol#page_engine li.placeholder {
79
+ border: dashed 1px #333;
80
+ }
81
+
82
+ ol#page_engine * {
83
+ list-style: none;
84
+ }
85
+
86
+ ol#page_engine .icon.add {
87
+ margin: 0 0 0 6px;
88
+ background-image: url(/assets/page_engine/page_add.png);
89
+ }
90
+
91
+ ol#page_engine .icon.edit {
92
+ background-image: url(/assets/page_engine/page_edit.png);
93
+ }
94
+
95
+ ol#page_engine .icon.delete {
96
+ background-image: url(/assets/page_engine/page_delete.png);
97
+ }
98
+
99
+ ol#page_engine .icon.duplicate {
100
+ background-image: url(/assets/page_engine/page_copy.png);
101
+ }
102
+
103
+ ol#page_engine .icon.published {
104
+ margin: 0 6px 0 0;
105
+ background-image: url(/assets/page_engine/page_green.png);
106
+ }
107
+
108
+ ol#page_engine .icon.live {
109
+ margin: 0 6px 0 0;
110
+ background-image: url(/assets/page_engine/page_lightning.png);
111
+ }
112
+
113
+ ol#page_engine .icon.draft {
114
+ margin: 0 6px 0 0;
115
+ background-image: url(/assets/page_engine/page_red.png);
116
+ }
117
+
118
+ ol#page_engine .icon.hidden {
119
+ margin: 0 6px 0 0;
120
+ background-image: url(/assets/page_engine/page_hidden.png);
121
+ }
122
+
123
+ ol#page_engine .icon.review {
124
+ margin: 0 6px 0 0;
125
+ background-image: url(/assets/page_engine/page_gear.png);
126
+ }
127
+
128
+ .page_part .delete {
129
+ float: right;
130
+ }
131
+
132
+ .page_part.ui-tabs-panel {
133
+ padding: 5px;
134
+ }
135
+
136
+ .page_part .field textarea {
137
+ width: 98.5%;
138
+ }
139
+
140
+ .tabs li.tab_with_errors {
141
+ background: #CC0000 !important;
142
+ }
143
+
144
+ .tabs li.tab_with_errors a {
145
+ color: white !important;
146
+ }
147
+
148
+ .page_form br {
149
+ display: none;
150
+ }
151
+
152
+ .page_form .field input[type="text"] {
153
+ width: 44.6em;
154
+ }
155
+
156
+ .page_form #new_page_part_name {
157
+ width: 20em;
158
+ }
159
+
160
+ .page_form .field.new_page_part_name {
161
+ text-align: right;
162
+ }
163
+
164
+ .page_form .field.page_part_title label {
165
+ width: 6em;
166
+ display: inline-block;
167
+ text-align: right;
168
+ }
169
+
170
+ .page_form .field.status label,
171
+ .page_form .field.css label,
172
+ .page_form .field.js label,
173
+ .page_form .field.no_publish_window label,
174
+ .page_form .field.publish_from label,
175
+ .page_form .field.publish_to label,
176
+ .page_form .field.controller_action label,
177
+ .page_form .field.url label,
178
+ .page_form .field.display_in_sitemap label,
179
+ .page_form .field.display_in_menu label,
180
+ .page_form .field.menu_css_class label,
181
+ .page_form .field.no_link label,
182
+ .page_form .field.layout label,
183
+ .page_form .field.title label,
184
+ .page_form .field.permalink label,
185
+ .page_form .field.meta_description label,
186
+ .page_form .field.meta_keywords label,
187
+ .page_form .field.page_part_title label,
188
+ .page_form .field.filter label,
189
+ .page_form .field.roles label:first-child {
190
+ padding: 0 10px 0 0;
191
+ width: 10em;
192
+ display: inline-block;
193
+ text-align: right;
194
+ }
195
+
196
+ .page_form .field.page_part_title label,
197
+ .page_form .field.filter label {
198
+ width: 4em;
199
+ }
200
+
201
+ .page_form #page_meta_keywords,
202
+ .page_form #page_meta_description,
203
+ .page_form #page_css,
204
+ .page_form #page_js {
205
+ height: 12em;
206
+ vertical-align: middle;
207
+ width: 49.5em;
208
+ }
209
+
210
+ .page_form .field.roles .roles_list {
211
+ display: inline;
212
+ }
213
+
214
+ form#page_snippet .field.name br,
215
+ form#page_snippet .field.filter br {
216
+ display: none;
217
+ }
218
+
219
+ form#page_snippet .field.name label,
220
+ form#page_snippet .field.filter label {
221
+ display: inline-block;
222
+ width: 80px;
223
+ }
224
+
225
+ form#page_snippet .field.name input[type="text"] {
226
+ width: 645px;
227
+ }
228
+
229
+ form#page_snippet .field.content textarea {
230
+ width: 98.4%;
231
+ }
@@ -0,0 +1,64 @@
1
+ class Admin::PageSnippetsController < ApplicationController
2
+ layout 'admin'
3
+
4
+ def index
5
+ @page_snippets = PageSnippet.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @page_snippets }
10
+ end
11
+ end
12
+
13
+ def new
14
+ @page_snippet = PageSnippet.new
15
+
16
+ respond_to do |format|
17
+ format.html # new.html.erb
18
+ format.xml { render :xml => @page_snippet }
19
+ end
20
+ end
21
+
22
+ def edit
23
+ @page_snippet = PageSnippet.find(params[:id])
24
+ end
25
+
26
+ def create
27
+ @page_snippet = PageSnippet.new(params[:page_snippet])
28
+
29
+ respond_to do |format|
30
+ if @page_snippet.save
31
+ format.html { redirect_to(admin_page_snippets_url, :notice => 'Page snippet was successfully created.') }
32
+ format.xml { render :xml => @page_snippet, :status => :created, :location => @page_snippet }
33
+ else
34
+ format.html { render :action => "new" }
35
+ format.xml { render :xml => @page_snippet.errors, :status => :unprocessable_entity }
36
+ end
37
+ end
38
+ end
39
+
40
+ def update
41
+ @page_snippet = PageSnippet.find(params[:id])
42
+
43
+ respond_to do |format|
44
+ if @page_snippet.update_attributes(params[:page_snippet])
45
+ format.html { redirect_to(admin_page_snippets_url, :notice => 'Page snippet was successfully updated.') }
46
+ format.xml { head :ok }
47
+ else
48
+ format.html { render :action => "edit" }
49
+ format.xml { render :xml => @page_snippet.errors, :status => :unprocessable_entity }
50
+ end
51
+ end
52
+ end
53
+
54
+ def destroy
55
+ @page_snippet = PageSnippet.find(params[:id])
56
+ @page_snippet.destroy
57
+
58
+ respond_to do |format|
59
+ format.html { redirect_to(admin_page_snippets_url) }
60
+ format.xml { head :ok }
61
+ format.js
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,167 @@
1
+ class Admin::PagesController < ApplicationController
2
+ before_filter :get_routes, :except => [:index, :destroy]
3
+ layout 'admin'
4
+
5
+ def index
6
+ @pages = Page.order(:lft).all.group_by(&:parent_id)
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.xml { render :xml => @pages }
11
+ end
12
+ end
13
+
14
+ # GET /pages/1
15
+ # GET /pages/1.xml
16
+ def show
17
+ @page = Page.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @page }
22
+ end
23
+ end
24
+
25
+ # GET /pages/new
26
+ # GET /pages/new.xml
27
+ def new
28
+ @page = Page.new
29
+ Page.page_parts.collect { |page_part| @page.page_parts.build(:title => page_part) }
30
+ @parent = Page.find_by_permalink(params[:page_id])
31
+ @roles = PageEngine.class_exists?('Role') ? Role.all : []
32
+ @page_part_index = 0
33
+
34
+ respond_to do |format|
35
+ format.html # new.html.erb
36
+ format.xml { render :xml => @page }
37
+ end
38
+ end
39
+
40
+ # GET /pages/1/edit
41
+ def edit
42
+ @page = Page.includes([:parent, :page_parts]).where({ :permalink => params[:id] })
43
+ @page = @page.includes(:required_roles) if PageEngine.class_exists?('Role')
44
+ @page = @page.first
45
+ @parent = @page.parent
46
+ @roles = PageEngine.class_exists?('Role') ? Role.all : []
47
+ @page_part_index = 0
48
+ end
49
+
50
+ # POST /pages
51
+ # POST /pages.xml
52
+ def create
53
+ @parent = Page.find_by_permalink(params[:page_id])
54
+ @page = Page.new(params[:page])
55
+
56
+ respond_to do |format|
57
+ if @page.save
58
+
59
+ @page.move_to_child_of @parent unless @parent.nil?
60
+
61
+ return_path = params.has_key?('continue') ? edit_admin_page_path(@page) : admin_pages_path
62
+
63
+ format.html { redirect_to(return_path, :notice => 'Page was successfully created.') }
64
+ format.xml { render :xml => @page, :status => :created, :location => @page }
65
+ else
66
+ @roles = PageEngine.class_exists?('Role') ? Role.all : []
67
+ format.html { render :action => "new" }
68
+ format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
69
+ end
70
+ end
71
+ end
72
+
73
+ # PUT /pages/1
74
+ # PUT /pages/1.xml
75
+ def update
76
+ @page = Page.includes([:parent, :page_parts]).find(params[:the_page_id])
77
+
78
+ if PageEngine.class_exists?('Role')
79
+ params[:page][:required_role_ids] ||= []
80
+ params[:page][:excluded_role_ids] ||= []
81
+ end
82
+
83
+ respond_to do |format|
84
+ if @page.update_attributes(params[:page])
85
+ return_path = params.has_key?('continue') ? edit_admin_page_path(@page) : admin_pages_path
86
+
87
+ format.html { redirect_to(return_path, :notice => 'Page was successfully updated.') }
88
+ format.xml { head :ok }
89
+ else
90
+ @parent = @page.parent
91
+ @roles = PageEngine.class_exists?('Role') ? Role.all : []
92
+ format.html { render :action => "edit" }
93
+ format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
94
+ end
95
+ end
96
+ end
97
+
98
+ # DELETE /pages/1
99
+ # DELETE /pages/1.xml
100
+ def destroy
101
+ @page = Page.find_by_permalink(params[:id])
102
+ @page.move_children_to_parent
103
+ @page.destroy
104
+
105
+ respond_to do |format|
106
+ format.html do
107
+ redirect_to(admin_pages_path)
108
+ end
109
+ format.xml { head :ok }
110
+ format.js do
111
+ @pages = Page.order(:lft).all.group_by(&:parent_id)
112
+ end
113
+ end
114
+ end
115
+
116
+
117
+ def sort
118
+ params[:pages].values.each do |value|
119
+ @page = Page.find_by_id(value[:item_id])
120
+ parent_id = value[:parent_id] == 'root' ? nil : value[:parent_id]
121
+
122
+ @page.parent_id = parent_id
123
+ @page.lft = value[:left].to_i - 1
124
+ @page.rgt = value[:right].to_i - 1
125
+ @page.save
126
+ end
127
+
128
+ render :nothing => true
129
+ end
130
+
131
+ def duplicate
132
+ @original_page = Page.find_by_permalink params[:id], :include => [:page_parts]
133
+ @page = @original_page.duplicate
134
+ @pages = {}
135
+
136
+ respond_to do |format|
137
+ format.html { redirect_to admin_pages_path, :notice => 'Page was successfully duplicated' }
138
+ format.js
139
+ end
140
+ end
141
+
142
+ def parse_content
143
+ case params[:data_type]
144
+ when 'textile'
145
+ render :text => RedCloth.new(params[:data]).to_html
146
+ when 'markdown'
147
+ render :text => BlueCloth.new(params[:data]).to_html
148
+ else
149
+ render :nothing => true
150
+ end
151
+ end
152
+
153
+ private
154
+
155
+ # Retrieve the available routes (:get only) and compile the ones already taken by other pages
156
+ def get_routes
157
+ @current = Page.just_controller_and_actions.collect{ |i| i.taken }.compact
158
+ @routes = {}
159
+
160
+ routes = PageEngine.available_routes
161
+
162
+ routes.keys.each do |controller|
163
+ @routes[controller.humanize] = routes[controller].collect { |action| ["#{controller.humanize}::#{action.humanize}", "#{controller}|#{action}"] }
164
+ end
165
+ end
166
+ end
167
+