summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-02-12 21:33:39 -0800
committerelijah <elijah@riseup.net>2013-02-12 21:33:39 -0800
commit71ec0edea3f87fb69222dbb6fe025c2211402ca2 (patch)
tree5490323e8686df14165ccf5f37fa2d691fc99b88 /app
parent00c785b728c5d97335b87e3eb7d10b9ad0c46d35 (diff)
added capacity for pulling static pages from multiple directory source trees.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb34
-rw-r--r--app/controllers/pages_controller.rb4
-rw-r--r--app/helpers/application_helper.rb8
-rw-r--r--app/helpers/blog_helper.rb4
-rw-r--r--app/helpers/navigation_helper.rb37
-rw-r--r--app/views/layouts/_topnav.html.haml8
-rw-r--r--app/views/layouts/application.html.haml2
7 files changed, 56 insertions, 41 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index da6cf3e..b2c5762 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -3,6 +3,10 @@ class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale, :initialize_pages
+ class << self
+ attr_accessor :current_site # a class instance variable
+ end
+
if Rails.env.production?
rescue_from Exception, :with => :render_500
rescue_from ActionController::RoutingError, :with => :render_404
@@ -81,25 +85,31 @@ class ApplicationController < ActionController::Base
helper_method :page_body
##
- ## INITIALIZATION
+ ## SITE
##
#
- # run every time in development mode, run once in production mode
+ # if we ever make this code support multiple sites, this should depend on the request's domain
#
- def initialize_pages
- run_once(:initialize_pages, :unless => Rails.env.development?) do
- StaticPage.load(PAGE_DIRECTORY)
- Menu.load(PAGE_DIRECTORY + '/menu.txt')
- end
+ def site
+ self.class.current_site ||= Site.new
end
+ helper_method :site
- def run_once(name, options={})
- key_name = "run_once_#{name}"
- if !Thread.current[key_name] || options[:unless]
- yield
+ def initialize_pages
+ if Rails.env.development?
+ site.load_pages
+ else
+ site.reload_pages_if_needed
end
- Thread.current[key_name] = true
end
+ #def run_once(name, options={})
+ # key_name = "run_once_#{name}"
+ # if !Thread.current[key_name] || options[:unless]
+ # yield
+ # end
+ # Thread.current[key_name] = true
+ #end
+
end
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index d4fa09a..36c733b 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -7,7 +7,7 @@ class PagesController < ApplicationController
rescue_from PageNotFound, :with => :render_404
def show
- @page = StaticPage.find(params[:page])
+ @page = site.find_pages(params[:page])
if @page
respond_to do |format|
format.atom { render_atom_feed(@page) }
@@ -21,7 +21,7 @@ class PagesController < ApplicationController
protected
def choose_layout
- if @page && @page.props.layout
+ if @page && @page.props && @page.props.layout
@page.props.layout
else
'application'
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b5bb657..2933bd1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -33,7 +33,7 @@ module ApplicationHelper
if name.starts_with?('#') || name.starts_with?('http')
path = name
else
- page = StaticPage.find(name)
+ page = site.find_page(name)
if page
label ||= page.title
path = page_path(page)
@@ -69,7 +69,11 @@ module ApplicationHelper
def page_title
if @page
- @page.props.title || @page.title
+ if @page.props
+ @page.props.title || @page.title
+ else
+ @page.title
+ end
else
""
end
diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb
index 42e6f9c..2fc6b85 100644
--- a/app/helpers/blog_helper.rb
+++ b/app/helpers/blog_helper.rb
@@ -1,9 +1,9 @@
module BlogHelper
def recent_blog_summaries(path)
- root = StaticPage.find(path)
+ root = site.find_page(path)
if root
- pages = root.all_children.order_by(:posted_at, :direction => :desc).limit(PAGINATION_SIZE)
+ pages = root.all_children.order_by(:posted_at, :direction => :desc).limit(site.pagination_size)
haml do
pages.each do |page|
haml render(:partial => 'layouts/blog/summary', :locals => {:page => page})
diff --git a/app/helpers/navigation_helper.rb b/app/helpers/navigation_helper.rb
index 8582391..a43eecd 100644
--- a/app/helpers/navigation_helper.rb
+++ b/app/helpers/navigation_helper.rb
@@ -1,18 +1,21 @@
module NavigationHelper
def has_side_column?
- second_level_children_count = Menu.menu.submenu(current_page_path.first).try(:size)
+ if root_page?
+ return false
+ end
+ second_level_children_count = site.menu.submenu(current_page_path.first).try(:size)
if second_level_children_count.nil?
false
else
- second_level_children_count > 1
+ second_level_children_count >= 1
end
end
def top_level_navigation_links
haml do
first = 'first'
- Menu.menu.each do |item|
+ site.menu.each do |item|
active = current_page_path.first == item.name ? 'active' : ''
haml 'li.tab', :class => first do
haml 'a.tab', I18n.t('pages.' + item.name), :href => menu_item_path(item), :class => active
@@ -23,7 +26,7 @@ module NavigationHelper
end
def side_column_navigation_links
- if menu = Menu.menu.submenu(current_page_path.first)
+ if menu = site.menu.submenu(current_page_path.first)
haml do
haml 'ul.nav.nav-tabs.nav-stacked' do
display_menu(menu, 1)
@@ -33,7 +36,7 @@ module NavigationHelper
end
def act_as(page)
- page = StaticPage.find(page)
+ page = site.find_page(page)
@current_page_path = page.path
render_page(page)
end
@@ -54,7 +57,17 @@ module NavigationHelper
end
def path_active(page_path, menu_item)
- array_starts_with(page_path, menu_item.path) ? 'active' : ''
+ active = ''
+ if menu_item.path == page_path
+ active = 'active'
+ elsif menu_item.path_prefix_of?(page_path)
+ if menu_item.leaf_for_path?(page_path)
+ active = 'active'
+ else
+ active = 'semi-active'
+ end
+ end
+ active
end
def current_page_path
@@ -70,15 +83,11 @@ module NavigationHelper
end
#
- # returns true if first part of array_long contains array_short
+ # the usage of 'home' as the default root page is hardcoded right now in the routes.
+ # this should be changed in the future.
#
- def array_starts_with(array_long, array_short)
- array_short.length.times do |i|
- if array_short[i] != array_long[i]
- return false
- end
- end
- return true
+ def root_page?
+ @page && @page.path == ['home']
end
end
diff --git a/app/views/layouts/_topnav.html.haml b/app/views/layouts/_topnav.html.haml
deleted file mode 100644
index d0d553e..0000000
--- a/app/views/layouts/_topnav.html.haml
+++ /dev/null
@@ -1,8 +0,0 @@
-%ul#topnav
- = top_level_navigation_links
- %li.tab.first
- %a.tab{:href => '#'} Home
- %li.tab
- %a.tab.active{:href => '#'} Technology
- %li.tab
- %a.tab About Us \ No newline at end of file
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index fe0888a..3d28f38 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -1,7 +1,7 @@
!!! 5
%html{:dir=>'ltr'}
%head
- %title #{SITE_TITLE} - #{page_title}
+ %title #{site.title} - #{page_title}
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags