summaryrefslogtreecommitdiff
path: root/config/routes.rb
blob: 8e5ff23af97629126ba0a1278927d649e5c5199c (plain)
1
2
3
4
5
6
7
8
9
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
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
Cccms::Application.routes.draw do

  # Handles bare locale root paths: /de and /en (without trailing slash).
  # Must live outside and before the scope because the scope's /*page_path
  # catch-all would otherwise consume these before the locale segment is
  # recognised. Replaces routing-filter's around_recognize hook which
  # handled this transparently.
  get '/:locale', to: 'content#render_page',
      defaults: { page_path: ['home'] },
      constraints: { locale: /de|en/ }

  # All application routes are scoped under an optional two-letter locale
  # prefix: /de/... and /en/... Both forms are valid; the prefix is omitted
  # for the default locale (:de) in generated URLs via default_url_options
  # in ApplicationController. This replaces the routing-filter gem.
  #
  # The locale regex must be kept in sync with config/application.rb
  # (config.i18n.available_locales) and ApplicationController#set_locale.
  # Adding a new locale requires updating all three locations.
  scope '(:locale)', locale: /de|en/ do

    resources :tags

    resources :events do
      collection do
        get :without_node
      end
    end

    get  'pages/:id/preview',     to: 'pages#preview',     as: :preview_page
    put  'pages/:id/sort_images', to: 'pages#sort_images', as: :sort_images_page

    get 'preview/:token', to: 'shared_previews#show', as: :shared_preview

    scope '/admin' do
      resources :assets

      resources :nodes do
        collection do
          get 'tags/:tags', action: :tags, as: :tags, constraints: { tags: /[^\/]+/ }
          get :parameterize_preview
          get :drafts
          get :recent
          get :mine
          get :chapters
          get :sitemap
        end

        member do
          put :unlock
          put :publish
          put :generate_shared_preview
          put :revoke_shared_preview
          put :autosave
          put :revert
        end

        resources :translations, controller: 'page_translations',
          param: :translation_locale,
          constraints: { translation_locale: /en/ },
          only: [:show, :edit, :update, :destroy] do
          member do
            put :autosave
          end
        end

        resources :related_assets, only: [:create, :destroy, :update] do
          collection do
            get :search
          end
        end

        resources :revisions do
          collection do
            post :diff
            get  :diff
          end
          member do
            put :restore
          end
        end
      end

      match ''                 => 'admin#index',            :as => :admin,                  :via => :get
      match 'search'           => 'admin#search',           :as => :admin_search,           :via => :get
      match 'menu_search'      => 'admin#menu_search',      :as => :admin_menu_search,      :via => :get
      match 'conventions'      => 'admin#conventions',      :as => :admin_conventions,      :via => :get
      match 'dashboard_search' => 'admin#dashboard_search', :as => :admin_dashboard_search, :via => :get
    end

    match '/logout'      => 'sessions#destroy', :as => :logout,       :via => :delete
    match '/login'       => 'sessions#new',     :as => :login,        :via => :get
    match 'search'       => 'search#index',     :as => :search,       :via => :get

    resources :users

    resources :menu_items do
      member do
        post :sort
      end
    end

    resource :session

    get  'rss/updates',         :to => 'rss#updates', :as => :rss
    get  'rss/updates.:format', :to => 'rss#updates', :as => :rss_feed,
           :constraints => { :format => /xml|rdf/ }
    get  'rss/tags/:tag/updates',         :to => 'rss#tag_updates', :as => :rss_tag
    get  'rss/tags/:tag/updates.:format', :to => 'rss#tag_updates', :as => :rss_tag_feed,
           :constraints => { :format => /xml/ }

    match 'galleries/*page_path' => 'content#render_gallery', :via => :get
    match '/*page_path'          => 'content#render_page', :as => :content, :via => :get

    # Handles /de/ and /en/ (locale root with trailing slash).
    # The bare-slash case inside the scope is distinct from the /:locale
    # route above due to trailing slash handling in Rack/Rails routing.
    get '/', to: 'content#render_page', defaults: { page_path: ['home'] }

    # Handles / (no locale prefix — default locale :de).
    root to: 'content#render_page', defaults: { page_path: ['home'] }

  end

end