<commit_before>(ns clojournal.layout
  (:require [selmer.parser :as parser]
            [clojure.string :as s]
            [ring.util.response :refer [content-type response]]
            [compojure.response :refer [Renderable]]
            [environ.core :refer [env]]
            [clojournal.models.article :as article]
            [clojournal.models.tag :as tag]))

(parser/set-resource-path!  (clojure.java.io/resource "templates"))

(deftype RenderableTemplate [template params]
  Renderable
  (render [this request]
    (content-type
      (->> (assoc params
                  (keyword (s/replace template #".html" "-selected")) "active"
                  :dev (env :dev)
                  :servlet-context
                  (if-let [context (:servlet-context request)]
                    ;; If we're not inside a serlvet environment (for
                    ;; example when using mock requests), then
                    ;; .getContextPath might not exist
                    (try (.getContextPath context)
                         (catch IllegalArgumentException _ context)))
                  ;; FIXME: the following line always issues db query even if not necessary
                  :latest-articles (:articles (article/latest-articles 0 10))
                  :tag-cloud-tags (map #(assoc % :size (long (+ 20 (* (:group %) 20))))
                             (tag/tag-cloud)))
        (parser/render-file (str template))
        response)
      "text/html; charset=utf-8")))

(defn render [template & [params]]
  (RenderableTemplate. template params))
<commit_msg>Remove a blank line before EOF.<commit_after>(ns clojournal.layout
  (:require [selmer.parser :as parser]
            [clojure.string :as s]
            [ring.util.response :refer [content-type response]]
            [compojure.response :refer [Renderable]]
            [environ.core :refer [env]]
            [clojournal.models.article :as article]
            [clojournal.models.tag :as tag]))

(parser/set-resource-path!  (clojure.java.io/resource "templates"))

(deftype RenderableTemplate [template params]
  Renderable
  (render [this request]
    (content-type
      (->> (assoc params
                  (keyword (s/replace template #".html" "-selected")) "active"
                  :dev (env :dev)
                  :servlet-context
                  (if-let [context (:servlet-context request)]
                    ;; If we're not inside a serlvet environment (for
                    ;; example when using mock requests), then
                    ;; .getContextPath might not exist
                    (try (.getContextPath context)
                         (catch IllegalArgumentException _ context)))
                  ;; FIXME: the following line always issues db query even if not necessary
                  :latest-articles (:articles (article/latest-articles 0 10))
                  :tag-cloud-tags (map #(assoc % :size (long (+ 20 (* (:group %) 20))))
                             (tag/tag-cloud)))
        (parser/render-file (str template))
        response)
      "text/html; charset=utf-8")))

(defn render [template & [params]]
  (RenderableTemplate. template params))
{'fraction_non_alphanumeric': 0.11714556362488159, 'fraction_numerical': 0.0050520997789706345, 'mean_word_length': 1.901098901098901, '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': '3188360', 'n_tokens_mistral': 868, 'n_tokens_neox': 811, 'n_words': 237}