<commit_before>(ns schedule.web.handler
  (:use [clostache.parser])
  (:require
   [compojure.route :as route]
   [compojure.handler :as handler]
   [compojure.core :refer [defroutes GET context routes]]
   [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
   [reloaded.repl :refer [system]]))

(def common-partials {:footer (render-resource "templates/footer.mustache")})

(def common-features 
  {:header #(-> (render-resource "templates/header.mustache") (clojure.string/replace "%TITLE%" %))})

(defn index [db]
  (render-resource
   "templates/index.mustache"
   (assoc common-features
          :conventions (get db :conventions))
   common-partials))

(defn new-convention [db]
  (render-resource "templates/new-convention.mustache" common-features common-partials))

(let [db (:db system)]
  (defroutes convention-routes
    (context "/convention" []
      (GET "/new" [] (new-convention db))))
  (defroutes core-routes
    (GET "/" [] (index db))
    (route/not-found "Not found")))

(def app
  (-> (routes convention-routes core-routes)
      (wrap-defaults site-defaults)))
<commit_msg>Refactor template rendering<commit_after>(ns schedule.web.handler
  (:require
   [clostache.parser :as clo]
   [compojure.route :as route]
   [compojure.handler :as handler]
   [compojure.core :refer [defroutes GET context routes]]
   [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
   [reloaded.repl :refer [system]]))

(def common-partials {:footer (clo/render-resource "templates/footer.mustache")})

(def common-features 
  {:header #(-> (clo/render-resource "templates/header.mustache") (clojure.string/replace "%TITLE%" %))})

(defn render [template values]
  (clo/render-resource
   template
   (merge common-features values)
   common-partials))

(defn index [db]
  (render "templates/index.mustache"
          {:conventions (get db :conventions)}))

(defn new-convention [db]
  (render "templates/new-convention.mustache" {}))

(let [db (:db system)]
  (defroutes convention-routes
    (context "/convention" []
      (GET "/new" [] (new-convention db))))
  (defroutes core-routes
    (GET "/" [] (index db))
    (route/not-found "Not found")))

(def app
  (-> (routes convention-routes core-routes)
      (wrap-defaults site-defaults)))

{'fraction_non_alphanumeric': 0.1600703605980651, 'fraction_numerical': 0.0, 'mean_word_length': 4.078125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3369571', 'n_tokens_mistral': 769, 'n_tokens_neox': 768, 'n_words': 172}