diff --git a/Gemfile b/Gemfile index 079cc4b..866a715 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,9 @@ source "http://rubygems.org" # development dependencies will be added by default to the :development group. gemspec -gem "rails", ">= 4.1.4" +gem "rails", "4.2.0.beta4" group :assets do - gem 'sass-rails', '4.0.2' + gem 'sass-rails', '5.0.0.beta1' gem 'bourbon' gem 'coffee-script' #gem 'therubyracer', :platforms => :ruby @@ -25,6 +25,7 @@ gem 'haml-rails' gem 'slim-rails' gem 'paperclip' gem 'email_validator' +gem 'actionpack-page_caching' # Declare any dependencies that are still in development here instead of in # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing diff --git a/Gemfile.lock b/Gemfile.lock index 8064ad7..384122a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/bterkuile/couch_potato.git - revision: 6fbcb3edcaf3edec63230308f123c1e03417967d + revision: 8929326ee855e964a441a8ede941b52c0ee88a16 specs: couch_potato (0.7.1) activemodel @@ -43,41 +43,52 @@ PATH GEM remote: http://rubygems.org/ specs: - actionmailer (4.1.4) - actionpack (= 4.1.4) - actionview (= 4.1.4) - mail (~> 2.5.4) - actionpack (4.1.4) - actionview (= 4.1.4) - activesupport (= 4.1.4) - rack (~> 1.5.2) + actionmailer (4.2.0.beta4) + actionpack (= 4.2.0.beta4) + actionview (= 4.2.0.beta4) + activejob (= 4.2.0.beta4) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.4) + actionpack (4.2.0.beta4) + actionview (= 4.2.0.beta4) + activesupport (= 4.2.0.beta4) + rack (~> 1.6.0.beta) rack-test (~> 0.6.2) - actionview (4.1.4) - activesupport (= 4.1.4) + rails-dom-testing (~> 1.0, >= 1.0.4) + rails-html-sanitizer (~> 1.0, >= 1.0.1) + actionpack-page_caching (1.0.2) + actionpack (>= 4.0.0, < 5) + actionview (4.2.0.beta4) + activesupport (= 4.2.0.beta4) builder (~> 3.1) erubis (~> 2.7.0) - activemodel (4.1.4) - activesupport (= 4.1.4) + rails-dom-testing (~> 1.0, >= 1.0.4) + rails-html-sanitizer (~> 1.0, >= 1.0.1) + activejob (4.2.0.beta4) + activesupport (= 4.2.0.beta4) + globalid (>= 0.3.0) + activemodel (4.2.0.beta4) + activesupport (= 4.2.0.beta4) builder (~> 3.1) - activerecord (4.1.4) - activemodel (= 4.1.4) - activesupport (= 4.1.4) - arel (~> 5.0.0) - activesupport (4.1.4) - i18n (~> 0.6, >= 0.6.9) + activerecord (4.2.0.beta4) + activemodel (= 4.2.0.beta4) + activesupport (= 4.2.0.beta4) + arel (>= 6.0.0.beta2, < 6.1) + activesupport (4.2.0.beta4) + i18n (>= 0.7.0.beta1, < 0.8) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) - arel (5.0.1.20140414130214) - bcrypt (3.1.7) + arel (6.0.0.beta2) + bcrypt (3.1.9) bootstrap-sass (2.3.2.2) sass (~> 3.2) - bourbon (3.2.3) - sass (~> 3.2) + bourbon (4.0.2) + sass (~> 3.3) thor builder (3.2.2) - capybara (2.4.1) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) @@ -91,16 +102,17 @@ GEM coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.7.1) + coffee-script-source (1.8.0) couchrest (1.2.0) mime-types (~> 1.15) multi_json (~> 1.0) rest-client (~> 1.6.1) daemons (1.1.9) - devise (3.2.4) + devise (3.4.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) + responders thread_safe (~> 0.1) warden (~> 1.2.3) diff-lcs (1.2.5) @@ -108,12 +120,14 @@ GEM activemodel erubis (2.7.0) eventmachine (1.0.3) - execjs (2.2.1) - factory_girl (4.4.0) + execjs (2.2.2) + factory_girl (4.5.0) activesupport (>= 3.0.0) - factory_girl_rails (4.4.1) - factory_girl (~> 4.4.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) railties (>= 3.0.0) + globalid (0.3.0) + activesupport (>= 4.1.0) haml (4.0.5) tilt haml-rails (0.5.3) @@ -122,119 +136,127 @@ GEM haml (>= 3.1, < 5.0) railties (>= 4.0.1) hike (1.2.3) - i18n (0.6.11) - jquery-rails (3.1.1) + i18n (0.7.0.beta1) + jquery-rails (3.1.2) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - jquery-ui-rails (5.0.0) + jquery-ui-rails (5.0.2) railties (>= 3.2.16) json (1.8.1) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) + loofah (2.0.1) + nokogiri (>= 1.5.9) + mail (2.6.3) + mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (1.25.1) - mini_portile (0.6.0) - minitest (5.4.0) + mini_portile (0.6.1) + minitest (5.4.2) multi_json (1.10.1) - nokogiri (1.6.2.1) - mini_portile (= 0.6.0) + nokogiri (1.6.4) + mini_portile (~> 0.6.0) paperclip (4.2.0) activemodel (>= 3.0.0) activesupport (>= 3.0.0) cocaine (~> 0.5.3) mime-types - polyglot (0.3.5) - pry (0.10.0) + pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-rails (0.3.2) pry (>= 0.9.10) - rack (1.5.2) + rack (1.6.0.beta) rack-test (0.6.2) rack (>= 1.0) - rails (4.1.4) - actionmailer (= 4.1.4) - actionpack (= 4.1.4) - actionview (= 4.1.4) - activemodel (= 4.1.4) - activerecord (= 4.1.4) - activesupport (= 4.1.4) + rails (4.2.0.beta4) + actionmailer (= 4.2.0.beta4) + actionpack (= 4.2.0.beta4) + actionview (= 4.2.0.beta4) + activejob (= 4.2.0.beta4) + activemodel (= 4.2.0.beta4) + activerecord (= 4.2.0.beta4) + activesupport (= 4.2.0.beta4) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.4) - sprockets-rails (~> 2.0) - railties (4.1.4) - actionpack (= 4.1.4) - activesupport (= 4.1.4) + railties (= 4.2.0.beta4) + sprockets-rails (~> 3.0.0.beta1) + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.4) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.1) + loofah (~> 2.0) + railties (4.2.0.beta4) + actionpack (= 4.2.0.beta4) + activesupport (= 4.2.0.beta4) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) - rdoc (4.1.1) + rdoc (4.1.2) json (~> 1.4) + responders (2.0.1) + railties (>= 4.2.0.alpha, < 5) rest-client (1.6.8) mime-types (~> 1.16) rdoc (>= 2.4.2) - rspec-core (3.0.2) - rspec-support (~> 3.0.0) - rspec-expectations (3.0.2) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.0.0) - rspec-its (1.0.1) - rspec-core (>= 2.99.0.beta1) - rspec-expectations (>= 2.99.0.beta1) - rspec-mocks (3.0.2) - rspec-support (~> 3.0.0) - rspec-rails (3.0.1) + rspec-support (~> 3.1.0) + rspec-its (1.1.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-rails (3.1.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-support (~> 3.0.0) - rspec-support (3.0.2) - sass (3.2.19) - sass-rails (4.0.2) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-support (~> 3.1.0) + rspec-support (3.1.2) + sass (3.4.7) + sass-rails (5.0.0.beta1) railties (>= 4.0.0, < 5.0) - sass (~> 3.2.0) - sprockets (~> 2.8, <= 2.11.0) - sprockets-rails (~> 2.0.0) - slim (2.0.3) - temple (~> 0.6.6) + sass (~> 3.2) + sprockets (~> 2.12) + sprockets-rails (>= 2.0, < 4.0) + slim (2.1.0) + temple (~> 0.6.9) tilt (>= 1.3.3, < 2.1) slim-rails (2.1.5) actionpack (>= 3.0, < 4.2) activesupport (>= 3.0, < 4.2) railties (>= 3.0, < 4.2) slim (~> 2.0) - slop (3.5.0) - sprockets (2.11.0) + slop (3.6.0) + sprockets (2.12.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.1) - actionpack (>= 3.0) - activesupport (>= 3.0) + sprockets-rails (3.0.0.beta1) + actionpack (>= 4.0) + activesupport (>= 4.0) sprockets (~> 2.8) steak (2.0.0) capybara (>= 1.0.0) rspec-rails (>= 2.5.0) - temple (0.6.8) - thin (1.6.2) - daemons (>= 1.0.9) - eventmachine (>= 1.0.0) - rack (>= 1.0.0) + temple (0.6.10) + thin (1.6.3) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0) + rack (~> 1.0) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) - tinymce-rails (4.1.0) + tinymce-rails (4.1.6) railties (>= 3.1.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (1.2.1) + tzinfo (1.2.2) thread_safe (~> 0.1) warden (1.2.3) rack (>= 1.0) @@ -245,6 +267,7 @@ PLATFORMS ruby DEPENDENCIES + actionpack-page_caching bootstrap-sass (~> 2.3) bourbon cmtool! @@ -260,9 +283,9 @@ DEPENDENCIES orm_adapter! paperclip pry-rails - rails (>= 4.1.4) + rails (= 4.2.0.beta4) rspec-its - sass-rails (= 4.0.2) + sass-rails (= 5.0.0.beta1) simply_stored! slim-rails steak diff --git a/README.md b/README.md new file mode 100644 index 0000000..6f76443 --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ +# Cmtool +[](http://travis-ci.org/bterkuile/cmtool) +## About +Cmtool is a CMS to give you a quickstart for a website using CouchDB as +database backend. It is in developing stage, but already used in production. +It is designed as an engine. The thought behind is that you will have to +create your own rails website, but get a lot of stuff for free. These things +are: + +* User management +* Page management +* Faq +* News +* Newsletter subscriptions +* Directory manager +* Image manager + + +## Setup +To start using Cmtool as website CMS add it to your Gemfile. Since it depends +on github gems and gem dependencies do not support those you have to +explicitly add two dependencies to your Gemfile: + gem 'couch_potato' , :git => 'git://github.com/bterkuile/couch_potato.git' + gem 'simply_stored' , :git => 'git://github.com/bterkuile/simply_stored.git' + gem 'cmtool' + +This will add some gems you might like anyway, here a list: + +* bourbon +* jquery-rails +* tinymce-rails +* sass-rails +* haml-rails +* paperclip +* email_validator (validates :email, email: true) + + +### Controllers + +in `app/controllers/pages_controller.rb`: + +```ruby +class PagesController + include Cmtool::Includes::PagesController +end +``` + +in `app/models/page.rb`: +```ruby +class Page + include Cmtool::Includes::Page + + def self.layouts + %w[home application contact] + end +end +``` + +### Securing + +Cmtool is looking for an authorize_cmtool method present in the application +controller. Something like: + +```ruby +class ApplicationController + ... + + private + + def authorize_cmtool + redirect_to main_app.root_path, alert: t('general.unauthorized') unless current_user.present? && current_user.is_admin? + end +end +``` + +### Routing + +Add the following routes: +```ruby +devise_for :users, :controllers => {:sessions => 'cmtool/sessions', :passwords => 'cmtool/passwords'} +mount Cmtool::Engine => '/cmtool' +get '/sitemap(.:format)' => 'pages#sitemap' +scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: :nl } do + get "/:name" => "pages#show", constraints: {name: /.*/}, as: :page +end +match "/*url" => "pages#not_found" +root :to => 'pages#home' +``` + +### User model +The user model is important. We recommend you to create your own user model: +```ruby +class User + include Cmtool::User + +end +``` + +This is enough to start using Cmtool. But probably you want to add some +goodies of your own. Remember that this is a SimplyStored model with almost +all the ActiveModel features. + +### Page model +The page model allows you to control some interesting things. To create it +(app/models/page.rb): +```ruby +class Page + include Cmtool::Page + + # Define the locales you want to use in your website + def self.locales + [:en] + end + + # 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 +end +``` + +### Controlling the language of the system +If you add a method `cmtool_locale` to your application controller Cmtool will +take this value: +```ruby +class ApplicationController + before_filter :set_locale + + private + + def set_locale + # Do some magic + I18n.locale = :en + end + + def cmtool_locale + 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: +`app/views/about.html.haml` 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. diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index 3c90e97..0000000 --- a/README.rdoc +++ /dev/null @@ -1,131 +0,0 @@ -= Cmtool -{Build Status}[http://travis-ci.org/bterkuile/cmtool] -== About -Cmtool is a CMS to give you a quickstart for a website using CouchDB as database -backend. It is in developing stage, but already used in production. -It is designed as an engine. The thought behind is that you will have to -create your own rails website, but get a lot of stuff for free. These things are: - -* User management -* Page management -* Faq -* News -* Newsletter subscriptions -* Directory manager -* Image manager - -== Setup -To start using Cmtool as website CMS add it to your Gemfile. Since it -depends on github gems and gem dependencies do not support those you -have to explicitly add two dependencies to your Gemfile: - gem 'couch_potato' , :git => 'git://github.com/bterkuile/couch_potato.git' - gem 'simply_stored' , :git => 'git://github.com/bterkuile/simply_stored.git' - gem 'cmtool' -This will add some gems you might like anyway, here a list: - -* bourbon -* jquery-rails -* tinymce-rails -* sass-rails -* haml-rails -* paperclip -* email_validator (validates :email, email: true) - -=== Controllers - -in app/controllers/pages_controller.rb: - class PagesController - include Cmtool::Includes::PagesController - end - -in app/models/page.rb: - class Page - include Cmtool::Includes::Page - - def self.layouts - %w[home application contact] - end - end - -=== Securing - -Cmtool is looking for an authorize_cmtool method present in the application controller. Something like: - class ApplicationController - ... - - private - - def authorize_cmtool - redirect_to main_app.root_path, alert: t('general.unauthorized') unless current_user.present? && current_user.is_admin? - end - end - -=== Routing - -Add the following routes: - devise_for :users, :controllers => {:sessions => 'cmtool/sessions', :passwords => 'cmtool/passwords'} - mount Cmtool::Engine => '/cmtool' - scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: :nl } do - get "/:name" => "pages#show", constraints: {name: /.*/}, as: :page - end - match "/*url" => "pages#not_found" - root :to => 'pages#home' - -=== User model -The user model is important. We recommend you to create your own user model: - class User - include Cmtool::User - - end -This is enough to start using Cmtool. But probably you want to add some goodies of your own. -Remember that this is a SimplyStored model with almost all the ActiveModel features. - -=== Page model -The page model allows you to control some interesting things. To create it (app/models/page.rb): - class Page - include Cmtool::Page - - # Define the locales you want to use in your website - def self.locales - [:en] - end - - # 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 - end - -=== Controlling the language of the system -If you add a method cmtool_locale to your application controller -Cmtool will take this value: - class ApplicationController - before_filter :set_locale - - private - - def set_locale - # Do some magic - I18n.locale = :en - end - - def cmtool_locale - 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: -app/views/about.html.haml -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. diff --git a/config/routes.rb b/config/routes.rb index fea97e4..9edf8af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Cmtool::Engine.routes.draw do end collection do get :generate_name + get :sitemap end end resources :news do diff --git a/lib/cmtool/includes/pages_controller.rb b/lib/cmtool/includes/pages_controller.rb index 6b464a1..3160990 100644 --- a/lib/cmtool/includes/pages_controller.rb +++ b/lib/cmtool/includes/pages_controller.rb @@ -1,6 +1,7 @@ module Cmtool module Includes module PagesController + extend ActiveSupport::Concern def home page_name = "home" @page = ::Page.find_by_name_and_locale(page_name, I18n.locale.to_s) || ::Page.new(:name => page_name, locale: I18n.locale.to_s) @@ -28,6 +29,22 @@ module Cmtool @sub_pages = [] render template: 'pages/404', layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404 end + + def sitemap + respond_to do |format| + format.xml do + page_uris = ::Page.all.map{|p| page_path(p.name, locale: p.locale)} + pages_xml = page_uris.map{|uri| "#{uri}"}.join("\n") + result = <<-XML + + +#{pages_xml} + + XML + render xml: result + end + end + end end end end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index accbfa7..a59fbaf 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -2,10 +2,12 @@ require 'spec_helper' describe Cmtool::PagesController, type: :controller do routes { Cmtool::Engine.routes } + describe 'GET index' do it "should render standard view when tree is available" do create_pages_tree expect{ get :index }.not_to raise_error end end + end diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 47bba96..0398511 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -2,7 +2,11 @@ Rails.application.routes.draw do devise_for :users, :controllers => {:sessions => 'cmtool/sessions', :passwords => 'cmtool/passwords'} mount Cmtool::Engine => "/cmtool" + get '/sitemap(.:format)' => 'test_pages#sitemap' get "/:name" => "pages#show" + scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: :nl } do + get "/:name" => "pages#show", constraints: {name: /.*/}, as: :page + end get "/*url" => "pages#not_found" root :to => 'pages#home' end diff --git a/spec/includes/pages_controller_include_spec.rb b/spec/includes/pages_controller_include_spec.rb new file mode 100644 index 0000000..97c361f --- /dev/null +++ b/spec/includes/pages_controller_include_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +class TestPagesController < ApplicationController + include Cmtool::Includes::PagesController +end + +describe TestPagesController, type: :controller do + describe 'sitemap' do + it 'returns a proper sitemap' do + create_pages_tree + get :sitemap, format: 'xml' + expect( response.body ).to include "/en/child2.2" + end + end +end