-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates.clj
48 lines (41 loc) · 1.04 KB
/
templates.clj
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
(ns tadam.templates
(:require
[environ.core :refer [env]]
[clojure.java.io :refer [resource]]
[selmer.parser :as s]
[cheshire.core :refer [generate-string]]
))
;; Disabled cache in debug
(if (:debug env)
(s/cache-off!))
;; Path templates
(s/set-resource-path! (resource "templates") )
(defn raw-HTML
;; Render raw HTML
[text params]
{:status 200
:headers {"Content-Type" "text/html"}
:body (s/render text params)})
(defn render-HTML
;; Render to HTML
([template params]
{:status 200
:headers {"Content-Type" "text/html"}
:body (s/render-file template params)})
([template params session]
{:status 200
:headers {"Content-Type" "text/html"}
:body (s/render-file template params)
:session session}))
(defn render-JSON
;; Render JSON
[hash-map]
{:status 200
:headers {"Content-Type" "application/json"}
:body (generate-string hash-map)})
(defn render-404
;; Render 404 HTML
[]
{:status 404
:headers {"Content-Type" "text/html"}
:body (s/render-file "404.html" {})})