Skip to content

Commit

Permalink
Add Pages for managing static content and use to replace hard-coded F…
Browse files Browse the repository at this point in the history
…AQ and About pages.
  • Loading branch information
Errol Siegel committed Aug 26, 2009
1 parent c50327e commit b6d0c7b
Show file tree
Hide file tree
Showing 34 changed files with 526 additions and 84 deletions.
6 changes: 0 additions & 6 deletions app/controllers/base_controller.rb
Expand Up @@ -61,15 +61,9 @@ def homepage_features
render :partial => 'homepage_feature', :collection => @homepage_features and return
end

def about
end

def advertise
end

def faq
end

def css_help
end

Expand Down
33 changes: 33 additions & 0 deletions app/controllers/page_sweeper.rb
@@ -0,0 +1,33 @@
class PageSweeper < ActionController::Caching::Sweeper
observe Page # This sweeper is going to keep an eye on the Page model

# If our sweeper detects that a Page was created call this
def after_create(page)
expire_cache_for(page)
end

# If our sweeper detects that a Page was updated call this
def after_update(page)
expire_cache_for(page)
end

# If our sweeper detects that a Page was deleted call this
def after_destroy(page)
expire_cache_for(page)
end

private
def expire_cache_for(record)
# Expire the home page
expire_action(:controller => 'base', :action => 'site_index')

# Expire the footer content
expire_action(:controller => 'base', :action => 'footer_content')

# Also expire the sitemap
expire_action(:controller => 'sitemap', :action => 'index')

# Also expire the show pages, in case we just edited/deleted a page
expire_action(:controller => 'pages', :action => 'show', :id => record.to_param)
end
end
68 changes: 68 additions & 0 deletions app/controllers/pages_controller.rb
@@ -0,0 +1,68 @@
class PagesController < BaseController
uses_tiny_mce(:options => AppConfig.default_mce_options, :only => [:new, :edit, :update, :create ])

cache_sweeper :page_sweeper, :only => [:create, :update, :destroy]
caches_action :show, :if => Proc.new{|c| c.cache_action? }

def cache_action?
!logged_in? && controller_name.eql?('pages')
end

before_filter :login_required, :only => [:index, :new, :edit, :update, :destroy, :create, :preview]
before_filter :require_moderator, :only => [:index, :new, :edit, :update, :destroy, :create, :preview]

def index
@pages = Page.find_without_published_as(:all, :order => 'created_at DESC')
end

def preview
@page = Page.find(params[:id])
render :action => :show
end

def show
@page = Page.live.find(params[:id])
unless logged_in? || @page.page_public
flash[:error] = :this_page_is_not_public_youll_need_to_create_an_account_and_log_in_to_access_it.l
redirect_to :controller => 'sessions', :action => 'new'
end
rescue
flash[:error] = :page_not_found.l
redirect_to home_path
end

def create
@page = Page.new(params[:page])
if @page.save
flash[:notice] = :page_was_successfully_created.l
redirect_to admin_pages_path
else
render :action => :new
end
end

def update
if @page.update_attributes(params[:page])
flash[:notice] = :page_was_successfully_updated.l
redirect_to admin_pages_path
else
render :action => :edit
end
end

def destroy
@page.destroy
flash[:notice] = :page_was_successfully_deleted.l
redirect_to admin_pages_path
end

private

def require_moderator
@page ||= Page.find(params[:id]) if params[:id]
unless admin? || moderator?
redirect_to :controller => 'sessions', :action => 'new' and return false
end
end

end
8 changes: 8 additions & 0 deletions app/models/page.rb
@@ -0,0 +1,8 @@
class Page < ActiveRecord::Base
acts_as_publishable :live, :draft, :members_only, :public
validates_presence_of :title, :body

def to_param
id.to_s << "-" << (title ? title.parameterize : '')
end
end
16 changes: 0 additions & 16 deletions app/views/base/_about_nav.html.haml

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/base/about.html.haml

This file was deleted.

20 changes: 0 additions & 20 deletions app/views/base/faq.html.haml

This file was deleted.

