darthapo-comatose 2.0

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 (92) hide show
  1. data/CHANGELOG +171 -0
  2. data/INSTALL +19 -0
  3. data/LICENSE +20 -0
  4. data/MANIFEST +91 -0
  5. data/README.rdoc +148 -0
  6. data/Rakefile +122 -0
  7. data/SPECS +61 -0
  8. data/about.yml +7 -0
  9. data/bin/comatose +20 -0
  10. data/generators/comatose_migration/USAGE +15 -0
  11. data/generators/comatose_migration/comatose_migration_generator.rb +59 -0
  12. data/generators/comatose_migration/templates/migration.rb +35 -0
  13. data/generators/comatose_migration/templates/v4_upgrade.rb +15 -0
  14. data/generators/comatose_migration/templates/v6_upgrade.rb +23 -0
  15. data/generators/comatose_migration/templates/v7_upgrade.rb +22 -0
  16. data/init.rb +10 -0
  17. data/install.rb +16 -0
  18. data/lib/acts_as_versioned.rb +543 -0
  19. data/lib/comatose.rb +23 -0
  20. data/lib/comatose/comatose_drop.rb +79 -0
  21. data/lib/comatose/configuration.rb +68 -0
  22. data/lib/comatose/page_wrapper.rb +119 -0
  23. data/lib/comatose/processing_context.rb +69 -0
  24. data/lib/comatose/tasks/admin.rb +60 -0
  25. data/lib/comatose/tasks/data.rb +82 -0
  26. data/lib/comatose/tasks/setup.rb +52 -0
  27. data/lib/comatose/version.rb +4 -0
  28. data/lib/comatose_admin_controller.rb +348 -0
  29. data/lib/comatose_admin_helper.rb +37 -0
  30. data/lib/comatose_controller.rb +141 -0
  31. data/lib/comatose_helper.rb +3 -0
  32. data/lib/comatose_page.rb +141 -0
  33. data/lib/liquid.rb +52 -0
  34. data/lib/liquid/block.rb +96 -0
  35. data/lib/liquid/context.rb +190 -0
  36. data/lib/liquid/document.rb +17 -0
  37. data/lib/liquid/drop.rb +48 -0
  38. data/lib/liquid/errors.rb +7 -0
  39. data/lib/liquid/extensions.rb +53 -0
  40. data/lib/liquid/file_system.rb +62 -0
  41. data/lib/liquid/htmltags.rb +64 -0
  42. data/lib/liquid/standardfilters.rb +111 -0
  43. data/lib/liquid/standardtags.rb +399 -0
  44. data/lib/liquid/strainer.rb +42 -0
  45. data/lib/liquid/tag.rb +25 -0
  46. data/lib/liquid/template.rb +88 -0
  47. data/lib/liquid/variable.rb +39 -0
  48. data/lib/redcloth.rb +1129 -0
  49. data/lib/support/class_options.rb +36 -0
  50. data/lib/support/inline_rendering.rb +48 -0
  51. data/lib/support/route_mapper.rb +50 -0
  52. data/lib/text_filters.rb +138 -0
  53. data/lib/text_filters/markdown.rb +14 -0
  54. data/lib/text_filters/markdown_smartypants.rb +15 -0
  55. data/lib/text_filters/none.rb +8 -0
  56. data/lib/text_filters/rdoc.rb +13 -0
  57. data/lib/text_filters/simple.rb +8 -0
  58. data/lib/text_filters/textile.rb +15 -0
  59. data/rails/init.rb +12 -0
  60. data/resources/layouts/comatose_admin_template.html.erb +28 -0
  61. data/resources/public/images/collapsed.gif +0 -0
  62. data/resources/public/images/expanded.gif +0 -0
  63. data/resources/public/images/no-children.gif +0 -0
  64. data/resources/public/images/page.gif +0 -0
  65. data/resources/public/images/spinner.gif +0 -0
  66. data/resources/public/images/title-hover-bg.gif +0 -0
  67. data/resources/public/javascripts/comatose_admin.js +401 -0
  68. data/resources/public/stylesheets/comatose_admin.css +381 -0
  69. data/tasks/comatose.rake +9 -0
  70. data/test/behaviors.rb +106 -0
  71. data/test/fixtures/comatose_pages.yml +96 -0
  72. data/test/functional/comatose_admin_controller_test.rb +112 -0
  73. data/test/functional/comatose_controller_test.rb +44 -0
  74. data/test/javascripts/test.html +26 -0
  75. data/test/javascripts/test_runner.js +307 -0
  76. data/test/test_helper.rb +43 -0
  77. data/test/unit/class_options_test.rb +52 -0
  78. data/test/unit/comatose_page_test.rb +128 -0
  79. data/test/unit/processing_context_test.rb +108 -0
  80. data/test/unit/text_filters_test.rb +52 -0
  81. data/views/comatose_admin/_form.html.erb +96 -0
  82. data/views/comatose_admin/_page_list_item.html.erb +60 -0
  83. data/views/comatose_admin/delete.html.erb +18 -0
  84. data/views/comatose_admin/edit.html.erb +5 -0
  85. data/views/comatose_admin/index.html.erb +18 -0
  86. data/views/comatose_admin/new.html.erb +5 -0
  87. data/views/comatose_admin/reorder.html.erb +30 -0
  88. data/views/comatose_admin/versions.html.erb +40 -0
  89. data/views/layouts/comatose_admin.html.erb +814 -0
  90. data/views/layouts/comatose_admin_customize.html.erb +28 -0
  91. data/views/layouts/comatose_content.html.erb +17 -0
  92. metadata +157 -0
