<commit_before>(ns sdos-site.core
  (:require [sdos-site.settings :refer :all]
            [sdos-site.db :refer :all]
            [sdos-site.user :as user]
            [sdos-site.admin :as admin]
            [compojure.core :refer :all]
            [compojure.route :refer (not-found) :as route]
            [clj-time.core :refer (date-time)]
            [clj-time.format :as tf]
            [clj-time.coerce :refer (to-date)]
            [clj-rss.core :as rss]
            [immutant.web :refer (wrap-resource) :as web]
            [compojure.handler :refer (site)]
            [sdos-site.layout :refer (main-template)]))

(def world (atom {}))

(defn page
  [category]
  (fn [req]
    (let [db (:db req)
          articles (find-category-articles db category)
          settings (get-settings req)]
      (main-template settings articles))))

(defn rss-item
  [{:keys [id title author date content]}]
  (let [link (str base-url "/article/" id)]
    {:guid link
     :title title
     :description content
     :link link
     :pubDate (to-date date)}))

(defn rss
  [req]
  (let [db (:db req)
        articles (find-category-articles db "home")]
    (apply rss/channel-xml
           {:title "Sauerbraten Day of Sobriety"
            :link base-url
            :description "A Sauerbraten Tournament"}
           (map rss-item articles))))

(defn show-article
  [req]
  (let [id (some->
            (get-in req [:route-params :id])
            (Integer/parseInt))
        db (:db req)]
    (if-let [article (find-article db id)]
      (let [settings (get-settings req)]
        (main-template settings article))
      {:status 404 :headers {} :body "Sorry, article not found."})))

(defroutes admin-routes
  (GET "/" [] admin/show-articles-summary)
  (GET "/articles/create" [] admin/create-article-page)
  (POST "/articles" [] admin/do-create-article)
  (GET "/articles/:id" [] admin/edit-article-page)
  (POST "/articles/:id" [] admin/do-edit-article)
  (POST "/articles/:id/delete" [] admin/do-delete-article)
  (GET "/users" [] admin/show-users)
  (GET "/users/new" [] admin/add-user-page)
  (POST "/users" [] admin/do-add-user)
  (GET "/users/:id" [] admin/show-user)
  (POST "/users/:id" [] admin/do-edit-user)
  (POST "/users/:id/delete" [] admin/do-delete-user)
  (GET "/tournaments" [] admin/show-tournaments)
  (GET "/tournaments/new" [] admin/add-tournament-page)
  (POST "/tournaments" [] admin/do-add-tournament)
  (GET "/tournaments/:id" [] admin/show-tournament)
  (POST "/tournaments/:id" [] admin/do-edit-tournament))

(defroutes user-routes
  (GET "/" [] user/profile-page)
  (GET "/login" [] user/login-page)
  (POST "/login" [] user/do-login)
  (GET "/logout" [] user/do-logout)
  (GET "/register" [] user/registration-page)
  (POST "/register" [] user/do-registration)<commit_msg>single articles need to be wrapped in coll<commit_after>(ns sdos-site.core
  (:require [sdos-site.settings :refer :all]
            [sdos-site.db :refer :all]
            [sdos-site.user :as user]
            [sdos-site.admin :as admin]
            [compojure.core :refer :all]
            [compojure.route :refer (not-found) :as route]
            [clj-time.core :refer (date-time)]
            [clj-time.format :as tf]
            [clj-time.coerce :refer (to-date)]
            [clj-rss.core :as rss]
            [immutant.web :refer (wrap-resource) :as web]
            [compojure.handler :refer (site)]
            [sdos-site.layout :refer (main-template)]))

(def world (atom {}))

(defn page
  [category]
  (fn [req]
    (let [db (:db req)
          articles (find-category-articles db category)
          settings (get-settings req)]
      (main-template settings articles))))

(defn rss-item
  [{:keys [id title author date content]}]
  (let [link (str base-url "/article/" id)]
    {:guid link
     :title title
     :description content
     :link link
     :pubDate (to-date date)}))

(defn rss
  [req]
  (let [db (:db req)
        articles (find-category-articles db "home")]
    (apply rss/channel-xml
           {:title "Sauerbraten Day of Sobriety"
            :link base-url
            :description "A Sauerbraten Tournament"}
           (map rss-item articles))))

(defn show-article
  [req]
  (let [id (some->
            (get-in req [:route-params :id])
            (Integer/parseInt))
        db (:db req)]
    (if-let [article (find-article db id)]
      (let [settings (get-settings req)]
        (main-template settings [article]))
      {:status 404 :headers {} :body "Sorry, article not found."})))

(defroutes admin-routes
  (GET "/" [] admin/show-articles-summary)
  (GET "/articles/create" [] admin/create-article-page)
  (POST "/articles" [] admin/do-create-article)
  (GET "/articles/:id" [] admin/edit-article-page)
  (POST "/articles/:id" [] admin/do-edit-article)
  (POST "/articles/:id/delete" [] admin/do-delete-article)
  (GET "/users" [] admin/show-users)
  (GET "/users/new" [] admin/add-user-page)
  (POST "/users" [] admin/do-add-user)
  (GET "/users/:id" [] admin/show-user)
  (POST "/users/:id" [] admin/do-edit-user)
  (POST "/users/:id/delete" [] admin/do-delete-user)
  (GET "/tournaments" [] admin/show-tournaments)
  (GET "/tournaments/new" [] admin/add-tournament-page)
  (POST "/tournaments" [] admin/do-add-tournament)
  (GET "/tournaments/:id" [] admin/show-tournament)
  (POST "/tournaments/:id" [] admin/do-edit-tournament))

(defroutes user-routes
  (GET "/" [] user/profile-page)
  (GET "/login" [] user/login-page)
  (POST "/login" [] user/do-login)
  (GET "/logout" [] user/do-logout)
  (GET "/register" [] user/registration-page)
  (POST "/register" [] user/do-registration)
{'fraction_non_alphanumeric': 0.174622892635315, 'fraction_numerical': 0.001064773735581189, 'mean_word_length': 2.571609632446134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '80182', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1949, 'n_words': 456}