Module: Cms::Routes

Defined in:
lib/cms/routes.rb

Instance Method Summary collapse

Instance Method Details

#content_blocks(content_block_name, options = {}, &block) ⇒ Object

content_block_name - Should be a plural symbol matching the name of the content_block, like :dogs or donation_statuses



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cms/routes.rb', line 6

def content_blocks(content_block_name, options={}, &block)
  content_block = content_block_name.to_s.classify.constantize
  resources(*[content_block_name, default_routes_for_content_block(content_block).deep_merge(options)], &block)
  if content_block.versioned?
    # I'm not sure why, but these named routes 
    # don't end up getting nested in the CMS namepace.
    # So for now I'm just hard-coding the stuff related to the CMS namespace
    send("version_cms_#{content_block_name}".to_sym, 
      "/cms/#{content_block_name}/:id/version/:version",
      :controller => "cms/#{content_block_name}",
      :action => "version",
      :conditions => {:method => :get})
    send("revert_to_cms_#{content_block_name}".to_sym, 
      "/cms/#{content_block_name}/:id/revert_to/:version",
      :controller => "cms/#{content_block_name}",
      :action => "revert_to",
      :conditions => {:method => :put})
  end
end

#default_routes_for_content_block(content_block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/cms/routes.rb', line 26

def default_routes_for_content_block(content_block)
  member_routes = {}
  member_routes[:publish] = :put if content_block.publishable?
  member_routes[:versions] = :get if content_block.versioned?
  member_routes[:usages] = :get if content_block.connectable?    
  {:member => member_routes}
end

#routes_for_browser_cmsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/cms/routes.rb', line 34

def routes_for_browser_cms

  namespace(:cms) do |cms|
    
    cms.home '/', :controller => 'home'
    
    cms.logout '/logout', :controller => 'sessions', :action => 'destroy'
    cms. '/login', :controller => 'sessions', :action => 'new', :conditions => { :method => :get }
    cms.connect '/login', :controller => 'sessions', :action => 'create', :conditions => { :method => :post }      
    cms.dashboard '/dashboard', :controller => 'dashboard'
    cms.sitemap '/sitemap', :controller => 'section_nodes'

    cms.content_types '/content_types', :controller => 'content_types'
    cms.resources :connectors, :member => {
      :move_up => :put,
      :move_down => :put,
      :move_to_bottom => :put,
      :move_to_top => :put
    }
    cms.resources :links

    cms.resources :pages, :member => {
      :archive => :put,
      :hide => :put,
      :publish => :put,
      :versions => :get
    }, :collection => {
      :publish => :put
    }, :has_many => [:tasks]
    version_cms_page '/cms/pages/:id/version/:version', :controller => 'cms/pages', :action => 'version', :conditions => {:method => :get}
    revert_to_cms_page '/cms/pages/:id/revert_to/:version', :controller => 'cms/pages', :action => 'revert_to', :conditions => {:method => :put}

    cms.file_browser '/sections/file_browser.xml', :controller => 'sections', :action => 'file_browser', :format => "xml"
    cms.resources :sections, :has_many => [:links, :pages]

    cms.resources :section_nodes, :member => {
      :move_before => :put,
      :move_after => :put,
      :move_to_beginning => :put,
      :move_to_end => :put,
      :move_to_root => :put
    }
    cms.attachment '/attachments/:id', :controller => 'attachments', :action => 'show'

    cms.resources :tasks, :member => {:complete => :put}, :collection => {:complete => :put}
    cms.toolbar '/toolbar', :controller => 'toolbar'
    
    # TODO: Make an actual content library controller 
    # that redirects to the last content type you were working on
    cms.content_library '/content_library', :controller => 'html_blocks' 
    
    cms.content_blocks :html_blocks
    cms.content_blocks :portlets, :member => {:usages => :get}
    cms.handler "/portlet/:id/:handler", 
      :controller => "portlet", 
      :action => "execute_handler", 
      :conditions => {:method => :post}
    
    cms.content_blocks :file_blocks
    cms.content_blocks :image_blocks
    cms.content_blocks :category_types
    cms.content_blocks :categories
    cms.content_blocks :tags
    
    cms.administration '/administration', :controller => 'users'
    
    cms.with_options :controller => "cache" do |cache|
        cache.cache "/cache", :action => "show", :conditions => {:method => :get}
      cache.connect "/cache", :action => "destroy", :conditions => {:method => :delete}
    end
          
    cms.resources :email_messages
    cms.resources :groups
    cms.resources :redirects
    cms.resources :page_partials, :controller => 'dynamic_views'
    cms.resources :page_templates, :controller => 'dynamic_views'
    cms.resources :page_routes do |pr|
      pr.resources :conditions, :controller => "page_route_conditions"
      pr.resources :requirements, :controller => "page_route_requirements"
    end
    cms.routes "/routes", :controller => "routes"
    cms.resources :users, :member => {
      :change_password => :get, 
      :update_password => :put,
      :disable => :put, 
      :enable => :put
    }
    
    if RAILS_ENV == "test" && File.expand_path(RAILS_ROOT) == File.expand_path(File.dirname(__FILE__) + "/../..")
      cms.content_blocks :content_block
    end
    
  end

  if PageRoute.table_exists?
    PageRoute.all(:order => "page_routes.name").each do |r|
      send((r.route_name || 'connect').to_sym, r.pattern, r.options_map)
    end
  end

  connect '*path', :controller => 'cms/content', :action => 'show'    
end