diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index a6a3059..9f1fb85 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -50,9 +50,6 @@ def new def create @page.name = @page.name.gsub(' ', '_') - unless current_user.can_publish? - @page.published = false - end if @page.save attach_page_plugins message = 'Page Added Successfully' diff --git a/app/helpers/page_helper.rb b/app/helpers/page_helper.rb index 0bff317..816208f 100644 --- a/app/helpers/page_helper.rb +++ b/app/helpers/page_helper.rb @@ -25,4 +25,10 @@ def page_controls(page, options = {}) buffer << label.join if label buffer.join(options[:separator]) end + + def render_special(name) + # TODO: this needs to be cached + page = Page.find_or_create_page_by_path("special/#{name}") + render :partial => 'content/page', :object => page + end end diff --git a/app/models/page.rb b/app/models/page.rb index 84046de..2dd90bb 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -162,6 +162,31 @@ def self.find_page_by_path(path) page.split_page! end + def self.find_or_create_page_by_path(path) + ary = path.split('/') + page = find_page_by_path(ary) + return page if page + # if it doesn't exist, create the path that it's supposed to exist at + page = nil + paths = [] + ary.each_with_index do |entry, i| + paths << ary[0..i] + end + paths.each_with_index do |the_path, i| + # get the parent + unless i == 0 + parent = find_page_by_path(paths[i-1]) + end + # create it if it doesn't exist + unless page = find_page_by_path(the_path) + name = the_path.last + page = Page.new(:name => name, :title => name, :full_title => name, :parent_id => (parent ? parent.id : Page.root.id)) + page.save + end + end + page + end + # Get the last page in the tree def last_page parent_id = self.parent_id.to_s diff --git a/app/views/content/_page.html.erb b/app/views/content/_page.html.erb new file mode 100644 index 0000000..37e2333 --- /dev/null +++ b/app/views/content/_page.html.erb @@ -0,0 +1,5 @@ +<% if page.page_plugins.any? -%> + <% page.page_plugins.each do |plugin| -%> + <%= render :partial => plugin.module_class.view_partial, :locals => { :plugin_module => plugin.module } -%> + <% end -%> +<% end -%> diff --git a/app/views/content/page.html.erb b/app/views/content/page.html.erb index e136b3c..ef45a3e 100644 --- a/app/views/content/page.html.erb +++ b/app/views/content/page.html.erb @@ -1,8 +1,4 @@ <% if @page.display_title %>

<%= @page.full_title %>

<% end %> -<% if @page.page_plugins.any? -%> - <% @page.page_plugins.each do |plugin| -%> - <%= render :partial => plugin.module_class.view_partial, :locals => { :plugin_module => plugin.module } -%> - <% end -%> -<% end -%> +<%= render :partial => 'content/page', :object => @page %> diff --git a/app/views/page/_footer.html.erb b/app/views/page/_footer.html.erb index 52b5041..2a2088e 100644 --- a/app/views/page/_footer.html.erb +++ b/app/views/page/_footer.html.erb @@ -1,6 +1,3 @@