8 changes: 1 addition & 7 deletions app/views/base/site_index.html.haml
Expand Up @@ -11,13 +11,7 @@
= render :partial => 'posts/post', :collection => @posts

.yui-b
-box do
%h3= :explore_site.l :site => AppConfig.community_name
%ul.list.checks
- Category.find(:all).each do |c|
%li= link_to c.name, category_path(c)
%li= link_to :whats_popular.l, popular_url, {:class => 'popular'}
%li= link_to :find_an_expert.l, skills_path, {:class => 'users'}
=render :partial => 'shared/explore'

-box :class => "alt" do
%h3
Expand Down
2 changes: 1 addition & 1 deletion app/views/categories/_tips.html.haml
Expand Up @@ -6,6 +6,6 @@
%p
%em
=:every_person_has_something_to_say.l
%p= :need_some_help_contact_our.l+" #{link_to :faq_section.l, faq_url}."



12 changes: 5 additions & 7 deletions app/views/layouts/application.html.haml
Expand Up @@ -42,15 +42,13 @@
%li
%a{:href=>logout_url, :title=>:log_out_of_your.l + " #{AppConfig.community_name} " + :account.l}
=:log_out.l
%li
%a{:href=>about_url, :title=>:what_is.l + " #{AppConfig.community_name}?"}
=:about.l
%li
%a{:href=>faq_url, :title=>:frequent_asked_questions.l}
=:faq.l

- Page.find(:all).each do |page|
- if (logged_in? || page.page_public)
%li= link_to page.title, pages_path(page)

- if @rss_title && @rss_url
%li#rss= link_to :rss.l, @rss_url, {:title => @rss_title}

%p
= :community_tagline.l
= :community_tagline.l
25 changes: 25 additions & 0 deletions app/views/pages/_form.html.haml
@@ -0,0 +1,25 @@
%label
=:title.l
%em="(#{:required.l})"
= f.text_field :title

%label
=:body_text.l
%em="(#{:required.l})"
= f.text_area :body, :style => "width:95%;"

%label
= f.check_box :page_public
=:make_page_public.l
%br
%em
=:when_checked_this_page_will_be_visible_to_anyone.l
%br
%em
=:when_unchecked_this_page_will_only_be_visible_to_people_who_are_logged_in_to.l
= "#{AppConfig.community_name}."

%label
=:save_page_as.l
= f.select(:published_as, [[:published.l, 'live'], [:draft.l, 'draft']])

16 changes: 16 additions & 0 deletions app/views/pages/edit.html.haml
@@ -0,0 +1,16 @@
#yui-main
.yui-b
-box do
%h3= :edit_page.l
= error_messages_for :page
- form_for(:page, :url => admin_page_path(@page), :html => {:method => :put, :class => "MainForm", :id => 'post_form'}) do |f|

=render :partial => 'form', :locals => {:f => f}

%p
= submit_tag :update.l
=:or.l
= link_to :cancel_and_go_back_to_pages.l, admin_pages_path
%p
=link_to "#{image_tag 'icons/delete.png', :plugin => :community_engine} "+:delete_this_page.l, admin_page_path(@page), :method => :delete, :confirm => :are_you_sure_you_want_to_delete_this_page.l

16 changes: 16 additions & 0 deletions app/views/pages/edit.html.haml~
@@ -0,0 +1,16 @@
#yui-main
.yui-b
-box do
%h3= :edit_page.l
= error_messages_for :page
- form_for(:page, :url => admin_page_path(@page.to_param), :html => {:method => :put, :class => "MainForm", :id => 'post_form'}) do |f|

=render :partial => 'form', :locals => {:f => f}

%p
= submit_tag :update.l
=:or.l
= link_to :cancel_and_go_back_to_pages.l, admin_pages_path
%p
=link_to "#{image_tag 'icons/delete.png', :plugin => :community_engine} "+:delete_this_page.l, admin_page_path(@page), :method => :delete, :confirm => :are_you_sure_you_want_to_delete_this_page.l

28 changes: 28 additions & 0 deletions app/views/pages/index.html.haml
@@ -0,0 +1,28 @@
.yui-b
= render :partial => 'shared/admin_nav'
-box :class => 'alt' do
%h3=:tips.l
%p=:page_tips.l

