Navigation Menu

Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
allow for things like footer sections via a special/ path in pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Nov 24, 2008
1 parent 5bfc106 commit 0e79dd3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
3 changes: 0 additions & 3 deletions app/controllers/admin/pages_controller.rb
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/page_helper.rb
Expand Up @@ -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
25 changes: 25 additions & 0 deletions app/models/page.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions 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 -%>
6 changes: 1 addition & 5 deletions app/views/content/page.html.erb
@@ -1,8 +1,4 @@
<% if @page.display_title %>
<h2><%= @page.full_title %></h2>
<% 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 %>
5 changes: 1 addition & 4 deletions app/views/page/_footer.html.erb
@@ -1,6 +1,3 @@
<div id="footer">
<a href="/pages/home">Home</a> | <a href="/pages/contact_us">Contact Us</a> | <a href="http://isotope11.selfip.com:11000/public_tickets/new" >Open a Trouble Ticket</a> | <a href="/pages/about_us">About Us</a> | <a href="/pages/payments">Make Payment</a> | <a href="/pages/site_map">Site Map</a><br/>
<br/>
&copy;2008 Isotope 11 | 600 Beacon Parkway West, Suite 950 | Birmingham, AL 35209<br/>
Office: 205.795.2551 | Fax: 205.795.2553 | Email: <a href="mailto:info@isotope11.com" class="">info@isotope11.com</a>
<%= render_special 'footer' %>
</div>

0 comments on commit 0e79dd3

Please sign in to comment.