add changes

This commit is contained in:
2012-03-28 15:47:20 +02:00
parent 2ca8e2c533
commit 664b001e5c
17 changed files with 176 additions and 118 deletions
+15
View File
@@ -53,6 +53,7 @@ The page model allows you to control some interesting things. To create it (app/
# Define the layouts you want to use in your website. Be sure to create them in
# app/views/layouts/...
# The first specified layout will become the default
def self.layouts
[:application, :home, :contact]
end
@@ -75,3 +76,17 @@ Cmtool will take this value:
I18n.locale
end
end
=== Customize a page
All pages by default are rendered using the view: app/pages/show. So adding and changing this file will
change all displayed pages without their own specific page. To create a specific page, create a page
with the name of the page you created in the Admin section. If for example you have created a page
with the name: about
Then you can give this page a custom look using the view:
<tt>app/views/about.html.haml</tt>
You can also use erb, slim or your choice of templating engine
=== Customize your 404
You can customize what is shown when a page cannot be found. There is a standard view app/pages/404.html.erb with the following content:
<%= render template: 'pages/show' %>
Overwrite this to get another page as show. To controll the content of the 404 page, create a page in the Admin area having the name: 404.
You can make a 404 page for every language in this manner. Here you can also give a custom layout if you do not want to use the default layout.
@@ -6,7 +6,7 @@ module Cmtool
def set_locale
if respond_to? :cmtool_locale
I18n.locale = :cmtool_locale
I18n.locale = cmtool_locale
else
I18n.locale = :en
end
+1 -1
View File
@@ -1,3 +1,3 @@
class Page
include Cmtool::Page
include Cmtool::Includes::Page
end
+1 -1
View File
@@ -1,3 +1,3 @@
class User
include Cmtool::User
include Cmtool::Includes::User
end
-3
View File
@@ -32,9 +32,6 @@
.field
= f.label :parent_id
= f.select :parent_id, tree_options_for_select(Page.full_tree(@page.locale), exclude: @page.id, selected: @page.parent_id), include_blank: ' -- '
.field
= f.label :default
= f.check_box :default
.field
= f.label :position
= f.select :position, (0..20).to_a
+1
View File
@@ -0,0 +1 @@
<%= render template: 'pages/show' %>
+1
View File
@@ -0,0 +1 @@
= render template: 'pages/show'
+1
View File
@@ -0,0 +1 @@
=raw @page.body
+3 -2
View File
@@ -1,6 +1,7 @@
require "cmtool/engine"
require 'cmtool/user'
require 'cmtool/page'
require 'cmtool/includes/user'
require 'cmtool/includes/page'
require 'cmtool/includes/pages_controller'
module Cmtool
end
+1
View File
@@ -5,6 +5,7 @@ require 'devise'
require 'devise_simply_stored'
require 'haml-rails'
require 'sass-rails'
require 'tinymce-rails'
require 'paperclip'
require 'jquery-rails'
require 'bourbon'
+65
View File
@@ -0,0 +1,65 @@
module Cmtool
module Includes
module Page
def self.included(klass)
klass.send :include, SimplyStored::Couch
klass.send :include, InstanceMethods
klass.send :extend, ClassMethods
# PROPERTIES
klass.property :name
klass.property :menu_text
klass.property :title
klass.property :body
klass.property :footer
klass.property :sidebar
klass.property :priority, type: Float, default: 0.5
klass.property :active, type: :boolean, default: true
klass.property :layout
klass.property :in_menu, type: :boolean
klass.has_ancestry :by_property => :locale
klass.validates :name, presence: true
klass.validates :locale, presence: true
# RELATIONS
klass.has_and_belongs_to_many :keywords, storing_keys: true, class_name: 'Cmtool::Keyword'
# DEFAULT ORDER
klass.view :all_documents, key: [:position, :name, :title]
klass.view :by_name_and_locale, key: [:name, :locale]
end
module InstanceMethods
def generate_name
name = self.class.generate_name(title)
end
end
module ClassMethods
def generate_name(name)
name.to_s.downcase.gsub(/^\W+/, '').gsub(/\W+$/,'').gsub(/\W+/, '-')
end
def active(*args)
all(*args)
end
def layouts
[:application, :home, :contact]
end
def flag_locales
[:ad, :ae, :af, :ag, :ai, :al, :am, :an, :ao, :aq, :ar, :as, :at, :au, :aw, :az, :ba, :bb, :bd, :be, :bf, :bg, :bh, :bi, :bj, :bm, :bn, :bo, :br, :bs, :bt, :bw, :by, :bz, :ca, :cd, :cf, :cg, :ch, :ci, :ck, :cl, :cm, :cn, :co, :cr, :cu, :cv, :cy, :cz, :de, :dj, :dk, :dm, :do, :dz, :ec, :ee, :eg, :eh, :en, :er, :es, :et, :fi, :fj, :fm, :fo, :fr, :ga, :gb, :gd, :ge, :gg, :gh, :gi, :gl, :gm, :gn, :gp, :gq, :gr, :gt, :gu, :gw, :gy, :hk, :hn, :hr, :ht, :hu, :id, :ie, :il, :im, :in, :iq, :ir, :is, :it, :je, :jm, :jo, :jp, :ke, :kg, :kh, :ki, :km, :kn, :kp, :kr, :kw, :ky, :kz, :la, :lb, :lc, :li, :lk, :lr, :ls, :lt, :lu, :lv, :ly, :ma, :mc, :md, :me, :mg, :mh, :mk, :ml, :mm, :mn, :mo, :mq, :mr, :ms, :mt, :mu, :mv, :mw, :mx, :my, :mz, :na, :nc, :ne, :ng, :ni, :nl, :no, :np, :nr, :nz, :om, :pa, :pe, :pf, :pg, :ph, :pk, :pl, :pr, :ps, :pt, :pw, :py, :qa, :re, :ro, :rs, :ru, :rw, :sa, :sb, :sc, :sd, :se, :sg, :si, :sk, :sl, :sm, :sn, :so, :sr, :st, :sv, :sy, :sz, :tc, :td, :tg, :th, :tj, :tl, :tm, :tn, :to, :tr, :tt, :tv, :tw, :tz, :ua, :ug, :us, :uy, :uz, :va, :vc, :ve, :vg, :vi, :vn, :vu, :ws, :ye, :za, :zm, :zw]
end
def locales
[:en, :nl, :de, :es]
end
def default_locale
:en
end
end
end
end
end
+33
View File
@@ -0,0 +1,33 @@
module Cmtool
module Includes
module PagesController
def home
page_name = "home"
@page = ::Page.find_by_name_and_locale(page_name, I18n.locale) || ::Page.new(:name => page_name, locale: I18n.locale)
@sub_pages = @page.children.select{|child| child.in_menu.present? }
render :template => "pages/#{page_name}", :layout => @page.layout.presence || ::Page.layouts.first.to_s
end
# General catcher for pages
def show
@page = ::Page.find_by_name_and_locale(params[:name], I18n.locale)
not_found and return unless @page
@sub_pages = [@page] + @page.children.select{|child| child.in_menu.present? }
template = "pages/#{@page.name}"
if template_exists?(template)
render :template => template, :layout => @page.layout.presence || ::Page.layouts.first
return
else
render :layout => @page.layout.presence || ::Page.layouts.first
end
end
def not_found
@page = ::Page.find_by_name_and_locale('404', I18n.locale) || ::Page.new(name: '404', body: "404 Page Not Found")
@sub_pages = []
render template: 'pages/404', layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404
end
end
end
end
+47
View File
@@ -0,0 +1,47 @@
module Cmtool
module Includes
module User
def self.included(klass)
klass.extend Devise::Models
klass.send :include, SimplyStored::Couch
klass.send :include, Devise::Orm::SimplyStored
klass.send :include, InstanceMethods
klass.property :employee_email
klass.property :is_admin, type: :boolean
klass.property :active, type: :boolean, default: true
klass.devise :database_authenticatable, :recoverable, :rememberable, :trackable
#== VALIDATIONS
klass.validates_presence_of :email
klass.validates_uniqueness_of :email
klass.validates_presence_of :encrypted_password, if: lambda{ |u| u.email.present? }
klass.validates_confirmation_of :password, if: lambda{ |u| u.password.present? }
klass.view :by_email, key: :email
end
module InstanceMethods
def google?
false
end
def name
email
end
def generated_password
@generated_password
end
def generate_password!
@password_haystack ||= (:a..:z).to_a + (:A..:Z).to_a + (0..9).to_a
@generated_password = @password_haystack.sample(8).join
self.password = @generated_password
self.password_confirmation = @generated_password
end
end
end
end
end
-65
View File
@@ -1,65 +0,0 @@
module Cmtool
module Page
LAYOUTS = %w[application home contact manual]
def self.included(klass)
klass.send :include, SimplyStored::Couch
klass.send :include, InstanceMethods
klass.send :extend, ClassMethods
# PROPERTIES
klass.property :name
klass.property :menu_text
klass.property :title
klass.property :body
klass.property :footer
klass.property :sidebar
klass.property :priority, type: Float, default: 0.5
klass.property :default, type: :boolean
klass.property :active, type: :boolean, default: true
klass.property :layout
klass.property :in_menu, type: :boolean
klass.has_ancestry :by_property => :locale
klass.validates :name, presence: true
klass.validates :locale, presence: true
# RELATIONS
klass.has_and_belongs_to_many :keywords, storing_keys: true, class_name: 'Cmtool::Keyword'
# DEFAULT ORDER
klass.view :all_documents, key: [:position, :name, :title]
klass.view :by_name_and_locale, key: [:name, :locale]
end
module InstanceMethods
def generate_name
name = self.class.generate_name(title)
end
end
module ClassMethods
def generate_name(name)
name.to_s.downcase.gsub(/^\W+/, '').gsub(/\W+$/,'').gsub(/\W+/, '-')
end
def active(*args)
all(*args)
end
def layouts
[:application, :home, :contact]
end
def flag_locales
[:ad, :ae, :af, :ag, :ai, :al, :am, :an, :ao, :aq, :ar, :as, :at, :au, :aw, :az, :ba, :bb, :bd, :be, :bf, :bg, :bh, :bi, :bj, :bm, :bn, :bo, :br, :bs, :bt, :bw, :by, :bz, :ca, :cd, :cf, :cg, :ch, :ci, :ck, :cl, :cm, :cn, :co, :cr, :cu, :cv, :cy, :cz, :de, :dj, :dk, :dm, :do, :dz, :ec, :ee, :eg, :eh, :en, :er, :es, :et, :fi, :fj, :fm, :fo, :fr, :ga, :gb, :gd, :ge, :gg, :gh, :gi, :gl, :gm, :gn, :gp, :gq, :gr, :gt, :gu, :gw, :gy, :hk, :hn, :hr, :ht, :hu, :id, :ie, :il, :im, :in, :iq, :ir, :is, :it, :je, :jm, :jo, :jp, :ke, :kg, :kh, :ki, :km, :kn, :kp, :kr, :kw, :ky, :kz, :la, :lb, :lc, :li, :lk, :lr, :ls, :lt, :lu, :lv, :ly, :ma, :mc, :md, :me, :mg, :mh, :mk, :ml, :mm, :mn, :mo, :mq, :mr, :ms, :mt, :mu, :mv, :mw, :mx, :my, :mz, :na, :nc, :ne, :ng, :ni, :nl, :no, :np, :nr, :nz, :om, :pa, :pe, :pf, :pg, :ph, :pk, :pl, :pr, :ps, :pt, :pw, :py, :qa, :re, :ro, :rs, :ru, :rw, :sa, :sb, :sc, :sd, :se, :sg, :si, :sk, :sl, :sm, :sn, :so, :sr, :st, :sv, :sy, :sz, :tc, :td, :tg, :th, :tj, :tl, :tm, :tn, :to, :tr, :tt, :tv, :tw, :tz, :ua, :ug, :us, :uy, :uz, :va, :vc, :ve, :vg, :vi, :vn, :vu, :ws, :ye, :za, :zm, :zw]
end
def locales
[:en, :nl, :de, :es]
end
def default_locale
:en
end
end
end
end
-45
View File
@@ -1,45 +0,0 @@
module Cmtool
module User
def self.included(klass)
klass.extend Devise::Models
klass.send :include, SimplyStored::Couch
klass.send :include, Devise::Orm::SimplyStored
klass.send :include, InstanceMethods
klass.property :employee_email
klass.property :is_admin, type: :boolean
klass.property :active, type: :boolean, default: true
klass.devise :database_authenticatable, :recoverable, :rememberable, :trackable
#== VALIDATIONS
klass.validates_presence_of :email
klass.validates_uniqueness_of :email
klass.validates_presence_of :encrypted_password, if: lambda{ |u| u.email.present? }
klass.validates_confirmation_of :password, if: lambda{ |u| u.password.present? }
klass.view :by_email, key: :email
end
module InstanceMethods
def google?
false
end
def name
email
end
def generated_password
@generated_password
end
def generate_password!
@password_haystack ||= (:a..:z).to_a + (:A..:Z).to_a + (0..9).to_a
@generated_password = @password_haystack.sample(8).join
self.password = @generated_password
self.password_confirmation = @generated_password
end
end
end
end
@@ -0,0 +1,3 @@
class PagesController < ApplicationController
include Cmtool::Includes::PagesController
end
+3
View File
@@ -1,5 +1,8 @@
Rails.application.routes.draw do
devise_for :users, :controllers => {:sessions => 'cmtool/sessions', :passwords => 'cmtool/passwords'}
match "/:name" => "pages#show"
match "/*url" => "pages#not_found"
root :to => 'pages#home'
mount Cmtool::Engine => "/cmtool"
end