### codetube
    Copyright (C) 2011 payload payload@lavabit.com
    Copyright (C) 2011 dodo dodo.the.last@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
###

Router = require('./router')
appconfig = require('./appconfig')
config = require('./config')



# define routes

router = new Router (app) ->
    p = appconfig.prefix

    # loading controller
    controller = router.controller = {}
    for name in appconfig.controller
        controller[name] = new (require('./controller/' + name))()
    { main, authentication, user, project, git } = controller

    app.get  main.welcome, "/"
    app.get  main.home   , "/#{p}home"
    app.get  main.about  , "/#{p}about"

    app.get  authentication.login      ,"/#{p}login"
    app.post authentication.login_post ,"/#{p}login"
    app.get  authentication.logout     ,"/#{p}logout"
    app.get  authentication.register   ,"/#{p}register"
    app.post user.New                  ,"/#{p}register"
    app.get  user.list                 ,"/#{p}users"

    app.get  project.list   ,"/#{p}projects"
    app.get  project.create ,"/#{p}project/new"
    app.post project.New    ,"/#{p}project/new"

    app.get  user.settings ,"/:userid/#{p}settings"
    app.get  user.settings ,"/:userid/#{p}settings/*"
    app.post user.settings ,"/:userid/#{p}settings/*"

    app.get  user.show ,"/:userid"

    app.get  project.pages       ,"/:owner/:id/pages*?"
    app.get  project.settings    ,"/:owner/:id/#{p}settings/*"
    app.post project.settings    ,"/:owner/:id/#{p}settings/*"
    app.get  project.settings    ,"/:owner/:id/#{p}settings"
    app.get  project.commit      ,"/:owner/:id/commit/:sha"
    app.get  project.commits     ,"/:owner/:id/commits/:branch?"
    app.get  project.blob        ,"/:owner/:id/blob/:sha/*"
    app.get  project.show        ,"/:owner/:id/tree/:branch/*"
    app.get  project.show        ,"/:owner/:id/tree/:branch"
    app.get  project.show        ,"/:owner/:id/tree"

    app.all git.http ,"/:owner/:id.:repo.git*"
    app.all git.http ,"/:owner/:id.git*"

    app.get project.show ,"/:owner/:id/branch/:branch?"
    app.get project.show ,"/:owner/:id"

# exports

module.exports = router

