forked from bborn/communityengine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pages for managing static content and use to replace hard-coded F…
…AQ and About pages.
- Loading branch information
Errol Siegel
committed
Aug 26, 2009
1 parent
c50327e
commit b6d0c7b
Showing
34 changed files
with
526 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
= render :partial => 'shared/admin_nav' | ||
#yui-main | ||
.yui-b | ||
-box do | ||
%h3= @page.title | ||
= @page.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
Oops, something went wrong.