@@ -0,0 +1,52 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ namespace :comatose do
5
+ #
6
+ # Setup Task...
7
+ #
8
+ namespace :setup do
9
+
10
+ desc "If the installation didn't add the images correctly, use this task"
11
+ task :copy_images do
12
+ plugin_dir = File.join(File.dirname(__FILE__), '..')
13
+ unless FileTest.exist? File.join(RAILS_ROOT, 'public', 'images', 'comatose')
14
+ FileUtils.mkdir( File.join(RAILS_ROOT, 'public', 'images', 'comatose') )
15
+ end
16
+ FileUtils.cp(
17
+ Dir[File.join(plugin_dir, 'resources', 'public', 'images', '*.gif')],
18
+ File.join(RAILS_ROOT, 'public', 'images', 'comatose'),
19
+ :verbose => true
20
+ )
21
+ puts "Finished."
22
+ end
23
+
24
+ # For use when upgrading...
25
+
26
+ def move(args)
27
+ if ENV['USE_SVN'] == 'true'
28
+ `svn move #{args}`
29
+ else
30
+ `mv #{args}`
31
+ end
32
+ end
33
+
34
+ def delete(args)
35
+ if ENV['USE_SVN'] == 'true'
36
+ `svn delete #{args}`
37
+ else
38
+ `rm -rf #{args}`
39
+ end
40
+ end
41
+
42
+ # TODO: Test the setup:restructure_customization task...
43
+ desc "[EXPERIMENTAL] Restructures customized admin folder to version 0.6 from older version -- Only run this if you have customized the admin. USE_SVN=true if you want to update subversion"
44
+ task :restructure_customization do
45
+ ENV['USE_SVN'] ||= 'false'
46
+ move 'public/javscripts/comatose.js public/javscripts/comatose_admin.js'
47
+ move 'public/stylesheets/comatose.css public/stylesheets/comatose_admin.css'
48
+ move 'app/views/comatose app/views/comatose_admin'
49
+ delete 'app/views/layouts/comatose_content.html.erb'
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,4 @@
1
+ module Comatose
2
+ VERSION = "2.0"
3
+ VERSION_STRING = "#{VERSION} (uber-alpha)"
4
+ end
@@ -0,0 +1,348 @@
1
+ # The controller for serving cms content...
2
+ class ComatoseAdminController < ActionController::Base
3
+
4
+ define_option :original_template_root, nil
5
+ define_option :plugin_layout_path, File.join( '..', '..', '..', 'vendor', 'plugins', 'comatose', 'views', 'layouts' )
6
+
7
+ before_filter :handle_authorization
8
+ before_filter :set_content_type
9
+ layout 'comatose_admin'
10
+
11
+ # Shows the page tree
12
+ def index
13
+ @root_pages = [fetch_root_page].flatten
14
+ end
15
+
16
+ # Edit a specfic page (posts back)
17
+ def edit
18
+ # Clear the page cache for this page... ?
19
+ @page = ComatosePage.find params[:id]
20
+ @root_pages = [fetch_root_page].flatten
21
+ if request.post?
22
+ @page.update_attributes(params[:page])
23
+ @page.updated_on = Time.now
24
+ @page.author = fetch_author_name
25
+ if @page.save
26
+ expire_cms_page @page
27
+ expire_cms_fragment @page
28
+ flash[:notice] = "Saved changes to '#{@page.title}'"
29
+ redirect_to :controller=>self.controller_name, :action=>'index'
30
+ end
31
+ end
32
+ end
33
+
34
+ # Create a new page (posts back)
35
+ def new
36
+ @root_pages = [fetch_root_page].flatten
37
+ if request.post?
38
+ @page = ComatosePage.new params[:page]
39
+ @page.author = fetch_author_name
40
+ if @page.save
41
+ flash[:notice] = "Created page '#{@page.title}'"
42
+ redirect_to :controller=>self.controller_name, :action=>'index'
43
+ end
44
+ else
45
+ @page = ComatosePage.new :title=>'New Page', :parent_id=>(params[:parent] || nil)
46
+ end
47
+ end
48
+
49
+ # Saves position of child pages
50
+ def reorder
51
+ # If it's AJAX, do our thing and move on...
52
+ if request.xhr?
53
+ params["page_list_#{params[:id]}"].each_with_index { |id,idx| ComatosePage.update(id, :position => idx) }
54
+ expire_cms_page ComatosePage.find(params[:id])
55
+ render :text=>'Updated sort order', :layout=>false
56
+ else
57
+ @page = ComatosePage.find params[:id]
58
+ if params.has_key? :cmd
59
+ @target = ComatosePage.find params[:page]
60
+ case params[:cmd]
61
+ when 'up' then @target.move_higher
62
+ when 'down' then @target.move_lower
63
+ end
64
+ redirect_to :action=>'reorder', :id=>@page
65
+ end
66
+ end
67
+ end
68
+
69
+ # Allows comparing between two versions of a page's content
70
+ def versions
71
+ @page = ComatosePage.find params[:id]
72
+ @version_num = (params[:version] || @page.versions.length).to_i
73
+ @version = @page.find_version(@version_num)
74
+ end
75
+
76
+ # Reverts a page to a specific version...
77
+ def set_version
78
+ if request.post?
79
+ @page = ComatosePage.find params[:id]
80
+ @version_num = params[:version]
81
+ @page.revert_to!(@version_num)
82
+ end
83
+ redirect_to :controller=>self.controller_name, :action=>'index'
84
+ end
85
+
86
+ # Deletes the specified page
87
+ def delete
88
+ @page = ComatosePage.find params[:id]
89
+ if request.post?
90
+ expire_cms_pages_from_bottom @page
91
+ expire_cms_fragments_from_bottom @page
92
+ @page.destroy
93
+ flash[:notice] = "Deleted page '#{@page.title}'"
94
+ redirect_to :controller=>self.controller_name, :action=>'index'
95
+ end
96
+ end
97
+
98
+ # Returns a preview of the page content...
99
+ def preview
100
+ begin
101
+ page = ComatosePage.new(params[:page])
102
+ page.author = fetch_author_name
103
+ if params.has_key? :version
104
+ content = page.to_html( {'params'=>params.stringify_keys, 'version'=>params[:version]} )
105
+ else
106
+ content = page.to_html( {'params'=>params.stringify_keys} )
107
+ end
108
+ rescue SyntaxError
109
+ content = "<p>There was an error generating the preview.</p><p><pre>#{$!.to_s.gsub(/\</, '&lt;')}</pre></p>"
110
+ rescue
111
+ content = "<p>There was an error generating the preview.</p><p><pre>#{$!.to_s.gsub(/\</, '&lt;')}</pre></p>"
112
+ end
113
+ render :text=>content, :layout => false
114
+ end
115
+
116
+ # Expires the entire page cache
117
+ def expire_page_cache
118
+ expire_cms_pages_from_bottom( fetch_root_page )
119
+ expire_cms_fragments_from_bottom( fetch_root_page )
120
+ flash[:notice] = "Page cache has been flushed"
121
+ redirect_to :controller=>self.controller_name, :action=>'index'
122
+ end
123
+
124
+ # Walks the page tree and generates HTML files in your /public
125
+ # folder... It will skip pages that have a 'nocache' keyword
126
+ # TODO: Make page cache generation work when in :plugin mode
127
+ def generate_page_cache
128
+ if runtime_mode == :plugin
129
+ @errors = ["Page cache cannot be generated in plugin mode"]
130
+ else
131
+ @errors = generate_all_pages_html(params)
132
+ end
133
+ if @errors.length == 0
134
+ flash[:notice] = "Pages Cached Successfully"
135
+ else
136
+ flash[:notice] = "Pages Cache Error(s): #{@errors.join(', ')}"
137
+ flash[:cache_errors] = @errors
138
+ end
139
+ redirect_to :controller=>self.controller_name, :action=>'index'
140
+ end
141
+
142
+
143
+ protected
144
+
145
+ def handle_authorization
146
+ if Comatose.config.admin_authorization.is_a? Proc
147
+ instance_eval &Comatose.config.admin_authorization
148
+ elsif Comatose.config.admin_authorization.is_a? Symbol
149
+ send(Comatose.config.admin_authorization)
150
+ elsif defined? authorize
151
+ authorize
152
+ else
153
+ true
154
+ end
155
+ end
156
+
157
+ def fetch_author_name
158
+ if Comatose.config.admin_get_author.is_a? Proc
159
+ instance_eval &Comatose.config.admin_get_author
160
+ elsif Comatose.config.admin_get_author.is_a? Symbol
161
+ send(Comatose.config.admin_get_author)
162
+ elsif defined? get_author
163
+ get_author
164
+ end
165
+ end
166
+
167
+ # Can be overridden -- return your root comtase page
168
+ def fetch_root_page
169
+ if Comatose.config.admin_get_root_page.is_a? Proc
170
+ instance_eval &Comatose.config.admin_get_root_page
171
+ elsif Comatose.config.admin_get_root_page.is_a? Symbol
172
+ send(Comatose.config.admin_get_root_page)
173
+ elsif defined? get_root_page
174
+ get_root_page
175
+ end
176
+ end
177
+
178
+ # Sets the HTTP content-type header based on what's configured
179
+ # in Comatose.config.content_type
180
+ def set_content_type
181
+ response.headers["Content-Type"] = "text/html; charset=#{Comatose.config.content_type}" unless Comatose.config.content_type.nil?
182
+ end
183
+
184
+ # Calls generate_page_html for each mount point..
185
+ def generate_all_pages_html(params={})
186
+ @errors = []
187
+ @been_cached = []
188
+ Comatose.mount_points.each do |root_info|
189
+ ComatosePage.active_mount_info = root_info
190
+ generate_page_html(ComatosePage.find_by_path( root_info[:index] ), root_info, params)
191
+ end
192
+ @errors
193
+ end
194
+
195
+ # Accepts a Comatose Page and a root_info object to generate
196
+ # the page as a static HTML page -- using the layout that was
197
+ # defined on the mount point
198
+ def generate_page_html(page, root_info, params={})
199
+ @been_cached ||= []
200
+ unless page.has_keyword? :nocache or @been_cached.include? page.id
201
+ uri = page.uri
202
+ uri = "#{uri}/index".split('/').flatten.join('/') if page.full_path == root_info[:index]
203
+ @page = Comatose::PageWrapper.new(page)
204
+ begin
205
+ page_layout = get_page_layout(root_info)
206
+ #puts "mode = #{runtime_mode}, layout = #{page_layout}, template_root = #{template_root}, original_template_root = #{original_template_root}"
207
+ html = render_to_string( :text=>page.to_html({'params'=>params.stringify_keys}), :layout=>page_layout )
208
+ cache_page( html, uri )
209
+ rescue
210
+ logger.error "Comatose CMS Page Cache Exception: #{$!}"
211
+ @errors << "(#{page}/#{page.slug}) - #{$!}"
212
+ end
213
+ @been_cached << page.id
214
+ # recurse...
215
+ page.children.each do |child|
216
+ generate_page_html(child, root_info)
217
+ end
218
+ end
219
+ end
220
+
221
+ # Calls the class methods of the same name...
222
+ def expire_cms_page(page)
223
+ self.class.expire_cms_page(page)
224
+ end
225
+ def expire_cms_pages_from_bottom(page)
226
+ self.class.expire_cms_pages_from_bottom(page)
227
+ end
228
+
229
+
230
+ # expire the page from the fragment cache
231
+ def expire_cms_fragment(page)
232
+ key = page.full_path.gsub(/\//, '+')
233
+ expire_fragment(key)
234
+ end
235
+
236
+ # expire pages starting at a specific node
237
+ def expire_cms_fragments_from_bottom(page)
238
+ pages = page.is_a?(Array) ? page : [page]
239
+ pages.each do |page|
240
+ page.children.each {|c| expire_cms_fragments_from_bottom( c ) } if !page.children.empty?
241
+ expire_cms_fragment( page )
242
+ end
243
+ end
244
+
245
+ # Class Methods...
246
+ class << self
247
+
248
+ # Walks all the way down, and back up the tree -- the allows the expire_cms_page
249
+ # to delete empty directories better
250
+ def expire_cms_pages_from_bottom(page)
251
+ pages = page.is_a?(Array) ? page : [page]
252
+ pages.each do |page|
253
+ page.children.each {|c| expire_cms_pages_from_bottom( c ) } if !page.children.empty?
254
+ expire_cms_page( page )
255
+ end
256
+ end
257
+
258
+ # Expire the page from all the mount points...
259
+ def expire_cms_page(page)
260
+ Comatose.mount_points.each do |path_info|
261
+ ComatosePage.active_mount_info = path_info
262
+ expire_page(page.uri)
263
+ # If the page is the index page for the root, expire it too
264
+ if path_info[:root] == page.uri
265
+ expire_page("#{path_info[:root]}/index")
266
+ end
267
+ begin # I'm not sure this matters too much -- but it keeps things clean
268
+ dir_path = File.join(RAILS_ROOT, 'public', page.uri[1..-1])
269
+ Dir.delete( dir_path ) if FileTest.directory?( dir_path ) and !page.parent.nil?
270
+ rescue
271
+ # It probably isn't empty -- just as well we leave it be
272
+ #STDERR.puts " - Couldn't delete dir #{dir_path} -> #{$!}"
273
+ end
274
+ end
275
+ end
276
+
277
+ # Returns a path to plugin layout, if it's unspecified, otherwise
278
+ # a path to an application layout...
279
+ def get_page_layout(params)
280
+ if params[:layout] == 'comatose_content'
281
+ File.join(plugin_layout_path, params[:layout])
282
+ else
283
+ params[:layout]
284
+ end
285
+ end
286
+
287
+ def configure_template_root
288
+ if self.runtime_mode == :unknown
289
+ if FileTest.exist? File.join(RAILS_ROOT, 'public', 'javascripts', 'comatose_admin.js')
290
+ self.runtime_mode = :application
291
+ else
292
+ self.runtime_mode = :plugin
293
+ end
294
+ end
295
+ end
296
+
297
+ def runtime_mode
298
+ @@runtime_mode ||= :unknown
299
+ end
300
+
301
+ def runtime_mode=(mode)
302
+ admin_view_path = File.expand_path(File.join( File.dirname(__FILE__), '..', 'views'))
303
+ if self.respond_to?(:template_root)
304
+ case mode
305
+ when :plugin
306
+ self.original_template_root = self.template_root
307
+ self.template_root = admin_view_path
308
+ when :application
309
+ self.template_root = self.original_template_root if self.original_template_root
310
+ end
311
+ else
312
+ ActionController::Base.append_view_path(admin_view_path) unless ActionController::Base.view_paths.include?(admin_view_path)
313
+ end
314
+ @@runtime_mode = mode
315
+ end
316
+
317
+ end
318
+
319
+ # Check to see if we are in 'embedded' mode, or are being 'customized'
320
+ # embedded = runtime_mode of :plugin
321
+ # customized = runtime_mode of :application
322
+ configure_template_root
323
+
324
+ #
325
+ # Include any modules...
326
+ Comatose.config.admin_includes.each do |mod|
327
+ if mod.is_a? String
328
+ include mod.constantize
329
+ elsif mod.is_a? Symbol
330
+ include mod.to_s.classify.constantize
331
+ else
332
+ include mod
333
+ end
334
+ end
335
+
336
+ # Include any helpers...
337
+ Comatose.config.admin_helpers.each do |mod|
338
+ if mod.is_a? String
339
+ helper mod.constantize
340
+ elsif mod.is_a? Symbol
341
+ helper mod.to_s.classify.constantize
342
+ else
343
+ helper mod
344
+ end
345
+ end
346
+
347
+
348
+ end
@@ -0,0 +1,37 @@
1
+ module ComatoseAdminHelper
2
+
3
+ # Checks the hidden_meta_fields class variable for a specified field name...
4
+ def show_field?(key)
5
+ !Comatose.config.hidden_meta_fields.include? key
6
+ end
7
+
8
+ # Used in the Page Form to build an indented drop-down list of pages
9
+ def tree_select_box(nodes, selected= nil, hide= nil, label="Parent", add_initial=false)
10
+ level = 0
11
+ select_box = add_initial ? "<option value=0>No #{label}</option>\n" : ""
12
+ selected = nodes[0].id if selected.nil? and not add_initial
13
+ nodes.each {|node| select_box += add_select_tree_node(node, selected, level, hide) }
14
+ select_box += ''
15
+ end
16
+ # Called by tree_select_box
17
+ def add_select_tree_node(node, selected, level, hide)
18
+ padding = "&nbsp;" * level * 4
19
+ padding += '&raquo; ' unless level==0
20
+ hide_values = Array.new
21
+ hide_values << hide if hide
22
+ if node.id == selected
23
+ select_box = %Q|<option value="#{node.id}" selected="true">#{padding}#{node.title}</option>\n|
24
+ else
25
+ if hide_values.include?(node.id)
26
+ select_box = ''
27
+ else
28
+ select_box = %Q|<option value="#{node.id}">#{padding}#{node.title}</option>\n|
29
+ end
30
+ end
31
+ node.children.each do |child|
32
+ select_box += add_select_tree_node(child, selected, level + 1, hide) unless hide_values.include?(node.id)
33
+ end
34
+ select_box
35
+ end
36
+
37
+ end
@@ -0,0 +1,141 @@
1
+ # The controller for serving cms content...
2
+ class ComatoseController < ActionController::Base
3
+
4
+ before_filter :handle_authorization, :set_content_type
5
+ after_filter :cache_cms_page
6
+
7
+ # Render a specific page
8
+ def show
9
+ page_name, page_ext = get_page_path
10
+ page = ComatosePage.find_by_path( page_name )
11
+ status = nil
12
+ if page.nil?
13
+ page = ComatosePage.find_by_path( '404' )
14
+ status = 404
15
+ end
16
+ # if it's still nil, well, send a 404 status
17
+ if page.nil?
18
+ render :nothing=>true, :status=>status
19
+ #raise ActiveRecord::RecordNotFound.new("Comatose page not found ")
20
+ else
21
+ # Make the page access 'safe'
22
+ @page = Comatose::PageWrapper.new(page)
23
+ # For accurate uri creation, tell the page class which is the active mount point...
24
+ ComatosePage.active_mount_info = get_active_mount_point(params[:index])
25
+ render :text=>page.to_html({'params'=>params.stringify_keys}), :layout=>get_page_layout, :status=>status
26
+ end
27
+ end
28
+
29
+ protected
30
+
31
+ def handle_authorization
32
+ if Comatose.config.authorization.is_a? Proc
33
+ instance_eval &Comatose.config.authorization
34
+ elsif Comatose.config.authorization.is_a? Symbol
35
+ send(Comatose.config.authorization)
36
+ elsif defined? authorize
37
+ authorize
38
+ else
39
+ true
40
+ end
41
+ end
42
+
43
+ def allow_page_cache?
44
+ # You should have access to the @page being rendered
45
+ true
46
+ end
47
+
48
+ # For use in the #show method... determines the current mount point
49
+ def get_active_mount_point( index )
50
+ Comatose.mount_points.each do |path_info|
51
+ if path_info[:index] == index
52
+ return path_info
53
+ end
54
+ end
55
+ {:root=>"", :index=>index}
56
+ end
57
+
58
+ # For use in the #show method... determines the current page path
59
+ def get_page_path
60
+
61
+ #in rails 2.0, params[:page] comes back as just an Array, so to_s doesn't do join('/')
62
+ if params[:page].is_a? Array
63
+ page_name = params[:page].join("/")
64
+ #in rails 1.x, params[:page] comes back as ActionController::Routing::PathSegment::Result
65
+ elsif params[:page].is_a? ActionController::Routing::PathSegment::Result
66
+ page_name = params[:page].to_s
67
+ else
68
+ logger.debug "get_page_path - params[:page] is an unrecognized type, may cause problems: #{params[:page].class}"
69
+ page_name = params[:page].to_s
70
+ end
71
+
72
+ page_ext = page_name.split('.')[1] unless page_name.empty?
73
+ # TODO: Automatic support for page RSS feeds... ????
74
+ if page_name.nil? or page_name.empty?
75
+ page_name = params[:index]
76
+ params[:cache_path] = "#{request.request_uri}/index"
77
+ elsif !params[:index].empty?
78
+ page_name = "#{params[:index]}/#{page_name}"
79
+ end
80
+ return page_name, page_ext
81
+ end
82
+
83
+ # Returns a path to plugin layout, if it's unspecified, otherwise
84
+ # a path to an application layout...
85
+ def get_page_layout
86
+ if params[:layout] == 'comatose_content'
87
+ File.join(plugin_layout_path, params[:layout])
88
+ else
89
+ params[:layout]
90
+ end
91
+ end
92
+
93
+ # An after_filter implementing page caching if it's enabled, globally,
94
+ # and is allowed by #allow_page_cache?
95
+ def cache_cms_page
96
+ unless Comatose.config.disable_caching or response.headers['Status'] == '404 Not Found'
97
+ return unless params[:use_cache].to_s == 'true' and allow_page_cache?
98
+ path = params[:cache_path] || request.request_uri
99
+ begin
100
+ # TODO: Don't cache pages rendering '404' content...
101
+ self.class.cache_page( response.body, path )
102
+ rescue
103
+ logger.error "Comatose CMS Page Cache Exception: #{$!}"
104
+ end
105
+ end
106
+ end
107
+
108
+ # An after_filter that sets the HTTP header for Content-Type to
109
+ # what's defined in Comatose.config.content_type. Defaults to utf-8.
110
+ def set_content_type
111
+ response.headers["Content-Type"] = "text/html; charset=#{Comatose.config.content_type}" unless Comatose.config.content_type.nil? or response.headers['Status'] == '404 Not Found'
112
+ end
113
+
114
+ # Path to layouts within the plugin... Assumes the plugin directory name is 'comatose'
115
+ define_option :plugin_layout_path, File.join( '..', '..', '..', 'vendor', 'plugins', 'comatose', 'views', 'layouts' )
116
+
117
+ # Include any, well, includes...
118
+ Comatose.config.includes.each do |mod|
119
+ mod_klass = if mod.is_a? String
120
+ mod.constantize
121
+ elsif mod.is_a? Symbol
122
+ mod.to_s.classify.constantize
123
+ else
124
+ mod
125
+ end
126
+ include mod_klass
127
+ end
128
+
129
+ # Include any helpers...
130
+ Comatose.config.helpers.each do |mod|
131
+ mod_klass = if mod.is_a? String
132
+ mod.constantize
133
+ elsif mod.is_a? Symbol
134
+ mod.to_s.classify.constantize
135
+ else
136
+ mod
137
+ end
138
+ helper mod_klass
139
+ end
140
+ end
141
+