Module: Cms::RouteExtensions
- Defined in:
- lib/cms/route_extensions.rb
Constant Summary collapse
- DEFAULT_RESOURCE_ACTIONS =
[:index, :show, :new, :create, :edit, :update, :destroy]
- DEFAULT_CONTENT_BLOCKS_OPTIONS =
{ bulk_update: true }
Instance Method Summary collapse
-
#content_blocks(content_block_name, options = {}, &block) ⇒ Object
Adds all necessary routes to manage a new content type.
-
#mount_browsercms ⇒ Object
(also: #routes_for_browser_cms)
Adds the routes required for BrowserCMS to function to a routes.rb file.
Instance Method Details
#content_blocks(content_block_name, options = {}, &block) ⇒ Object
Adds all necessary routes to manage a new content type. Works very similar to the Rails resources method, adding basic CRUD routes, as well as additional ones
for CMS specific routes (like versioning)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cms/route_extensions.rb', line 10 def content_blocks(content_block_name, = {}, &block) = DEFAULT_CONTENT_BLOCKS_OPTIONS.merge model_class = guess_model_class(content_block_name) # options to bulk_update = .delete :bulk_update only = .delete(:only) || DEFAULT_RESOURCE_ACTIONS.dup if model_class.try :readonly? only.delete :new only.delete :create only.delete :edit only.delete :update only.delete :destroy bulk_update = false end [:only] = only unless only == DEFAULT_RESOURCE_ACTIONS # pass the options only if any present resources_args = [content_block_name] resources_args << if .present? resources(*resources_args) do if model_class.publishable? || model_class.versioned? member do put :publish if model_class.publishable? if model_class.versioned? get :versions get 'version/:version', to: "#{content_block_name}#version", as: 'version' put 'revert_to/:version', to: "#{content_block_name}#revert_to", as: 'revert' end end end if bulk_update collection do put :update, to: "#{content_block_name}#bulk_update" end end yield if block_given? end end |
#mount_browsercms ⇒ Object Also known as: routes_for_browser_cms
Adds the routes required for BrowserCMS to function to a routes.rb file. Should be the last route in the file, as all following routes will be ignored.
Usage:
YourAppName::Application.routes.draw do
match '/some/path/in/your/app' :to=>"controller#action''
mount_browsercms
end
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cms/route_extensions.rb', line 66 def mount_browsercms mount Cms::Engine => "/cms", :as => "cms" add_page_routes_defined_in_database # Add User management features devise_for :cms_user, class_name: Cms.user_class_name, path: '', skip: :password, path_names: { sign_in: 'login' }, controllers: { sessions: 'cms/sites/sessions' } devise_scope :cms_user do get '/forgot-password' => "cms/sites/passwords#new", :as => 'forgot_password' post '/forgot-password' => "cms/sites/passwords#create", as: 'cms_user_password' get '/passwords/:id/edit' => "cms/sites/passwords#edit", as: 'edit_password' put '/forgot-password' => "cms/sites/passwords#update", as: 'update_password' end # Handle 'stock' attachments get "/attachments/:id/:filename", :to => "cms/attachments#download" get "/", :to => "cms/content#show" # Only need :POST to support portlets that are acting like controllers. # Ideally we could get rid of this need. match "*path", :to => "cms/content#show", via: [:get, :post] end |