#yui-main
.yui-b
-box do
%h3
=:manage_pages.l
%p=:pages_saved_with_draft_status_wont_appear_on_the_site_until_you_publish_them.l
%p=link_to :new_page.l, new_admin_page_path

%table{:border => 0, :width => '100%'}
%thead
%tr
%th=:title.l
%th=:public.l
%th=:status.l
%tbody
- @pages.each do |page|
%tr
%td
= link_to page.title, edit_admin_page_path(page)
= link_to("(#{:preview.l})", preview_admin_page_path(page), :target => '_blank') unless page.is_live?
%td= page.page_public ? 'Yes' : 'No'
%td= page.is_live? ? link_to(:published.l, pages_path(page)) : :draft.l
30 changes: 30 additions & 0 deletions app/views/pages/index.html.haml~
@@ -0,0 +1,30 @@
.yui-b
= render :partial => 'shared/admin_nav'

.yui-b.sidebar
-box do
%h3=:links.l
%ul.checks
%li=link_to :new_page.l, new_admin_page_path

#yui-main
.yui-b
-box do
%h3
=:manage_pages.l
%p=:pages_saved_with_draft_status_wont_appear_on_the_site_until_you_publish_them.l

%table{:border => 0, :width => '100%'}
%thead
%tr
%th=:title.l
%th=:public.l
%th=:status.l
%tbody
- @pages.each do |page|
%tr
%td
= link_to page.title, edit_admin_page_path(page)
= link_to("(#{:preview.l})", page_path(page), :target => '_blank') unless page.is_live?
%td= page.page_public ? :yes.l : :no.l
%td= page.is_live? ? link_to(:published.l, pages_path(page)) : :draft.l
14 changes: 14 additions & 0 deletions app/views/pages/new.html.haml
@@ -0,0 +1,14 @@
#yui-main
.yui-b
-box do
%h3= :new_page.l
= error_messages_for :page
- form_for(:page, :url => admin_pages_path, :html => {:class => "MainForm", :id => 'post_form'}) do |f|

=render :partial => 'form', :locals => {:f => f}

%p
= submit_tag :save.l
=:or.l
= link_to :cancel_and_go_back_to_pages.l, admin_pages_path

8 changes: 8 additions & 0 deletions app/views/pages/show.html.haml
@@ -0,0 +1,8 @@
.yui-b
= render :partial => 'shared/explore'
= render :partial => 'shared/contact'
#yui-main
.yui-b
-box :class=>'entry-content page-content' do
%h3= @page.title
= @page.body
6 changes: 6 additions & 0 deletions app/views/pages/show.html.haml~
@@ -0,0 +1,6 @@
= render :partial => 'shared/admin_nav'
#yui-main
.yui-b
-box do
%h3= @page.title
= @page.body
1 change: 1 addition & 0 deletions app/views/shared/_admin_nav.html.haml
Expand Up @@ -16,3 +16,4 @@
%li= link_to_unless_current :ads.l, ads_path
%li= link_to_unless_current :comments.l, admin_comments_path
%li= link_to_unless_current :tags.l, admin_tags_path
%li= link_to_unless_current :admin_pages.l, admin_pages_path
5 changes: 5 additions & 0 deletions app/views/shared/_contact.html.haml
@@ -0,0 +1,5 @@
-box :class => "alt" do
%h3=:need_to_contact_us.l
%p
=:dont_wait_its.l
%a{:href=>"mailto:#{AppConfig.support_email}"}= AppConfig.support_email
11 changes: 11 additions & 0 deletions app/views/shared/_explore.html.haml
@@ -0,0 +1,11 @@
-box do
%h3 Explore
%ul.list.checks
- Category.find(:all).each do |c|
%li= link_to c.name, category_path(c)
%li= link_to :whats_popular.l, popular_url, {:class => 'popular'}
%li= link_to :find_an_expert.l, skills_path, {:class => 'users'}
- Page.find(:all).each do |page|
- if (logged_in? || page.page_public)
%li= link_to page.title, pages_path(page)

0 comments on commit b6d0c7b

Please sign in to comment.