add changes
This commit is contained in:
+3
-2
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user